project-booster-vue 8.115.8 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-booster-vue",
3
- "version": "8.115.8",
3
+ "version": "8.115.9",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "test:unit": "vue-cli-service test:unit --forceExit --detectOpenHandles",
@@ -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 this.areConditionsValid(answer.conditions);
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
- this.areConditionsValid(this.payload.answers[answerCode].conditions)
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 && this.areConditionsValid(viewModel.footer.conditions);
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 answer.viewModel.disabled && this.areConditionsValid(answer.viewModel.disabled.conditions);
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: this.computeNextStep(answer.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: this.computeNextStep(multiSelectOptions.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: this.computeNextStep(button.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();
@@ -204,7 +204,7 @@ export default {
204
204
  return props.payload?.viewModel?.showMore?.position ?? 'center';
205
205
  });
206
206
 
207
- // Submition
207
+ // Submit
208
208
  const validateButtonProps = computed(() => {
209
209
  let label, leftIcon, rightIcon;
210
210
 
@@ -253,52 +253,10 @@ export default {
253
253
  */
254
254
  emit(props.completedEventName, {
255
255
  answers: answersToSubmit,
256
- nextStep: computeNextStep(nextStep),
256
+ nextStep: nextStep,
257
257
  });
258
258
  };
259
259
 
260
- // Scenario management
261
- const areConditionsValid = (conditions) => {
262
- let valid = true;
263
-
264
- if (conditions) {
265
- valid = false;
266
- for (const condition of conditions) {
267
- try {
268
- let conditionValid = new Function(
269
- 'isAnswerMatching',
270
- 'isAnswerContaining',
271
- 'answers',
272
- 'runtimeOptions',
273
- `return ${condition}`,
274
- ).call(this, isAnswerMatching, isAnswerContaining, props.answers, props.runtimeOptions);
275
-
276
- valid = valid || conditionValid;
277
- } catch (error) {
278
- console.error(error);
279
- valid = valid || true;
280
- }
281
- }
282
- }
283
- return valid;
284
- };
285
-
286
- const computeNextStep = (nextStep) => {
287
- let resultingNextStep;
288
-
289
- if (nextStep?.conditionals) {
290
- for (const conditional of nextStep.conditionals) {
291
- if (areConditionsValid(conditional.conditions)) {
292
- resultingNextStep = computeNextStep(conditional.nextStep);
293
- break;
294
- }
295
- }
296
- } else {
297
- resultingNextStep = nextStep;
298
- }
299
- return resultingNextStep;
300
- };
301
-
302
260
  const skipQuestion = () => {
303
261
  /**
304
262
  * Emitted when step is completed
@@ -307,7 +265,7 @@ export default {
307
265
  */
308
266
  emit(props.completedEventName, {
309
267
  answers: props.payload.skippable.defaultAnswer ? [props.payload.skippable.defaultAnswer.value] : [],
310
- nextStep: computeNextStep(props.payload?.skippable?.nextStep),
268
+ nextStep: props.payload?.skippable?.nextStep,
311
269
  });
312
270
  };
313
271
 
@@ -322,19 +280,6 @@ export default {
322
280
  );
323
281
  };
324
282
 
325
- const isAnswerMatching = (questionCode, answerCode) => {
326
- return props.answers[questionCode] && props.answers[questionCode][0]?.code === answerCode;
327
- };
328
-
329
- const isAnswerContaining = (questionCode, answerCode) => {
330
- return (
331
- props.answers[questionCode] &&
332
- props.answers[questionCode].findIndex((elt) => {
333
- return elt.code === answerCode;
334
- }) > -1
335
- );
336
- };
337
-
338
283
  const getAnswerValue = (answerCode, path) => {
339
284
  if (!props.answers[answerCode] || props.answers[answerCode].length === 0) {
340
285
  return null;
@@ -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 this.areConditionsValid(answer.conditions) && !answer.selected;
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 && this.areConditionsValid(viewModel.footer.conditions);
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 answer.viewModel.disabled && this.areConditionsValid(answer.viewModel.disabled.conditions);
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: this.computeNextStep(multiSelectOptions.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: this.computeNextStep(button.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();
@@ -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';
@@ -185,7 +186,7 @@ export default {
185
186
  options: [],
186
187
  };
187
188
  formattedExitOptions.options = this.payload?.exitOptions?.options?.filter(
188
- (option) => !option.conditions || this.areConditionsValid(option.conditions),
189
+ (option) => !option.conditions || areConditionsValid(option.conditions, this.answers, this.runtimeOptions),
189
190
  );
190
191
  return formattedExitOptions;
191
192
  },
@@ -201,7 +202,7 @@ export default {
201
202
  if (this.payload?.callToActions) {
202
203
  const saveAction = Object.values(this.payload.callToActions).find((cta) => {
203
204
  return (
204
- this.areConditionsValid(cta.conditions) &&
205
+ areConditionsValid(cta.conditions, this.answers, this.runtimeOptions) &&
205
206
  cta.action?.type === 'MODAL' &&
206
207
  cta.action?.component === 'PbProjectItemSave'
207
208
  );
@@ -223,41 +224,11 @@ export default {
223
224
  updateDisplayedCta() {
224
225
  if (this.payload?.callToActions) {
225
226
  this.displayedCta = Object.values(this.payload.callToActions).filter((cta) => {
226
- return this.areConditionsValid(cta.conditions);
227
+ return areConditionsValid(cta.conditions, this.answers, this.runtimeOptions);
227
228
  });
228
229
  }
229
230
  },
230
231
 
231
- areConditionsValid(conditions) {
232
- let valid = true;
233
-
234
- if (conditions) {
235
- valid = false;
236
- for (const condition of conditions) {
237
- try {
238
- valid =
239
- valid ||
240
- new Function('isAnswerMatching', 'answers', 'runtimeOptions', `return ${condition}`).call(
241
- this,
242
- this.isAnswerMatching,
243
- this.answers,
244
- this.runtimeOptions,
245
- );
246
- } catch (error) {
247
- console.error(error);
248
- valid = valid || true;
249
- }
250
- }
251
- }
252
-
253
- return valid;
254
- },
255
-
256
- // Function used by the scenario conditions
257
- isAnswerMatching(questionCode, answerCode) {
258
- return this?.answers[questionCode] && this?.answers[questionCode][0]?.code === answerCode;
259
- },
260
-
261
232
  callAction(action) {
262
233
  if (action.type === 'MODAL') {
263
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
- let valid = true;
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
+ };