project-booster-vue 9.41.0 → 9.41.1
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/question/PbQuestion.vue +1 -49
- package/src/components/question/amount-input/PbAmountInput.vue +1 -1
- package/src/components/question/city-search/PbCitySearch.vue +1 -2
- package/src/components/question/configurations-import/PbConfigurationsImport.vue +1 -2
- package/src/components/question/dimensions-input/PbDimensionsInput.vue +1 -1
- package/src/components/question/incremental-amount-input/PbIncrementalAmountInput.vue +1 -4
- package/src/components/question/list-select/PbListSelect.vue +1 -3
- package/src/components/question/name-input/PbNameInput.vue +1 -1
- package/src/components/question/space-input/PbSpaceInput.vue +1 -1
- package/src/components/question/upload-document/PbUploadDocument.vue +1 -2
- package/src/services/decorate.ts +65 -0
package/package.json
CHANGED
|
@@ -352,7 +352,6 @@
|
|
|
352
352
|
|
|
353
353
|
<script lang="ts">
|
|
354
354
|
import { defineComponent, PropType } from 'vue';
|
|
355
|
-
import objectPath from 'object-path';
|
|
356
355
|
import MButton from '../mozaic/buttons/MButton.vue';
|
|
357
356
|
import MContainer from '../mozaic/grid/MContainer.vue';
|
|
358
357
|
import MDialog from '../mozaic/dialog/MDialog.vue';
|
|
@@ -366,6 +365,7 @@ import PbCard from '../cards/PbCard.vue';
|
|
|
366
365
|
import PbStickyFooter from '../sticky-footer/PbStickyFooter.vue';
|
|
367
366
|
import { sortAnswers } from './sortAnswers';
|
|
368
367
|
import { areConditionsValid } from '../../services/scenarioConditionals';
|
|
368
|
+
import { decorate } from '@/services/decorate';
|
|
369
369
|
import {
|
|
370
370
|
ScenarioStepAnswer,
|
|
371
371
|
ScenarioStepAnswerDialog,
|
|
@@ -383,54 +383,6 @@ const BACK_ICON =
|
|
|
383
383
|
const INFO_ICON =
|
|
384
384
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Notification_Information_24px.svg';
|
|
385
385
|
|
|
386
|
-
// Function used by the scenario conditions
|
|
387
|
-
const getAnswerValue = (answers: Map<string, ScenarioStepAnswer[]>) => {
|
|
388
|
-
return (answerCode: string, path: string) => {
|
|
389
|
-
let answerValue: ScenarioStepAnswer | undefined = undefined;
|
|
390
|
-
if (answers?.get(answerCode)) {
|
|
391
|
-
const answerValues = answers.get(answerCode) ?? [];
|
|
392
|
-
answerValue = objectPath.get(answerValues[0], path);
|
|
393
|
-
}
|
|
394
|
-
return answerValue;
|
|
395
|
-
};
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
export const doEval = (
|
|
399
|
-
answers: Map<string, ScenarioStepAnswer[]>,
|
|
400
|
-
valueToEval: string,
|
|
401
|
-
defaultValue: string,
|
|
402
|
-
runtimeOptions: any,
|
|
403
|
-
) => {
|
|
404
|
-
return new Function('getAnswerValue', 'answers', 'defaultValue', 'runtimeOptions', `return ${valueToEval}`).call(
|
|
405
|
-
this,
|
|
406
|
-
getAnswerValue(answers),
|
|
407
|
-
Object.fromEntries(answers),
|
|
408
|
-
defaultValue,
|
|
409
|
-
runtimeOptions,
|
|
410
|
-
);
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
//TODO Think to move this kind of function in something like "helpers" or "tools"
|
|
414
|
-
// because this is use in multiple components (as PbIncrementalAmountInput.vue),
|
|
415
|
-
// and it shouldn't be in a component.
|
|
416
|
-
export const decorate = (
|
|
417
|
-
answers: Map<string, ScenarioStepAnswer[]>,
|
|
418
|
-
runtimeOptions = {},
|
|
419
|
-
valueToDecorate: string,
|
|
420
|
-
defaultValue = '',
|
|
421
|
-
): string => {
|
|
422
|
-
let decoratedValue = valueToDecorate;
|
|
423
|
-
if (valueToDecorate) {
|
|
424
|
-
const stringToEval = `\`${valueToDecorate}\``;
|
|
425
|
-
try {
|
|
426
|
-
decoratedValue = doEval(answers, stringToEval, defaultValue, runtimeOptions);
|
|
427
|
-
} catch (error) {
|
|
428
|
-
decoratedValue = valueToDecorate || defaultValue;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
return decoratedValue;
|
|
432
|
-
};
|
|
433
|
-
|
|
434
386
|
export default defineComponent({
|
|
435
387
|
name: 'PbQuestion',
|
|
436
388
|
|
|
@@ -63,7 +63,7 @@ import MTextInput from './../../mozaic/text-input/MTextInput.vue';
|
|
|
63
63
|
import DEFAULT_PAYLOAD from './default-payload.json';
|
|
64
64
|
import { AmountInputPayload } from '@/components/question/amount-input/AmountInput';
|
|
65
65
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
66
|
-
import { decorate } from '@/
|
|
66
|
+
import { decorate } from '@/services/decorate';
|
|
67
67
|
|
|
68
68
|
const BACK_ICON =
|
|
69
69
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -106,14 +106,13 @@ import debounce from 'lodash.debounce';
|
|
|
106
106
|
import merge from 'lodash.merge';
|
|
107
107
|
import initGoogleMapsApi from './google-maps-api';
|
|
108
108
|
import axios from 'axios';
|
|
109
|
-
import objectPath from 'object-path';
|
|
110
109
|
import MFlex from '../../mozaic/flex/MFlex.vue';
|
|
111
110
|
import MButton from '../../mozaic/buttons/MButton.vue';
|
|
112
111
|
import MLink from '../../mozaic/link/MLink.vue';
|
|
113
112
|
import MTextInput from '../../mozaic/text-input/MTextInput.vue';
|
|
114
113
|
import DEFAULT_PAYLOAD from './default-payload.json';
|
|
115
114
|
import { DebouncedFunc } from 'lodash-es';
|
|
116
|
-
import { decorate } from '@/
|
|
115
|
+
import { decorate } from '@/services/decorate';
|
|
117
116
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
118
117
|
|
|
119
118
|
const BACK_ICON =
|
|
@@ -165,7 +165,6 @@ import MLink from '../../../components/mozaic/link/MLink.vue';
|
|
|
165
165
|
import MNotification from '../../../components/mozaic/notifications/MNotification.vue';
|
|
166
166
|
import PbCard from '../../../components/cards/PbCard.vue';
|
|
167
167
|
import { format } from 'date-fns';
|
|
168
|
-
import objectPath from 'object-path';
|
|
169
168
|
import {
|
|
170
169
|
ConfigurationsImportMultiSelectAction,
|
|
171
170
|
ConfigurationsImportPayload,
|
|
@@ -174,7 +173,7 @@ import {
|
|
|
174
173
|
} from '@/components/question/configurations-import/ConfigurationsImport';
|
|
175
174
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
176
175
|
import { Configuration } from '@/types/pb/Configuration';
|
|
177
|
-
import { decorate } from '@/
|
|
176
|
+
import { decorate } from '@/services/decorate';
|
|
178
177
|
|
|
179
178
|
const BACK_ICON =
|
|
180
179
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -101,7 +101,7 @@ import MIcon from '../../mozaic/icon/MIcon.vue';
|
|
|
101
101
|
import { ref } from 'vue';
|
|
102
102
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
103
103
|
import { DimensionsInputPayload } from '@/components/question/dimensions-input/DimensionsInput';
|
|
104
|
-
import { decorate } from '@/
|
|
104
|
+
import { decorate } from '@/services/decorate';
|
|
105
105
|
|
|
106
106
|
const BACK_ICON =
|
|
107
107
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -72,7 +72,7 @@ import MLink from '../../mozaic/link/MLink.vue';
|
|
|
72
72
|
import MButton from '../../mozaic/buttons/MButton.vue';
|
|
73
73
|
import { ref } from 'vue';
|
|
74
74
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
75
|
-
import { decorate } from '@/
|
|
75
|
+
import { decorate } from '@/services/decorate';
|
|
76
76
|
import MQuantitySelector from '../../mozaic/quantityselector/MQuantitySelector.vue';
|
|
77
77
|
import { IncrementalAmountPayload } from '@/components/question/incremental-amount-input/IncrementalAmount';
|
|
78
78
|
|
|
@@ -169,9 +169,6 @@ export default defineComponent({
|
|
|
169
169
|
let tempPayload = cloneDeep(DEFAULT_PAYLOAD);
|
|
170
170
|
tempPayload = merge(tempPayload, props.payload);
|
|
171
171
|
|
|
172
|
-
// This will doEval and decorate dynamically variables from JSON templates
|
|
173
|
-
// For instance:
|
|
174
|
-
// "${getAnswerValue('DEVELOPER', 'code') == 'YES' ? 'I'm developer' : 'I'm not developer'}"
|
|
175
172
|
tempPayload.viewModel.label = decorate(props.answers!, props.runtimeOptions, tempPayload.viewModel.label);
|
|
176
173
|
tempPayload.viewModel.subtitle = decorate(props.answers!, props.runtimeOptions, tempPayload.viewModel.subtitle);
|
|
177
174
|
|
|
@@ -75,15 +75,13 @@
|
|
|
75
75
|
<script lang="ts">
|
|
76
76
|
import { defineComponent, PropType } from 'vue';
|
|
77
77
|
import { ref, computed, onMounted, Ref } from 'vue';
|
|
78
|
-
import objectPath from 'object-path';
|
|
79
78
|
import MFlex from '../../mozaic/flex/MFlex.vue';
|
|
80
79
|
import MButton from '../../mozaic/buttons/MButton.vue';
|
|
81
80
|
import MLink from '../../mozaic/link/MLink.vue';
|
|
82
81
|
import PbItemsList from '../../items/PbItemsList.vue';
|
|
83
82
|
import { sortAnswers } from '../sortAnswers';
|
|
84
83
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
85
|
-
import {
|
|
86
|
-
import { decorate } from '@/components/question/PbQuestion.vue';
|
|
84
|
+
import { decorate } from '@/services/decorate';
|
|
87
85
|
|
|
88
86
|
const BACK_ICON =
|
|
89
87
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -60,7 +60,7 @@ import MToggle from '../../mozaic/toggle/MToggle.vue';
|
|
|
60
60
|
import DEFAULT_PAYLOAD from './default-payload.json';
|
|
61
61
|
import { NameInputPayload } from '@/components/question/name-input/NameInput';
|
|
62
62
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
63
|
-
import { decorate } from '@/
|
|
63
|
+
import { decorate } from '@/services/decorate';
|
|
64
64
|
|
|
65
65
|
const BACK_ICON =
|
|
66
66
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -146,7 +146,7 @@ import MDialog from '../../mozaic/dialog/MDialog.vue';
|
|
|
146
146
|
import DEFAULT_PAYLOAD from './default-payload.json';
|
|
147
147
|
import { SpaceInputPayload } from '@/components/question/space-input/SpaceInput';
|
|
148
148
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
149
|
-
import { decorate } from '@/
|
|
149
|
+
import { decorate } from '@/services/decorate';
|
|
150
150
|
|
|
151
151
|
const BACK_ICON =
|
|
152
152
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -139,7 +139,6 @@
|
|
|
139
139
|
|
|
140
140
|
<script lang="ts">
|
|
141
141
|
import { defineComponent, computed, onMounted, ref, PropType, Ref, ComponentCustomProperties } from 'vue';
|
|
142
|
-
import objectPath from 'object-path';
|
|
143
142
|
import MButton from '../../mozaic/buttons/MButton.vue';
|
|
144
143
|
import MContainer from '../../mozaic/grid/MContainer.vue';
|
|
145
144
|
import MFlex from '../../mozaic/flex/MFlex.vue';
|
|
@@ -156,7 +155,7 @@ import {
|
|
|
156
155
|
UploadDocumentViewModel,
|
|
157
156
|
} from '@/components/question/upload-document/UploadDocument';
|
|
158
157
|
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
159
|
-
import { decorate, doEval } from '@/
|
|
158
|
+
import { decorate, doEval } from '@/services/decorate';
|
|
160
159
|
|
|
161
160
|
const BACK_ICON =
|
|
162
161
|
'https://storage.googleapis.com/project-booster-media/mozaic-icons/svg/Navigation_Arrow_Arrow--Left_16px.svg';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import objectPath from 'object-path';
|
|
2
|
+
|
|
3
|
+
import { ScenarioStepAnswer } from '@/types/pb/Scenario';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This function will doEval and decorate dynamically variables from JSON templates.
|
|
7
|
+
*
|
|
8
|
+
* For instance:
|
|
9
|
+
* "${getAnswerValue('DEVELOPER', 'code') == 'YES' ? 'I'm developer' : 'I'm not developer'}".
|
|
10
|
+
*
|
|
11
|
+
* @param answers A map of string and an array of ScenarioStepAnswer.
|
|
12
|
+
* @param valueToDecorate Targeted value to decorate.
|
|
13
|
+
* @param defaultValue Empty string by default.
|
|
14
|
+
* @returns Decorated value.
|
|
15
|
+
*/
|
|
16
|
+
export function decorate(
|
|
17
|
+
answers: Map<string, ScenarioStepAnswer[]>,
|
|
18
|
+
runtimeOptions = {},
|
|
19
|
+
valueToDecorate: string,
|
|
20
|
+
defaultValue = '',
|
|
21
|
+
): string {
|
|
22
|
+
let decoratedValue = valueToDecorate;
|
|
23
|
+
if (valueToDecorate) {
|
|
24
|
+
const stringToEval = `\`${valueToDecorate}\``;
|
|
25
|
+
try {
|
|
26
|
+
decoratedValue = doEval(answers, stringToEval, defaultValue, runtimeOptions);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
decoratedValue = valueToDecorate || defaultValue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return decoratedValue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function doEval(
|
|
35
|
+
this: any,
|
|
36
|
+
answers: Map<string, ScenarioStepAnswer[]>,
|
|
37
|
+
valueToEval: string,
|
|
38
|
+
defaultValue: string,
|
|
39
|
+
runtimeOptions: unknown,
|
|
40
|
+
): any {
|
|
41
|
+
return new Function('getAnswerValue', 'answers', 'defaultValue', 'runtimeOptions', `return ${valueToEval}`).call(
|
|
42
|
+
this,
|
|
43
|
+
getAnswerValue(answers),
|
|
44
|
+
Object.fromEntries(answers),
|
|
45
|
+
defaultValue,
|
|
46
|
+
runtimeOptions,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Function used by the scenario conditions.
|
|
52
|
+
*
|
|
53
|
+
* @param answers A map of string and an array of ScenarioStepAnswer.
|
|
54
|
+
* @returns Answers values.
|
|
55
|
+
*/
|
|
56
|
+
function getAnswerValue(answers: Map<string, ScenarioStepAnswer[]>) {
|
|
57
|
+
return (answerCode: string, path: string) => {
|
|
58
|
+
let answerValue: ScenarioStepAnswer | undefined = undefined;
|
|
59
|
+
if (answers?.get(answerCode)) {
|
|
60
|
+
const answerValues = answers.get(answerCode) ?? [];
|
|
61
|
+
answerValue = objectPath.get(answerValues[0], path);
|
|
62
|
+
}
|
|
63
|
+
return answerValue;
|
|
64
|
+
};
|
|
65
|
+
}
|