diff --git a/src/components/Inputs/SaveData/SaveData.vue b/src/components/Inputs/SaveData/SaveData.vue index 892e093..8b3415e 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 200; + } 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/Section/Section.vue b/src/components/Section/Section.vue index a76c36f..bc7382c 100644 --- a/src/components/Section/Section.vue +++ b/src/components/Section/Section.vue @@ -47,8 +47,8 @@
- Restart + Don't Know 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'])) { @@ -152,7 +173,7 @@ export default { return {}; }, responseMapper(responses) { - let keyArr; + let keyArr = []; // a variable map is defined! great if (this.activity['http://schema.repronim.org/addProperties']) { const vmap = this.activity['http://schema.repronim.org/addProperties']; @@ -164,6 +185,33 @@ export default { }); } + const respMapper = {}; + _.map(keyArr, (a) => { + 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 +232,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 +412,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); } 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']) { 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];