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']"
@@ -122,14 +122,35 @@ export default {
122122 const answered = _ .filter (this .context , c =>
123123 Object .keys (this .responses ).indexOf (c[' @id' ]) > - 1 );
124124 if (! answered .length ) {
125- this .listShow = [0 ];
125+ this .listShow = [this . initializeListShow () ];
126126 } else {
127127 this .listShow = _ .map (new Array (answered .length + 1 ), (c , i ) => i);
128128 }
129129 this .visibility = this .getVisibility (this .responses );
130130 });
131131 });
132132 },
133+ initializeListShow () {
134+ const responseMapper = this .responseMapper (this .responses );
135+ let i = 0 ;
136+ for (i = 0 ; i < this .context .length ; i += 1 ) {
137+ const eachItem = (this .context )[i];
138+ // return _.map(this.context, (o, index) => {
139+ const matchedObject = _ .filter (this .activity [' http://schema.repronim.org/addProperties' ], a => a[' http://schema.repronim.org/isAbout' ][0 ][' @id' ] === eachItem[' @id' ]);
140+ let val = true ; // true by default if not mentioned
141+ if (matchedObject[0 ][' http://schema.repronim.org/isVis' ]) {
142+ val = matchedObject[0 ][' http://schema.repronim.org/isVis' ][0 ][' @value' ];
143+ }
144+ if (_ .isString (val)) {
145+ val = this .evaluateString (val, responseMapper);
146+ }
147+ if (val === true ) { // first visible item
148+ break ;
149+ }
150+ }
151+ return i;
152+ // });
153+ },
133154 getVisibility (responses ) {
134155 const responseMapper = this .responseMapper (responses);
135156 if (! _ .isEmpty (this .activity [' http://schema.repronim.org/addProperties' ])) {
@@ -152,7 +173,7 @@ export default {
152173 return {};
153174 },
154175 responseMapper (responses ) {
155- let keyArr;
176+ let keyArr = [] ;
156177 // a variable map is defined! great
157178 if (this .activity [' http://schema.repronim.org/addProperties' ]) {
158179 const vmap = this .activity [' http://schema.repronim.org/addProperties' ];
@@ -164,6 +185,33 @@ export default {
164185 });
165186
166187 }
188+ const respMapper = {};
189+ _ .map (keyArr, (a ) => {
190+ respMapper[a .qId ] = { val: a .val , ref: a .key };
191+ });
192+ // Store the response variables in the state
193+ this .$store .state .responseMap [this .activity [' @id' ]] = respMapper;
194+ // Create a mapping from uris to variable names
195+ let uri2varmap = {};
196+ Object .entries (this .$store .state .responseMap ).forEach (
197+ // eslint-disable-next-line no-unused-vars
198+ ([unused , v ]) => {
199+ Object .entries (v).forEach (
200+ ([key1 , value1 ]) => {
201+ uri2varmap[value1[' ref' ]] = key1;
202+ })
203+ });
204+ Object .entries (this .$store .state .responseMap ).forEach (
205+ // eslint-disable-next-line no-unused-vars
206+ ([key , v ]) => {
207+ Object .entries (v).forEach (
208+ ([key1 , value1 ]) => {
209+ if (key in uri2varmap) {
210+ const joined_key = ' ' .concat (uri2varmap[key],' .' ,key1);
211+ keyArr .push ({ qId: joined_key, val: value1[' val' ], key: value1[' ref' ] });
212+ }
213+ })
214+ });
167215 if (this .$store .getters .getQueryParameters ) {
168216 const q = this .$store .getters .getQueryParameters ;
169217 Object .entries (q).forEach (
@@ -184,25 +232,36 @@ export default {
184232 return outMapper;
185233 },
186234 evaluateString (string , responseMapper ) {
187- // console.log(176, string, responseMapper);
188235 const keys = Object .keys (responseMapper);
189236 let output = string;
237+ let output_modified = false ;
190238 _ .map (keys, (k ) => {
191239 // grab the value of the key from responseMapper
192240 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
241+ if (val !== undefined ) {
242+ if (val !== ' skipped' && val !== ' dontknow' ) {
243+ if (_ .isString (val)) {
244+ val = ` '${ val} '` ; // put the string in quotes
245+ }
246+ if (_ .isArray (val)) {
247+ val = ` [${ val} ]` ; // put braces for array
248+ }
249+ let output_old = output;
250+ output = output .replaceAll (new RegExp (` \\ b${ k} \\ b` || ` \\ b${ k} \\ .` , ' g' ), val);
251+ if (output_old !== output) output_modified = true ;
252+ } else {
253+ let output_old = output;
254+ output = output .replaceAll (new RegExp (` \\ b${ k} \\ b` , ' g' ), 0 );
255+ if (output_old !== output) output_modified = true ;
199256 }
200- output = output .replace (new RegExp (` \\ b${ k} \\ b` ), val);
201- } else {
202- output = output .replace (new RegExp (` \\ b${ k} \\ b` ), 0 );
203257 }
204258 });
205- return Function (' return ' + output)();
259+ if (output_modified) {
260+ return Function (" return " + output)();
261+ }
262+ else {
263+ return false ;
264+ }
206265 },
207266 restart () {
208267 this .currentIndex = 0 ;
@@ -353,9 +412,11 @@ export default {
353412 document .documentElement .scrollTop = 0 ; // For Chrome, Firefox, IE and Opera
354413 this .checkAlertMessage (idx);
355414 if (skip) {
415+ this .$emit (' saveResponse' , this .context [idx][' @id' ], ' http://schema.repronim.org/Skipped' );
356416 this .setResponse (' http://schema.repronim.org/Skipped' , idx);
357417 }
358418 if (dontKnow) {
419+ this .$emit (' saveResponse' , this .context [idx][' @id' ], ' http://schema.repronim.org/DontKnow' );
359420 this .setResponse (' http://schema.repronim.org/DontKnow' , idx);
360421 }
361422
0 commit comments