From 5d7afe854ee7f9b7fd8e18cf056850d53a399762 Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Fri, 30 Aug 2024 20:21:10 -0400 Subject: [PATCH 1/5] fix: post if server is not null and token available --- src/components/Inputs/SaveData/SaveData.vue | 6 +++++- src/components/Survey/Survey.vue | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Inputs/SaveData/SaveData.vue b/src/components/Inputs/SaveData/SaveData.vue index 892e093..19f0c3c 100644 --- a/src/components/Inputs/SaveData/SaveData.vue +++ b/src/components/Inputs/SaveData/SaveData.vue @@ -195,10 +195,14 @@ export default { }); }, sendRetry(url, formData, index, retries = 3, backoff = 10000) { + if (!this.shouldUpload) { + console.log("Not uploading") + return; + } const config1 = { 'Content-Type': 'multipart/form-data' }; - return axios.post(`${config.backendServer}/submit`, formData, config1).then((res) => { + return axios.post(url, formData, config1).then((res) => { // console.log(322, 'SUCCESS!!', `${fileName}.zip.00${index}`, res.status); slicedArray.splice(index, 1); // remove successfully POSTed slice sentPartCount++; diff --git a/src/components/Survey/Survey.vue b/src/components/Survey/Survey.vue index 2d986af..7112fee 100644 --- a/src/components/Survey/Survey.vue +++ b/src/components/Survey/Survey.vue @@ -490,12 +490,16 @@ }); }, async sendRetry(url, formData, retries = 3, backoff = 10000) { + if (!this.shouldUpload) { + console.log("Not uploading") + return; + } const config1 = { 'Content-Type': 'multipart/form-data' }; try { // eslint-disable-next-line no-unused-vars - const res = await axios.post(`${config.backendServer}/submit`, formData, config1); + const res = await axios.post(url, formData, config1); // console.log(530, 'SUCCESS!!', formData, res.status); } catch (e) { if (retries > 0) { @@ -582,6 +586,9 @@ return criteria1 && criteria2; }); }, + shouldUpload() { + return !!(config.backendServer && this.$store.getters.getAuthToken); + }, context() { /* eslint-disable */ if (this.activity['http://schema.repronim.org/order']) { From f14408206cc766be42afa0e51db02560d705ebc6 Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Fri, 30 Aug 2024 20:30:06 -0400 Subject: [PATCH 2/5] fix: return status --- src/components/Inputs/SaveData/SaveData.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Inputs/SaveData/SaveData.vue b/src/components/Inputs/SaveData/SaveData.vue index 19f0c3c..8b3415e 100644 --- a/src/components/Inputs/SaveData/SaveData.vue +++ b/src/components/Inputs/SaveData/SaveData.vue @@ -197,7 +197,7 @@ export default { sendRetry(url, formData, index, retries = 3, backoff = 10000) { if (!this.shouldUpload) { console.log("Not uploading") - return; + return 200; } const config1 = { 'Content-Type': 'multipart/form-data' From a31d44111d1719df38dbfd2c868f9c78862f9f0a Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Sat, 31 Aug 2024 00:00:34 -0400 Subject: [PATCH 3/5] initial pass at accessing all variable records globally --- src/components/Section/Section.vue | 68 ++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/src/components/Section/Section.vue b/src/components/Section/Section.vue index a76c36f..6217964 100644 --- a/src/components/Section/Section.vue +++ b/src/components/Section/Section.vue @@ -47,8 +47,8 @@
- Restart + Don't Know { + respMapper[a.qId] = { val: a.val, ref: a.key }; + }); + // Store the response variables in the state + this.$store.state.responseMap[this.activity['@id']] = respMapper; + // Create a mapping from uris to variable names + let uri2varmap = {}; + Object.entries(this.$store.state.responseMap).forEach( + // eslint-disable-next-line no-unused-vars + ([unused, v]) => { + Object.entries(v).forEach( + ([key1, value1]) => { + uri2varmap[value1['ref']] = key1; + }) + }); + Object.entries(this.$store.state.responseMap).forEach( + // eslint-disable-next-line no-unused-vars + ([key, v]) => { + Object.entries(v).forEach( + ([key1, value1]) => { + if (key in uri2varmap) { + const joined_key = ''.concat(uri2varmap[key],'.',key1); + keyArr.push({ qId: joined_key, val: value1['val'], key: value1['ref'] }); + } + }) + }); if (this.$store.getters.getQueryParameters) { const q = this.$store.getters.getQueryParameters; Object.entries(q).forEach( @@ -184,25 +211,36 @@ export default { return outMapper; }, evaluateString(string, responseMapper) { - // console.log(176, string, responseMapper); const keys = Object.keys(responseMapper); let output = string; + let output_modified = false; _.map(keys, (k) => { // grab the value of the key from responseMapper let val = responseMapper[k].val; - if (Array.isArray(responseMapper[k].val)) { - val = responseMapper[k].val[0]; - } - if (val !== 'http://schema.repronim.org/Skipped' && val !== 'http://schema.repronim.org/DontKnow') { - if (_.isString(val)) { - val = `'${val}'`; // put the string in quotes + if (val !== undefined) { + if (val !== 'skipped' && val !== 'dontknow') { + if (_.isString(val)) { + val = `'${val}'`; // put the string in quotes + } + if (_.isArray(val)) { + val = `[${val}]`; // put braces for array + } + let output_old = output; + output = output.replaceAll(new RegExp(`\\b${k}\\b` || `\\b${k}\\.`, 'g'), val); + if (output_old !== output) output_modified = true; + } else { + let output_old = output; + output = output.replaceAll(new RegExp(`\\b${k}\\b`, 'g'), 0); + if (output_old !== output) output_modified = true; } - output = output.replace(new RegExp(`\\b${k}\\b`), val); - } else { - output = output.replace(new RegExp(`\\b${k}\\b`), 0); } }); - return Function('return ' + output)(); + if (output_modified) { + return Function("return " + output)(); + } + else { + return false; + } }, restart() { this.currentIndex = 0; @@ -353,9 +391,11 @@ export default { document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera this.checkAlertMessage(idx); if (skip) { + this.$emit('saveResponse', this.context[idx]['@id'], 'http://schema.repronim.org/Skipped'); this.setResponse('http://schema.repronim.org/Skipped', idx); } if (dontKnow) { + this.$emit('saveResponse', this.context[idx]['@id'], 'http://schema.repronim.org/DontKnow'); this.setResponse('http://schema.repronim.org/DontKnow', idx); } From f9ff613ae1ea6943a88bc25beab3053ebc0bf16a Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Sat, 31 Aug 2024 10:36:39 -0400 Subject: [PATCH 4/5] remove unused code --- src/components/SurveyItem/SurveyItem.vue | 42 ------------------------ 1 file changed, 42 deletions(-) diff --git a/src/components/SurveyItem/SurveyItem.vue b/src/components/SurveyItem/SurveyItem.vue index 85d9843..c9ab2b8 100644 --- a/src/components/SurveyItem/SurveyItem.vue +++ b/src/components/SurveyItem/SurveyItem.vue @@ -170,14 +170,6 @@ width: '100%', }; }, - bodyStyle() { - if (this.ui === 'section' || this.ui === 'multipart') { - return { - padding: 0, - }; - } - return {}; - }, ui() { /* eslint-disable */ if (this.data['@type'] && this.data['@type'][0] === "http://schema.repronim.org/Activity") { @@ -229,42 +221,8 @@ fieldData() { return this.data; }, - findPassOptions() { - if (this.data['http://schema.repronim.org/responseOptions']) { - // when responseOptions is a remote object - if (Object.keys(this.data['http://schema.repronim.org/responseOptions'][0]).indexOf('@id') > -1) { - this.getRequiredVal(); - return this.requireVal; - } - // when responseOptions in embedded in item object itself - if (this.data['http://schema.repronim.org/responseOptions'][0]) { - // make sure the requiredValue key is defined - // todo: requiredValue has moved to activity level, so change the code here - if (this.data['http://schema.repronim.org/responseOptions'][0]['http://schema.org/valueRequired']) { - return this.data['http://schema.repronim.org/responseOptions'][0]['http://schema.org/valueRequired'][0]['@value']; - } - } - } - return false; - }, }, methods: { - getRequiredVal() { // todo: this needs to change. requiredValue is in activity level now - jsonld.expand(this.data['http://schema.repronim.org/responseOptions'][0]['@id']) - .then((rsp) => { - this.requireVal = rsp[0]['http://schema.org/valueRequired'][0]['@value']; - // eslint-disable-next-line no-unused-vars - }).catch((e) => { - // console.log(240, 'constraint error', e); - jsonld.expand(`${this.data['http://schema.repronim.org/responseOptions'][0]['@id']}.jsonld`).then((resp) => { - // console.log(250, resp); - this.requireVal = resp[0]['http://schema.org/valueRequired'][0]['@value']; - // eslint-disable-next-line no-unused-vars - }).catch((e1) => { - // console.log(252, e1); - }); - }); - }, getValueConstraintsData(url) { jsonld.expand(url).then((rsp) => { this.valueC = rsp[0]; From 21bf162f8850a89329ddaed19243a7888ce6492c Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Sat, 31 Aug 2024 11:29:19 -0400 Subject: [PATCH 5/5] fix: change how listshow is being initialized --- src/components/Section/Section.vue | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/Section/Section.vue b/src/components/Section/Section.vue index 6217964..bc7382c 100644 --- a/src/components/Section/Section.vue +++ b/src/components/Section/Section.vue @@ -122,7 +122,7 @@ export default { const answered = _.filter(this.context, c => Object.keys(this.responses).indexOf(c['@id']) > -1); if (!answered.length) { - this.listShow = [0]; + this.listShow = [this.initializeListShow()]; } else { this.listShow = _.map(new Array(answered.length + 1), (c, i) => i); } @@ -130,6 +130,27 @@ export default { }); }); }, + initializeListShow() { + const responseMapper = this.responseMapper(this.responses); + let i = 0; + for (i = 0; i < this.context.length; i += 1) { + const eachItem = (this.context)[i]; + // return _.map(this.context, (o, index) => { + const matchedObject = _.filter(this.activity['http://schema.repronim.org/addProperties'], a => a['http://schema.repronim.org/isAbout'][0]['@id'] === eachItem['@id']); + let val = true; // true by default if not mentioned + if (matchedObject[0]['http://schema.repronim.org/isVis']) { + val = matchedObject[0]['http://schema.repronim.org/isVis'][0]['@value']; + } + if (_.isString(val)) { + val = this.evaluateString(val, responseMapper); + } + if (val === true) { // first visible item + break; + } + } + return i; + // }); + }, getVisibility(responses) { const responseMapper = this.responseMapper(responses); if (!_.isEmpty(this.activity['http://schema.repronim.org/addProperties'])) {