Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nested scoping across activities and sub activities #343

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/Inputs/SaveData/SaveData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
91 changes: 76 additions & 15 deletions src/components/Section/Section.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@


<div class="text-right mt-3" v-if="showPassOptions !== null ">
<b-button variant="default"
@click="restart">Restart</b-button>
<!--<b-button variant="default"
@click="restart">Restart</b-button> -->
<b-button variant="default" v-if="showPassOptions['dontKnow']"
@click="dontKnow">Don't Know</b-button>
<b-button variant="default" v-if="showPassOptions['skip']"
Expand Down Expand Up @@ -122,14 +122,35 @@ 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);
}
this.visibility = this.getVisibility(this.responses);
});
});
},
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'])) {
Expand All @@ -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'];
Expand All @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 8 additions & 1 deletion src/components/Survey/Survey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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']) {
Expand Down
42 changes: 0 additions & 42 deletions src/components/SurveyItem/SurveyItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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];
Expand Down
Loading