Skip to content

Commit a31d441

Browse files
committed
initial pass at accessing all variable records globally
1 parent f144082 commit a31d441

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

src/components/Section/Section.vue

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747

4848

4949
<div class="text-right mt-3" v-if="showPassOptions !== null ">
50-
<b-button variant="default"
51-
@click="restart">Restart</b-button>
50+
<!--<b-button variant="default"
51+
@click="restart">Restart</b-button> -->
5252
<b-button variant="default" v-if="showPassOptions['dontKnow']"
5353
@click="dontKnow">Don't Know</b-button>
5454
<b-button variant="default" v-if="showPassOptions['skip']"
@@ -152,7 +152,7 @@ export default {
152152
return {};
153153
},
154154
responseMapper(responses) {
155-
let keyArr;
155+
let keyArr = [];
156156
// a variable map is defined! great
157157
if (this.activity['http://schema.repronim.org/addProperties']) {
158158
const vmap = this.activity['http://schema.repronim.org/addProperties'];
@@ -164,6 +164,33 @@ export default {
164164
});
165165
166166
}
167+
const respMapper = {};
168+
_.map(keyArr, (a) => {
169+
respMapper[a.qId] = { val: a.val, ref: a.key };
170+
});
171+
// Store the response variables in the state
172+
this.$store.state.responseMap[this.activity['@id']] = respMapper;
173+
// Create a mapping from uris to variable names
174+
let uri2varmap = {};
175+
Object.entries(this.$store.state.responseMap).forEach(
176+
// eslint-disable-next-line no-unused-vars
177+
([unused, v]) => {
178+
Object.entries(v).forEach(
179+
([key1, value1]) => {
180+
uri2varmap[value1['ref']] = key1;
181+
})
182+
});
183+
Object.entries(this.$store.state.responseMap).forEach(
184+
// eslint-disable-next-line no-unused-vars
185+
([key, v]) => {
186+
Object.entries(v).forEach(
187+
([key1, value1]) => {
188+
if (key in uri2varmap) {
189+
const joined_key = ''.concat(uri2varmap[key],'.',key1);
190+
keyArr.push({ qId: joined_key, val: value1['val'], key: value1['ref'] });
191+
}
192+
})
193+
});
167194
if (this.$store.getters.getQueryParameters) {
168195
const q = this.$store.getters.getQueryParameters;
169196
Object.entries(q).forEach(
@@ -184,25 +211,36 @@ export default {
184211
return outMapper;
185212
},
186213
evaluateString(string, responseMapper) {
187-
// console.log(176, string, responseMapper);
188214
const keys = Object.keys(responseMapper);
189215
let output = string;
216+
let output_modified = false;
190217
_.map(keys, (k) => {
191218
// grab the value of the key from responseMapper
192219
let val = responseMapper[k].val;
193-
if (Array.isArray(responseMapper[k].val)) {
194-
val = responseMapper[k].val[0];
195-
}
196-
if (val !== 'http://schema.repronim.org/Skipped' && val !== 'http://schema.repronim.org/DontKnow') {
197-
if (_.isString(val)) {
198-
val = `'${val}'`; // put the string in quotes
220+
if (val !== undefined) {
221+
if (val !== 'skipped' && val !== 'dontknow') {
222+
if (_.isString(val)) {
223+
val = `'${val}'`; // put the string in quotes
224+
}
225+
if (_.isArray(val)) {
226+
val = `[${val}]`; // put braces for array
227+
}
228+
let output_old = output;
229+
output = output.replaceAll(new RegExp(`\\b${k}\\b` || `\\b${k}\\.`, 'g'), val);
230+
if (output_old !== output) output_modified = true;
231+
} else {
232+
let output_old = output;
233+
output = output.replaceAll(new RegExp(`\\b${k}\\b`, 'g'), 0);
234+
if (output_old !== output) output_modified = true;
199235
}
200-
output = output.replace(new RegExp(`\\b${k}\\b`), val);
201-
} else {
202-
output = output.replace(new RegExp(`\\b${k}\\b`), 0);
203236
}
204237
});
205-
return Function('return ' + output)();
238+
if (output_modified) {
239+
return Function("return " + output)();
240+
}
241+
else {
242+
return false;
243+
}
206244
},
207245
restart() {
208246
this.currentIndex = 0;
@@ -353,9 +391,11 @@ export default {
353391
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
354392
this.checkAlertMessage(idx);
355393
if (skip) {
394+
this.$emit('saveResponse', this.context[idx]['@id'], 'http://schema.repronim.org/Skipped');
356395
this.setResponse('http://schema.repronim.org/Skipped', idx);
357396
}
358397
if (dontKnow) {
398+
this.$emit('saveResponse', this.context[idx]['@id'], 'http://schema.repronim.org/DontKnow');
359399
this.setResponse('http://schema.repronim.org/DontKnow', idx);
360400
}
361401

0 commit comments

Comments
 (0)