project-booster-vue 8.115.5 → 8.115.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/appointment/PbAppointmentStartSection.vue +0 -16
- package/src/components/question/PbQuestion.vue +11 -59
- package/src/components/question/dimensions-input/PbDimensionsInput.vue +26 -2
- package/src/components/question/list-select/PbListSelect.vue +18 -72
- package/src/components/question/space-input/PbSpaceInput.vue +26 -1
- package/src/components/question/upload-document/PbUploadDocument.vue +10 -61
- package/src/components/restitution/PbRestitution.vue +9 -34
- package/src/components/restitution/PbRestitutionBody.vue +2 -38
- package/src/components/scenario/PbScenario.vue +2 -36
- package/src/service/scenarioConditionals.js +44 -0
package/package.json
CHANGED
|
@@ -68,22 +68,6 @@ export default {
|
|
|
68
68
|
nextStep: null,
|
|
69
69
|
});
|
|
70
70
|
},
|
|
71
|
-
computeNextStep(nextStep) {
|
|
72
|
-
let resultingNextStep;
|
|
73
|
-
|
|
74
|
-
if (nextStep?.conditionals) {
|
|
75
|
-
for (const conditional of nextStep.conditionals) {
|
|
76
|
-
if (this.areConditionsValid(conditional.conditions)) {
|
|
77
|
-
resultingNextStep = this.computeNextStep(conditional.nextStep);
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
resultingNextStep = nextStep;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return resultingNextStep;
|
|
86
|
-
},
|
|
87
71
|
},
|
|
88
72
|
};
|
|
89
73
|
</script>
|
|
@@ -257,6 +257,7 @@ import MLink from '../mozaic/link/MLink';
|
|
|
257
257
|
import PbCard from '../cards/PbCard';
|
|
258
258
|
import PbStickyFooter from '../sticky-footer/PbStickyFooter';
|
|
259
259
|
import { sortAnswers } from './sortAnswers';
|
|
260
|
+
import { areConditionsValid } from '../../service/scenarioConditionals';
|
|
260
261
|
|
|
261
262
|
const BACK_ICON =
|
|
262
263
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -391,7 +392,7 @@ export default {
|
|
|
391
392
|
|
|
392
393
|
if (this.payload?.answers) {
|
|
393
394
|
this.displayableAnswers = Object.values(this.payload?.answers).filter((answer) => {
|
|
394
|
-
return
|
|
395
|
+
return areConditionsValid(answer.conditions, this.answers, this.runtimeOptions);
|
|
395
396
|
});
|
|
396
397
|
}
|
|
397
398
|
|
|
@@ -406,7 +407,7 @@ export default {
|
|
|
406
407
|
for (const answerCode in this.payload.answers) {
|
|
407
408
|
if (
|
|
408
409
|
this.payload.answers[answerCode].selected &&
|
|
409
|
-
|
|
410
|
+
areConditionsValid(this.payload.answers[answerCode].conditions, this.answers, this.runtimeOptions)
|
|
410
411
|
) {
|
|
411
412
|
this.selectedAnswers[answerCode] = true;
|
|
412
413
|
}
|
|
@@ -445,35 +446,14 @@ export default {
|
|
|
445
446
|
);
|
|
446
447
|
},
|
|
447
448
|
isShowingFooter(viewModel) {
|
|
448
|
-
return viewModel.footer &&
|
|
449
|
+
return viewModel.footer && areConditionsValid(viewModel.footer.conditions, this.answers, this.runtimeOptions);
|
|
449
450
|
},
|
|
450
|
-
areConditionsValid(conditions) {
|
|
451
|
-
let valid = true;
|
|
452
|
-
|
|
453
|
-
if (conditions) {
|
|
454
|
-
valid = false;
|
|
455
|
-
for (const condition of conditions) {
|
|
456
|
-
try {
|
|
457
|
-
let conditionValid = new Function(
|
|
458
|
-
'isAnswerMatching',
|
|
459
|
-
'isAnswerContaining',
|
|
460
|
-
'answers',
|
|
461
|
-
'runtimeOptions',
|
|
462
|
-
`return ${condition}`,
|
|
463
|
-
).call(this, this.isAnswerMatching, this.isAnswerContaining, this.answers, this.runtimeOptions);
|
|
464
|
-
|
|
465
|
-
valid = valid || conditionValid;
|
|
466
|
-
} catch (error) {
|
|
467
|
-
console.error(error);
|
|
468
|
-
valid = valid || true;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
451
|
|
|
473
|
-
return valid;
|
|
474
|
-
},
|
|
475
452
|
isAnswerDisabled(answer) {
|
|
476
|
-
return
|
|
453
|
+
return (
|
|
454
|
+
answer.viewModel.disabled &&
|
|
455
|
+
areConditionsValid(answer.viewModel.disabled.conditions, this.answers, this.runtimeOptions)
|
|
456
|
+
);
|
|
477
457
|
},
|
|
478
458
|
selectAnswer(stepCode, answer) {
|
|
479
459
|
if (this.isAnswerDisabled(answer)) {
|
|
@@ -499,7 +479,7 @@ export default {
|
|
|
499
479
|
*/
|
|
500
480
|
this.$emit(this.completedEventName, {
|
|
501
481
|
answers: [answer],
|
|
502
|
-
nextStep:
|
|
482
|
+
nextStep: answer.nextStep,
|
|
503
483
|
});
|
|
504
484
|
}
|
|
505
485
|
|
|
@@ -527,18 +507,6 @@ export default {
|
|
|
527
507
|
|
|
528
508
|
return selectedAnswersNumber;
|
|
529
509
|
},
|
|
530
|
-
// Function used by the scenario conditions
|
|
531
|
-
isAnswerMatching(questionCode, answerCode) {
|
|
532
|
-
return this?.answers[questionCode] && this?.answers[questionCode][0]?.code === answerCode;
|
|
533
|
-
},
|
|
534
|
-
isAnswerContaining(questionCode, answerCode) {
|
|
535
|
-
return (
|
|
536
|
-
this?.answers[questionCode] &&
|
|
537
|
-
this?.answers[questionCode].findIndex((elt) => {
|
|
538
|
-
return elt.code === answerCode;
|
|
539
|
-
}) > -1
|
|
540
|
-
);
|
|
541
|
-
},
|
|
542
510
|
validMultiSelect(multiSelectOptions) {
|
|
543
511
|
const answers = [];
|
|
544
512
|
|
|
@@ -550,14 +518,14 @@ export default {
|
|
|
550
518
|
|
|
551
519
|
this.$emit(this.completedEventName, {
|
|
552
520
|
answers: answers,
|
|
553
|
-
nextStep:
|
|
521
|
+
nextStep: multiSelectOptions.nextStep,
|
|
554
522
|
});
|
|
555
523
|
},
|
|
556
524
|
skipQuestion(button) {
|
|
557
525
|
this.initAnswersSelectedState(this.payload.answers);
|
|
558
526
|
this.$emit(this.completedEventName, {
|
|
559
527
|
answers: button.defaultAnswer ? [button.defaultAnswer] : [],
|
|
560
|
-
nextStep:
|
|
528
|
+
nextStep: button.nextStep,
|
|
561
529
|
});
|
|
562
530
|
},
|
|
563
531
|
resetMultiSelect(multiSelectOptions, answers) {
|
|
@@ -569,22 +537,6 @@ export default {
|
|
|
569
537
|
answer.selected = false;
|
|
570
538
|
});
|
|
571
539
|
},
|
|
572
|
-
computeNextStep(nextStep) {
|
|
573
|
-
let resultingNextStep;
|
|
574
|
-
|
|
575
|
-
if (nextStep?.conditionals) {
|
|
576
|
-
for (const conditional of nextStep.conditionals) {
|
|
577
|
-
if (this.areConditionsValid(conditional.conditions)) {
|
|
578
|
-
resultingNextStep = this.computeNextStep(conditional.nextStep);
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
} else {
|
|
583
|
-
resultingNextStep = nextStep;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
return resultingNextStep;
|
|
587
|
-
},
|
|
588
540
|
handleShowMoreClick() {
|
|
589
541
|
this.activateShowMoreAnimation();
|
|
590
542
|
this.showMore();
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
</div>
|
|
63
63
|
</m-flex>
|
|
64
64
|
</m-flex>
|
|
65
|
-
<m-flex class="pb-dimensions-input__buttons-container" direction="column">
|
|
65
|
+
<m-flex class="pb-dimensions-input__buttons-container" direction="column" align-items="center">
|
|
66
66
|
<m-button
|
|
67
67
|
class="pb-dimensions-input__button"
|
|
68
68
|
:label="computedPayload.viewModel.actionLabel"
|
|
@@ -70,6 +70,15 @@
|
|
|
70
70
|
size="l"
|
|
71
71
|
@click="handleFormSubmit"
|
|
72
72
|
/>
|
|
73
|
+
<m-link
|
|
74
|
+
v-if="payload.skippable"
|
|
75
|
+
class="pb-dimensions-input__link"
|
|
76
|
+
:label="payload.skippable.label"
|
|
77
|
+
width="full"
|
|
78
|
+
size="l"
|
|
79
|
+
@click="skipQuestion"
|
|
80
|
+
:theme="payload.skippable.theme"
|
|
81
|
+
/>
|
|
73
82
|
</m-flex>
|
|
74
83
|
</m-flex>
|
|
75
84
|
</form>
|
|
@@ -266,7 +275,17 @@ export default {
|
|
|
266
275
|
],
|
|
267
276
|
});
|
|
268
277
|
});
|
|
269
|
-
|
|
278
|
+
const skipQuestion = () => {
|
|
279
|
+
/**
|
|
280
|
+
* Emitted when step is completed
|
|
281
|
+
* @event dynamic event name according to completedEventName prop
|
|
282
|
+
* @type {Event}
|
|
283
|
+
*/
|
|
284
|
+
emit(props.completedEventName, {
|
|
285
|
+
answers: props.payload?.skippable?.defaultAnswer ? [props.payload?.skippable?.defaultAnswer] : [],
|
|
286
|
+
nextStep: props.payload?.skippable?.nextStep,
|
|
287
|
+
});
|
|
288
|
+
};
|
|
270
289
|
onMounted(() => {
|
|
271
290
|
setTimeout(() => {
|
|
272
291
|
pbDimensionsInputLengthInput.value.focus();
|
|
@@ -282,6 +301,7 @@ export default {
|
|
|
282
301
|
computedPayload,
|
|
283
302
|
pbDimensionsInputLengthInput,
|
|
284
303
|
handleFormSubmit,
|
|
304
|
+
skipQuestion,
|
|
285
305
|
};
|
|
286
306
|
},
|
|
287
307
|
};
|
|
@@ -415,5 +435,9 @@ $responsive-breakpoint: 'm';
|
|
|
415
435
|
position: sticky;
|
|
416
436
|
z-index: 1;
|
|
417
437
|
}
|
|
438
|
+
|
|
439
|
+
&__link {
|
|
440
|
+
margin-top: $mu250;
|
|
441
|
+
}
|
|
418
442
|
}
|
|
419
443
|
</style>
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
</template>
|
|
73
73
|
|
|
74
74
|
<script>
|
|
75
|
-
import { ref, computed } from 'vue';
|
|
75
|
+
import { ref, computed, onMounted } from 'vue';
|
|
76
76
|
import objectPath from 'object-path';
|
|
77
77
|
import MFlex from '../../mozaic/flex/MFlex';
|
|
78
78
|
import MButton from '../../mozaic/buttons/MButton';
|
|
@@ -164,26 +164,25 @@ export default {
|
|
|
164
164
|
} else {
|
|
165
165
|
displayedAnswers = props.payload?.answers ? Object.values(props.payload.answers) : [];
|
|
166
166
|
}
|
|
167
|
-
updateSelectedAnswers();
|
|
168
167
|
return displayedAnswers;
|
|
169
168
|
});
|
|
170
169
|
|
|
171
170
|
const updateSelectedAnswers = () => {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
}
|
|
171
|
+
selectedAnswers.value = displayedAnswers.value
|
|
172
|
+
.filter((answer) => !!answer.selected)
|
|
173
|
+
.map((answer) => ({ key: answer.code, value: true }));
|
|
177
174
|
};
|
|
178
175
|
const handleSelectionChange = (items) => {
|
|
179
176
|
selectedAnswers.value = Object.entries(items)
|
|
180
177
|
.filter(([key, value]) => !!value)
|
|
181
|
-
.map(([key, value]) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
.map(([key, value]) => ({ key, value }));
|
|
179
|
+
Object.entries(items).map(([key, value]) => {
|
|
180
|
+
displayedAnswers.value.map((answer) => {
|
|
181
|
+
if (answer.code === key) {
|
|
182
|
+
answer.selected = value;
|
|
183
|
+
}
|
|
186
184
|
});
|
|
185
|
+
});
|
|
187
186
|
};
|
|
188
187
|
|
|
189
188
|
const hasSelectedAnswers = computed(() => {
|
|
@@ -205,7 +204,7 @@ export default {
|
|
|
205
204
|
return props.payload?.viewModel?.showMore?.position ?? 'center';
|
|
206
205
|
});
|
|
207
206
|
|
|
208
|
-
//
|
|
207
|
+
// Submit
|
|
209
208
|
const validateButtonProps = computed(() => {
|
|
210
209
|
let label, leftIcon, rightIcon;
|
|
211
210
|
|
|
@@ -239,7 +238,7 @@ export default {
|
|
|
239
238
|
}
|
|
240
239
|
|
|
241
240
|
let nextStep;
|
|
242
|
-
if (props.payload?.
|
|
241
|
+
if (props.payload?.multiSelect) {
|
|
243
242
|
nextStep = props.payload.multiSelect.actions.VALIDATE.nextStep;
|
|
244
243
|
} else if (props.payload?.answers[answersToSubmit[0].value]?.nextStep) {
|
|
245
244
|
nextStep = props.payload.answers[answersToSubmit[0].value].nextStep;
|
|
@@ -254,52 +253,10 @@ export default {
|
|
|
254
253
|
*/
|
|
255
254
|
emit(props.completedEventName, {
|
|
256
255
|
answers: answersToSubmit,
|
|
257
|
-
nextStep:
|
|
256
|
+
nextStep: nextStep,
|
|
258
257
|
});
|
|
259
258
|
};
|
|
260
259
|
|
|
261
|
-
// Scenario management
|
|
262
|
-
const areConditionsValid = (conditions) => {
|
|
263
|
-
let valid = true;
|
|
264
|
-
|
|
265
|
-
if (conditions) {
|
|
266
|
-
valid = false;
|
|
267
|
-
for (const condition of conditions) {
|
|
268
|
-
try {
|
|
269
|
-
let conditionValid = new Function(
|
|
270
|
-
'isAnswerMatching',
|
|
271
|
-
'isAnswerContaining',
|
|
272
|
-
'answers',
|
|
273
|
-
'runtimeOptions',
|
|
274
|
-
`return ${condition}`,
|
|
275
|
-
).call(this, isAnswerMatching, isAnswerContaining, props.answers, props.runtimeOptions);
|
|
276
|
-
|
|
277
|
-
valid = valid || conditionValid;
|
|
278
|
-
} catch (error) {
|
|
279
|
-
console.error(error);
|
|
280
|
-
valid = valid || true;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return valid;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
const computeNextStep = (nextStep) => {
|
|
288
|
-
let resultingNextStep;
|
|
289
|
-
|
|
290
|
-
if (nextStep?.conditionals) {
|
|
291
|
-
for (const conditional of nextStep.conditionals) {
|
|
292
|
-
if (areConditionsValid(conditional.conditions)) {
|
|
293
|
-
resultingNextStep = computeNextStep(conditional.nextStep);
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
} else {
|
|
298
|
-
resultingNextStep = nextStep;
|
|
299
|
-
}
|
|
300
|
-
return resultingNextStep;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
260
|
const skipQuestion = () => {
|
|
304
261
|
/**
|
|
305
262
|
* Emitted when step is completed
|
|
@@ -308,7 +265,7 @@ export default {
|
|
|
308
265
|
*/
|
|
309
266
|
emit(props.completedEventName, {
|
|
310
267
|
answers: props.payload.skippable.defaultAnswer ? [props.payload.skippable.defaultAnswer.value] : [],
|
|
311
|
-
nextStep:
|
|
268
|
+
nextStep: props.payload?.skippable?.nextStep,
|
|
312
269
|
});
|
|
313
270
|
};
|
|
314
271
|
|
|
@@ -323,19 +280,6 @@ export default {
|
|
|
323
280
|
);
|
|
324
281
|
};
|
|
325
282
|
|
|
326
|
-
const isAnswerMatching = (questionCode, answerCode) => {
|
|
327
|
-
return props.answers[questionCode] && props.answers[questionCode][0]?.code === answerCode;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
const isAnswerContaining = (questionCode, answerCode) => {
|
|
331
|
-
return (
|
|
332
|
-
props.answers[questionCode] &&
|
|
333
|
-
props.answers[questionCode].findIndex((elt) => {
|
|
334
|
-
return elt.code === answerCode;
|
|
335
|
-
}) > -1
|
|
336
|
-
);
|
|
337
|
-
};
|
|
338
|
-
|
|
339
283
|
const getAnswerValue = (answerCode, path) => {
|
|
340
284
|
if (!props.answers[answerCode] || props.answers[answerCode].length === 0) {
|
|
341
285
|
return null;
|
|
@@ -349,7 +293,9 @@ export default {
|
|
|
349
293
|
}
|
|
350
294
|
return valueToDecorate;
|
|
351
295
|
};
|
|
352
|
-
|
|
296
|
+
onMounted(() => {
|
|
297
|
+
updateSelectedAnswers();
|
|
298
|
+
});
|
|
353
299
|
return {
|
|
354
300
|
BACK_ICON,
|
|
355
301
|
INFO_ICON,
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
</m-flexy-col>
|
|
57
57
|
</m-flex>
|
|
58
58
|
|
|
59
|
-
<m-flex class="pb-space-input__buttons-container" direction="column">
|
|
59
|
+
<m-flex class="pb-space-input__buttons-container" direction="column" align-items="center">
|
|
60
60
|
<m-button
|
|
61
61
|
class="pb-space-input__button"
|
|
62
62
|
:label="computedPayload.viewModel.actionLabel"
|
|
@@ -64,6 +64,15 @@
|
|
|
64
64
|
size="l"
|
|
65
65
|
@click="handleFormSubmit"
|
|
66
66
|
/>
|
|
67
|
+
<m-link
|
|
68
|
+
v-if="payload.skippable"
|
|
69
|
+
class="pb-space-input__link"
|
|
70
|
+
:label="payload.skippable.label"
|
|
71
|
+
:theme="payload.skippable.theme"
|
|
72
|
+
width="full"
|
|
73
|
+
size="l"
|
|
74
|
+
@click="skipQuestion"
|
|
75
|
+
/>
|
|
67
76
|
</m-flex>
|
|
68
77
|
</m-flex>
|
|
69
78
|
</form>
|
|
@@ -233,6 +242,17 @@ export default {
|
|
|
233
242
|
],
|
|
234
243
|
});
|
|
235
244
|
});
|
|
245
|
+
const skipQuestion = () => {
|
|
246
|
+
/**
|
|
247
|
+
* Emitted when step is completed
|
|
248
|
+
* @event dynamic event name according to completedEventName prop
|
|
249
|
+
* @type {Event}
|
|
250
|
+
*/
|
|
251
|
+
emit(props.completedEventName, {
|
|
252
|
+
answers: props.payload?.skippable?.defaultAnswer ? [props.payload?.skippable?.defaultAnswer] : [],
|
|
253
|
+
nextStep: props.payload?.skippable?.nextStep,
|
|
254
|
+
});
|
|
255
|
+
};
|
|
236
256
|
|
|
237
257
|
const isShowingFooter = computed(() => {
|
|
238
258
|
return computedPayload.value.viewModel.footer;
|
|
@@ -254,6 +274,7 @@ export default {
|
|
|
254
274
|
handleFormSubmit,
|
|
255
275
|
isShowingFooter,
|
|
256
276
|
decorateBoolean,
|
|
277
|
+
skipQuestion,
|
|
257
278
|
};
|
|
258
279
|
},
|
|
259
280
|
};
|
|
@@ -382,5 +403,9 @@ $responsive-breakpoint: 'm';
|
|
|
382
403
|
position: sticky;
|
|
383
404
|
z-index: 1;
|
|
384
405
|
}
|
|
406
|
+
|
|
407
|
+
&__link {
|
|
408
|
+
margin-top: $mu250;
|
|
409
|
+
}
|
|
385
410
|
}
|
|
386
411
|
</style>
|
|
@@ -186,11 +186,10 @@ import MIcon from '../../mozaic/icon/MIcon';
|
|
|
186
186
|
import MImage from '../../mozaic/image/MImage';
|
|
187
187
|
import MLink from '../../mozaic/link/MLink';
|
|
188
188
|
import PbCard from '../../cards/PbCard';
|
|
189
|
-
import { sortAnswers } from '.././sortAnswers';
|
|
190
189
|
import MDialog from '../../mozaic/dialog/MDialog';
|
|
191
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
192
190
|
import PbUploadDocumentForm from './PbUploadDocumentForm';
|
|
193
191
|
import PbStickyFooter from '../../sticky-footer/PbStickyFooter';
|
|
192
|
+
import { areConditionsValid } from '../../../service/scenarioConditionals';
|
|
194
193
|
|
|
195
194
|
const BACK_ICON =
|
|
196
195
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -327,7 +326,7 @@ export default {
|
|
|
327
326
|
updateDefaultAnswers() {
|
|
328
327
|
if (this.payload?.answers) {
|
|
329
328
|
this.displayableAnswers = Object.values(this.payload?.answers).filter((answer) => {
|
|
330
|
-
return
|
|
329
|
+
return areConditionsValid(answer.conditions, this.answers, this.runtimeOptions) && !answer.selected;
|
|
331
330
|
});
|
|
332
331
|
Object.values(this.payload?.answers).map((answer) => {
|
|
333
332
|
let found = false;
|
|
@@ -371,42 +370,20 @@ export default {
|
|
|
371
370
|
);
|
|
372
371
|
},
|
|
373
372
|
isShowingFooter(viewModel) {
|
|
374
|
-
return viewModel.footer &&
|
|
375
|
-
},
|
|
376
|
-
areConditionsValid(conditions) {
|
|
377
|
-
let valid = true;
|
|
378
|
-
|
|
379
|
-
if (conditions) {
|
|
380
|
-
valid = false;
|
|
381
|
-
for (const condition of conditions) {
|
|
382
|
-
try {
|
|
383
|
-
let conditionValid = new Function(
|
|
384
|
-
'isAnswerMatching',
|
|
385
|
-
'isAnswerContaining',
|
|
386
|
-
'answers',
|
|
387
|
-
'runtimeOptions',
|
|
388
|
-
`return ${condition}`,
|
|
389
|
-
).call(this, this.isAnswerMatching, this.isAnswerContaining, this.answers, this.runtimeOptions);
|
|
390
|
-
|
|
391
|
-
valid = valid || conditionValid;
|
|
392
|
-
} catch (error) {
|
|
393
|
-
console.error(error);
|
|
394
|
-
valid = valid || true;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
return valid;
|
|
373
|
+
return viewModel.footer && areConditionsValid(viewModel.footer.conditions, this.answers, this.runtimeOptions);
|
|
400
374
|
},
|
|
375
|
+
|
|
401
376
|
isAnswerDisabled(answer) {
|
|
402
|
-
return
|
|
377
|
+
return (
|
|
378
|
+
answer.viewModel.disabled &&
|
|
379
|
+
areConditionsValid(answer.viewModel.disabled.conditions, this.answers, this.runtimeOptions)
|
|
380
|
+
);
|
|
403
381
|
},
|
|
404
382
|
selectAnswer(stepCode, answer) {
|
|
405
383
|
if (answer.code === 'ADD_DOCUMENT') {
|
|
406
384
|
this.$refs.pbUploadDocumentForm.$refs.pbDocumentUploadFormInput.click();
|
|
407
385
|
}
|
|
408
386
|
},
|
|
409
|
-
// Function used by the scenario conditions
|
|
410
387
|
getAnswerValue(answerCode, path) {
|
|
411
388
|
if (!this.answers[answerCode] || this.answers[answerCode].length === 0) {
|
|
412
389
|
return null;
|
|
@@ -414,28 +391,16 @@ export default {
|
|
|
414
391
|
|
|
415
392
|
return objectPath.get(this.answers[answerCode][0], path);
|
|
416
393
|
},
|
|
417
|
-
// Function used by the scenario conditions
|
|
418
|
-
isAnswerMatching(questionCode, answerCode) {
|
|
419
|
-
return this?.answers[questionCode] && this?.answers[questionCode][0]?.code === answerCode;
|
|
420
|
-
},
|
|
421
|
-
isAnswerContaining(questionCode, answerCode) {
|
|
422
|
-
return (
|
|
423
|
-
this?.answers[questionCode] &&
|
|
424
|
-
this?.answers[questionCode].findIndex((elt) => {
|
|
425
|
-
return elt.code === answerCode;
|
|
426
|
-
}) > -1
|
|
427
|
-
);
|
|
428
|
-
},
|
|
429
394
|
validMultiSelect(multiSelectOptions) {
|
|
430
395
|
this.$emit(this.completedEventName, {
|
|
431
396
|
answers: this.selectedDocuments,
|
|
432
|
-
nextStep:
|
|
397
|
+
nextStep: multiSelectOptions.nextStep,
|
|
433
398
|
});
|
|
434
399
|
},
|
|
435
400
|
skipQuestion(button) {
|
|
436
401
|
this.$emit(this.completedEventName, {
|
|
437
402
|
answers: this.selectedDocuments,
|
|
438
|
-
nextStep:
|
|
403
|
+
nextStep: button.nextStep,
|
|
439
404
|
});
|
|
440
405
|
},
|
|
441
406
|
resetMultiSelect(multiSelectOptions, answers) {
|
|
@@ -450,22 +415,6 @@ export default {
|
|
|
450
415
|
answer.selected = false;
|
|
451
416
|
});
|
|
452
417
|
},
|
|
453
|
-
computeNextStep(nextStep) {
|
|
454
|
-
let resultingNextStep;
|
|
455
|
-
|
|
456
|
-
if (nextStep?.conditionals) {
|
|
457
|
-
for (const conditional of nextStep.conditionals) {
|
|
458
|
-
if (this.areConditionsValid(conditional.conditions)) {
|
|
459
|
-
resultingNextStep = this.computeNextStep(conditional.nextStep);
|
|
460
|
-
break;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
} else {
|
|
464
|
-
resultingNextStep = nextStep;
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
return resultingNextStep;
|
|
468
|
-
},
|
|
469
418
|
handleShowMoreClick() {
|
|
470
419
|
this.activateShowMoreAnimation();
|
|
471
420
|
this.showMore();
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
:class="`pb-restitution pb-restitution--${componentTheme}`"
|
|
5
5
|
align-items="center"
|
|
6
6
|
direction="column"
|
|
7
|
-
:style="`min-height: ${
|
|
7
|
+
:style="`min-height: ${restitutionMinHeight};`"
|
|
8
8
|
ref="pbRestitution"
|
|
9
9
|
>
|
|
10
10
|
<m-link
|
|
@@ -78,6 +78,7 @@ import PbRestitutionBody from './PbRestitutionBody';
|
|
|
78
78
|
import PbProgressionPrice from '../progression-price/PbProgressionPrice';
|
|
79
79
|
import PbProjectItemSave from '../project-item-save/PbProjectItemSave';
|
|
80
80
|
import PbRestitutionExit from './PbRestitutionExit';
|
|
81
|
+
import { areConditionsValid } from '../../service/scenarioConditionals';
|
|
81
82
|
|
|
82
83
|
const BACK_ICON =
|
|
83
84
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -165,6 +166,7 @@ export default {
|
|
|
165
166
|
notifications: [],
|
|
166
167
|
displayDialog: false,
|
|
167
168
|
dialogViewModel: null,
|
|
169
|
+
restitutionMinHeight: '100vh',
|
|
168
170
|
}),
|
|
169
171
|
|
|
170
172
|
computed: {
|
|
@@ -184,7 +186,7 @@ export default {
|
|
|
184
186
|
options: [],
|
|
185
187
|
};
|
|
186
188
|
formattedExitOptions.options = this.payload?.exitOptions?.options?.filter(
|
|
187
|
-
(option) => !option.conditions ||
|
|
189
|
+
(option) => !option.conditions || areConditionsValid(option.conditions, this.answers, this.runtimeOptions),
|
|
188
190
|
);
|
|
189
191
|
return formattedExitOptions;
|
|
190
192
|
},
|
|
@@ -200,7 +202,7 @@ export default {
|
|
|
200
202
|
if (this.payload?.callToActions) {
|
|
201
203
|
const saveAction = Object.values(this.payload.callToActions).find((cta) => {
|
|
202
204
|
return (
|
|
203
|
-
|
|
205
|
+
areConditionsValid(cta.conditions, this.answers, this.runtimeOptions) &&
|
|
204
206
|
cta.action?.type === 'MODAL' &&
|
|
205
207
|
cta.action?.component === 'PbProjectItemSave'
|
|
206
208
|
);
|
|
@@ -208,6 +210,9 @@ export default {
|
|
|
208
210
|
this.projectSaveItemPayload = saveAction ? saveAction.payload : {};
|
|
209
211
|
this.showSaveProjectItem = this.showSaveEstimate;
|
|
210
212
|
}
|
|
213
|
+
setTimeout(() => {
|
|
214
|
+
this.restitutionMinHeight = this.payload?.exitOptions ? 'auto' : this.minHeight;
|
|
215
|
+
}, 300);
|
|
211
216
|
},
|
|
212
217
|
|
|
213
218
|
mounted() {
|
|
@@ -219,41 +224,11 @@ export default {
|
|
|
219
224
|
updateDisplayedCta() {
|
|
220
225
|
if (this.payload?.callToActions) {
|
|
221
226
|
this.displayedCta = Object.values(this.payload.callToActions).filter((cta) => {
|
|
222
|
-
return
|
|
227
|
+
return areConditionsValid(cta.conditions, this.answers, this.runtimeOptions);
|
|
223
228
|
});
|
|
224
229
|
}
|
|
225
230
|
},
|
|
226
231
|
|
|
227
|
-
areConditionsValid(conditions) {
|
|
228
|
-
let valid = true;
|
|
229
|
-
|
|
230
|
-
if (conditions) {
|
|
231
|
-
valid = false;
|
|
232
|
-
for (const condition of conditions) {
|
|
233
|
-
try {
|
|
234
|
-
valid =
|
|
235
|
-
valid ||
|
|
236
|
-
new Function('isAnswerMatching', 'answers', 'runtimeOptions', `return ${condition}`).call(
|
|
237
|
-
this,
|
|
238
|
-
this.isAnswerMatching,
|
|
239
|
-
this.answers,
|
|
240
|
-
this.runtimeOptions,
|
|
241
|
-
);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.error(error);
|
|
244
|
-
valid = valid || true;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return valid;
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
// Function used by the scenario conditions
|
|
253
|
-
isAnswerMatching(questionCode, answerCode) {
|
|
254
|
-
return this?.answers[questionCode] && this?.answers[questionCode][0]?.code === answerCode;
|
|
255
|
-
},
|
|
256
|
-
|
|
257
232
|
callAction(action) {
|
|
258
233
|
if (action.type === 'MODAL') {
|
|
259
234
|
if (action.component === 'PbProjectItemSave') {
|
|
@@ -72,6 +72,7 @@ import MLink from '../mozaic/link/MLink';
|
|
|
72
72
|
import { priceFormatter } from '../../service/priceFormatter';
|
|
73
73
|
import PbRestitutionBlock from './PbRestitutionBlock';
|
|
74
74
|
import MNotification from '../mozaic/notifications/MNotification';
|
|
75
|
+
import { areConditionsValid } from '../../service/scenarioConditionals';
|
|
75
76
|
|
|
76
77
|
export default {
|
|
77
78
|
name: 'PbRestitutionBody',
|
|
@@ -186,44 +187,7 @@ export default {
|
|
|
186
187
|
},
|
|
187
188
|
|
|
188
189
|
areConditionsValid(conditions) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (conditions) {
|
|
192
|
-
valid = false;
|
|
193
|
-
for (const condition of conditions) {
|
|
194
|
-
try {
|
|
195
|
-
let conditionValid = new Function(
|
|
196
|
-
'isAnswerMatching',
|
|
197
|
-
'isAnswerContaining',
|
|
198
|
-
'answers',
|
|
199
|
-
'runtimeOptions',
|
|
200
|
-
`return ${condition}`,
|
|
201
|
-
).call(this, this.isAnswerMatching, this.isAnswerContaining, this.answers, this.runtimeOptions);
|
|
202
|
-
|
|
203
|
-
valid = valid || conditionValid;
|
|
204
|
-
} catch (error) {
|
|
205
|
-
console.error(error);
|
|
206
|
-
valid = valid || true;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return valid;
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
// Function used by the scenario conditions
|
|
215
|
-
isAnswerMatching(questionCode, answerCode) {
|
|
216
|
-
return this?.answers && this?.answers[questionCode] && this?.answers[questionCode][0]?.code === answerCode;
|
|
217
|
-
},
|
|
218
|
-
|
|
219
|
-
isAnswerContaining(questionCode, answerCode) {
|
|
220
|
-
return (
|
|
221
|
-
this?.answers &&
|
|
222
|
-
this?.answers[questionCode] &&
|
|
223
|
-
this?.answers[questionCode].findIndex((elt) => {
|
|
224
|
-
return elt.code === answerCode;
|
|
225
|
-
}) > -1
|
|
226
|
-
);
|
|
190
|
+
return areConditionsValid(conditions, this.answers, this.runtimeOptions);
|
|
227
191
|
},
|
|
228
192
|
},
|
|
229
193
|
};
|
|
@@ -89,6 +89,7 @@ import PbRestitution from '../restitution/PbRestitution';
|
|
|
89
89
|
import PbSmartProgressionPrice from '../progression-price/PbSmartProgressionPrice';
|
|
90
90
|
import PbSpaceInput from '../question/space-input/PbSpaceInput';
|
|
91
91
|
import PbUploadDocument from '../question/upload-document/PbUploadDocument';
|
|
92
|
+
import { areConditionsValid } from '../../service/scenarioConditionals';
|
|
92
93
|
|
|
93
94
|
export default {
|
|
94
95
|
name: 'PbScenario',
|
|
@@ -444,7 +445,7 @@ export default {
|
|
|
444
445
|
|
|
445
446
|
if (nextStep?.conditionals) {
|
|
446
447
|
for (const conditional of nextStep.conditionals) {
|
|
447
|
-
if (areConditionsValid(conditional.conditions)) {
|
|
448
|
+
if (areConditionsValid(conditional.conditions, state.value.answers, props.runtimeOptions)) {
|
|
448
449
|
resultingNextStep = computeNextStep(conditional.nextStep);
|
|
449
450
|
break;
|
|
450
451
|
}
|
|
@@ -455,42 +456,7 @@ export default {
|
|
|
455
456
|
|
|
456
457
|
return resultingNextStep;
|
|
457
458
|
};
|
|
458
|
-
const areConditionsValid = (conditions) => {
|
|
459
|
-
let valid = true;
|
|
460
|
-
|
|
461
|
-
if (conditions) {
|
|
462
|
-
valid = false;
|
|
463
|
-
for (const condition of conditions) {
|
|
464
|
-
valid =
|
|
465
|
-
valid ||
|
|
466
|
-
new Function(
|
|
467
|
-
'isAnswerMatching',
|
|
468
|
-
'isAnswerContaining',
|
|
469
|
-
'answers',
|
|
470
|
-
'runtimeOptions',
|
|
471
|
-
`return ${condition}`,
|
|
472
|
-
).call(this, isAnswerMatching, isAnswerContaining, state.value.answers, props.runtimeOptions);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
459
|
|
|
476
|
-
return valid;
|
|
477
|
-
};
|
|
478
|
-
// Function used by the scenario conditions
|
|
479
|
-
const isAnswerMatching = (questionCode, answerCode) => {
|
|
480
|
-
return (
|
|
481
|
-
state.value.answers[questionCode] &&
|
|
482
|
-
state.value.answers[questionCode][0] &&
|
|
483
|
-
state.value.answers[questionCode][0].code === answerCode
|
|
484
|
-
);
|
|
485
|
-
};
|
|
486
|
-
const isAnswerContaining = (questionCode, answerCode) => {
|
|
487
|
-
return (
|
|
488
|
-
state.value.answers[questionCode] &&
|
|
489
|
-
state.value.answers[questionCode].findIndex((elt) => {
|
|
490
|
-
return elt.code === answerCode;
|
|
491
|
-
}) > -1
|
|
492
|
-
);
|
|
493
|
-
};
|
|
494
460
|
const stepAnimationName = () => {
|
|
495
461
|
const componentName = state.value.currentStep?.component;
|
|
496
462
|
let animationName = 'pb-scenario__step--slide';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function Condition(answers, runtimeOptions, condition) {
|
|
2
|
+
this.answers = answers;
|
|
3
|
+
this.runtimeOptions = runtimeOptions;
|
|
4
|
+
this.condition = condition;
|
|
5
|
+
|
|
6
|
+
this.isAnswerMatching = (questionCode, answerCode) => {
|
|
7
|
+
return this.answers[questionCode] && this.answers[questionCode][0]?.code === answerCode;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
this.isAnswerContaining = (questionCode, answerCode) => {
|
|
11
|
+
return (
|
|
12
|
+
this.answers[questionCode] &&
|
|
13
|
+
this.answers[questionCode].findIndex((elt) => {
|
|
14
|
+
return elt.code === answerCode;
|
|
15
|
+
}) > -1
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
this.isValid = new Function(
|
|
20
|
+
'isAnswerMatching',
|
|
21
|
+
'isAnswerContaining',
|
|
22
|
+
'answers',
|
|
23
|
+
'runtimeOptions',
|
|
24
|
+
`return ${condition}`,
|
|
25
|
+
).call(this, this.isAnswerMatching, this.isAnswerContaining, this.answers, this.runtimeOptions);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const areConditionsValid = (conditions, answers, runtimeOptions) => {
|
|
29
|
+
let valid = true;
|
|
30
|
+
|
|
31
|
+
if (conditions) {
|
|
32
|
+
valid = false;
|
|
33
|
+
for (const condition of conditions) {
|
|
34
|
+
try {
|
|
35
|
+
valid = valid || new Condition(answers, runtimeOptions, condition).isValid;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(error);
|
|
38
|
+
valid = valid || true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return valid;
|
|
44
|
+
};
|