@icure/form 2.0.10 → 2.1.0
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/.yarn/cache/@babel-runtime-npm-7.28.4-31bc1b0001-934b0a0460.zip +0 -0
- package/.yarn/cache/@icure-api-npm-5.3.18-99d397b97c-0da319f009.zip +0 -0
- package/.yarn/cache/@icure-motss-app-datepicker-npm-6.0.0-rc.40-ca1da7abbb-9bbe2bed34.zip +0 -0
- package/.yarn/cache/@lit-labs-ssr-dom-shim-npm-1.4.0-e5ef5fbeba-e267c25576.zip +0 -0
- package/.yarn/cache/@lit-reactive-element-npm-2.1.1-3875228c32-b9bbc9c089.zip +0 -0
- package/.yarn/cache/@lit-task-npm-1.0.3-48f265b3e9-790b6a2603.zip +0 -0
- package/.yarn/cache/@types-linkify-it-npm-5.0.0-576a16b976-ec98e03aa8.zip +0 -0
- package/.yarn/cache/@types-markdown-it-npm-14.1.2-d0c4e12c49-ad66e0b377.zip +0 -0
- package/.yarn/cache/@types-mdurl-npm-2.0.0-2f4116c0b0-78746e96c6.zip +0 -0
- package/.yarn/cache/big-integer-npm-1.6.52-4bec75720c-6e86885787.zip +0 -0
- package/.yarn/cache/date-fns-npm-2.30.0-895c790e0f-f7be015232.zip +0 -0
- package/.yarn/cache/libphonenumber-js-npm-1.12.23-68ac3c21d2-aad6c9ddc4.zip +0 -0
- package/.yarn/cache/{lit-element-npm-4.1.1-bb20932b82-74d0f2d6fb.zip → lit-element-npm-4.2.1-b5bc114ced-5925326176.zip} +0 -0
- package/.yarn/cache/{lit-html-npm-3.2.1-1662fc597d-1bacd9f8b2.zip → lit-html-npm-3.3.1-e3722d4f4a-de07c66945.zip} +0 -0
- package/.yarn/cache/{lit-npm-3.2.1-27cb5b7782-ee22bbc53d.zip → lit-npm-3.3.1-8f683c51f1-fb88f1ff80.zip} +0 -0
- package/.yarn/cache/lodash-npm-4.17.21-6382451519-eb835a2e51.zip +0 -0
- package/.yarn/cache/moment-npm-2.30.1-1c51a5c631-859236bab1.zip +0 -0
- package/.yarn/cache/prosemirror-commands-npm-1.7.1-5b2afb6640-2316c40ea2.zip +0 -0
- package/.yarn/cache/prosemirror-history-npm-1.4.1-ad68c86bb7-90f9bf59bc.zip +0 -0
- package/.yarn/cache/prosemirror-keymap-npm-1.2.3-0e7e0c8195-0a2eed2771.zip +0 -0
- package/.yarn/cache/prosemirror-markdown-npm-1.13.2-6e2f179fd8-ce9fcb3b13.zip +0 -0
- package/.yarn/cache/prosemirror-model-npm-1.25.3-95b23ed79b-2720e49795.zip +0 -0
- package/.yarn/cache/prosemirror-schema-basic-npm-1.2.4-8f943ded01-10ed022990.zip +0 -0
- package/.yarn/cache/prosemirror-schema-list-npm-1.5.1-7b138c5fed-6c7041e5b8.zip +0 -0
- package/.yarn/cache/prosemirror-transform-npm-1.10.4-f765dfe652-7b8b3ed82c.zip +0 -0
- package/.yarn/cache/prosemirror-view-npm-1.41.2-7f800b4d2b-263f15bec9.zip +0 -0
- package/.yarn/cache/text-encoding-npm-0.7.0-ff0c4af052-b6109a843f.zip +0 -0
- package/.yarn/cache/uuid-encoder-npm-1.2.0-6a9a810c6d-dd06230f08.zip +0 -0
- package/.yarn/cache/uuid-npm-8.3.2-eca0baba53-5575a8a75c.zip +0 -0
- package/.yarn/install-state.gz +0 -0
- package/components/common/field-with-options.d.ts +2 -2
- package/components/common/field-with-options.js +0 -1
- package/components/common/field-with-options.js.map +1 -1
- package/components/common/field.d.ts +10 -3
- package/components/common/field.js +21 -0
- package/components/common/field.js.map +1 -1
- package/components/common/metadata-buttons-bar.d.ts +2 -1
- package/components/common/metadata-buttons-bar.js +60 -28
- package/components/common/metadata-buttons-bar.js.map +1 -1
- package/components/common/styles/paths.d.ts +1 -0
- package/components/common/styles/paths.js +29 -16
- package/components/common/styles/paths.js.map +1 -1
- package/components/common/utils.js +4 -4
- package/components/common/utils.js.map +1 -1
- package/components/icure-button/index.d.ts +1 -1
- package/components/icure-button/index.js +54 -14
- package/components/icure-button/index.js.map +1 -1
- package/components/icure-button-group/index.d.ts +5 -3
- package/components/icure-button-group/index.js +81 -45
- package/components/icure-button-group/index.js.map +1 -1
- package/components/icure-date-picker/index.d.ts +6 -3
- package/components/icure-date-picker/index.js +62 -22
- package/components/icure-date-picker/index.js.map +1 -1
- package/components/icure-dropdown-field/index.d.ts +5 -2
- package/components/icure-dropdown-field/index.js +58 -18
- package/components/icure-dropdown-field/index.js.map +1 -1
- package/components/icure-form/fields/button-group/checkbox.d.ts +2 -1
- package/components/icure-form/fields/button-group/checkbox.js +1 -1
- package/components/icure-form/fields/button-group/checkbox.js.map +1 -1
- package/components/icure-form/fields/button-group/radio-button.d.ts +2 -1
- package/components/icure-form/fields/button-group/radio-button.js +1 -1
- package/components/icure-form/fields/button-group/radio-button.js.map +1 -1
- package/components/icure-form/fields/date-picker/date-picker.d.ts +2 -1
- package/components/icure-form/fields/date-picker/date-picker.js +1 -1
- package/components/icure-form/fields/date-picker/date-picker.js.map +1 -1
- package/components/icure-form/fields/date-picker/date-time-picker.d.ts +2 -1
- package/components/icure-form/fields/date-picker/date-time-picker.js +1 -1
- package/components/icure-form/fields/date-picker/date-time-picker.js.map +1 -1
- package/components/icure-form/fields/date-picker/time-picker.d.ts +2 -1
- package/components/icure-form/fields/date-picker/time-picker.js +1 -1
- package/components/icure-form/fields/date-picker/time-picker.js.map +1 -1
- package/components/icure-form/fields/dropdown/dropdown-field.d.ts +1 -1
- package/components/icure-form/fields/dropdown/dropdown-field.js +1 -1
- package/components/icure-form/fields/dropdown/dropdown-field.js.map +1 -1
- package/components/icure-form/fields/items-list-field/items-list-field.d.ts +2 -1
- package/components/icure-form/fields/items-list-field/items-list-field.js +1 -1
- package/components/icure-form/fields/items-list-field/items-list-field.js.map +1 -1
- package/components/icure-form/fields/measure-field/measure-field.d.ts +2 -1
- package/components/icure-form/fields/measure-field/measure-field.js +2 -1
- package/components/icure-form/fields/measure-field/measure-field.js.map +1 -1
- package/components/icure-form/fields/number-field/number-field.d.ts +2 -1
- package/components/icure-form/fields/number-field/number-field.js +2 -1
- package/components/icure-form/fields/number-field/number-field.js.map +1 -1
- package/components/icure-form/fields/text-field/text-field.d.ts +2 -1
- package/components/icure-form/fields/text-field/text-field.js +2 -1
- package/components/icure-form/fields/text-field/text-field.js.map +1 -1
- package/components/icure-form/fields/token-field/token-field.d.ts +2 -1
- package/components/icure-form/fields/token-field/token-field.js +1 -1
- package/components/icure-form/fields/token-field/token-field.js.map +1 -1
- package/components/icure-form/index.d.ts +6 -2
- package/components/icure-form/index.js +111 -21
- package/components/icure-form/index.js.map +1 -1
- package/components/icure-form/renderer/form/form-selection-button.js +48 -12
- package/components/icure-form/renderer/form/form-selection-button.js.map +1 -1
- package/components/icure-form/renderer/form/form.js +183 -142
- package/components/icure-form/renderer/form/form.js.map +1 -1
- package/components/icure-form/renderer/index.d.ts +1 -1
- package/components/icure-form/renderer/index.js.map +1 -1
- package/components/icure-label/index.js +54 -14
- package/components/icure-label/index.js.map +1 -1
- package/components/icure-text-field/index.d.ts +5 -2
- package/components/icure-text-field/index.js +151 -49
- package/components/icure-text-field/index.js.map +1 -1
- package/components/icure-text-field/prosemirror-commands.js +2 -3
- package/components/icure-text-field/prosemirror-commands.js.map +1 -1
- package/components/icure-text-field/prosemirror-utils.js +1 -2
- package/components/icure-text-field/prosemirror-utils.js.map +1 -1
- package/components/icure-text-field/schema/common-marks.js +2 -2
- package/components/icure-text-field/schema/common-marks.js.map +1 -1
- package/components/icure-text-field/schema/date-time-schema.js +3 -4
- package/components/icure-text-field/schema/date-time-schema.js.map +1 -1
- package/components/icure-text-field/schema/decimal-schema.js +1 -2
- package/components/icure-text-field/schema/decimal-schema.js.map +1 -1
- package/components/icure-text-field/schema/index.js +1 -2
- package/components/icure-text-field/schema/index.js.map +1 -1
- package/components/icure-text-field/schema/items-list-schema.js +1 -2
- package/components/icure-text-field/schema/items-list-schema.js.map +1 -1
- package/components/icure-text-field/schema/markdown-schema.js +3 -25
- package/components/icure-text-field/schema/markdown-schema.js.map +1 -1
- package/components/icure-text-field/schema/measure-schema.js +2 -2
- package/components/icure-text-field/schema/measure-schema.js.map +1 -1
- package/components/icure-text-field/schema/token-schema.js +1 -2
- package/components/icure-text-field/schema/token-schema.js.map +1 -1
- package/components/icure-text-field/schema/utils.js +2 -3
- package/components/icure-text-field/schema/utils.js.map +1 -1
- package/components/themes/default/index.js.map +1 -1
- package/components/themes/icure-blue/index.js +58 -3
- package/components/themes/icure-blue/index.js.map +1 -1
- package/components/themes/kendo/index.js +9 -5
- package/components/themes/kendo/index.js.map +1 -1
- package/conversion/icure-convert.js +1 -2
- package/conversion/icure-convert.js.map +1 -1
- package/generic/model.d.ts +5 -4
- package/generic/model.js.map +1 -1
- package/icure/form-values-container.d.ts +21 -13
- package/icure/form-values-container.js +235 -138
- package/icure/form-values-container.js.map +1 -1
- package/icure/icure-utils.js +6 -6
- package/icure/icure-utils.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +16 -13
- package/utils/dates.js +6 -7
- package/utils/dates.js.map +1 -1
- package/utils/fields-values-provider.d.ts +1 -1
- package/utils/fields-values-provider.js +16 -8
- package/utils/fields-values-provider.js.map +1 -1
- package/utils/interpreter.d.ts +2 -3
- package/utils/interpreter.js +11 -2
- package/utils/interpreter.js.map +1 -1
- package/utils/no-lodash.js +3 -4
- package/utils/no-lodash.js.map +1 -1
- package/utils/primitive.d.ts +1 -1
- package/utils/primitive.js +9 -9
- package/utils/primitive.js.map +1 -1
- package/.yarn/cache/@lit-labs-ssr-dom-shim-npm-1.2.1-d14ce3e3e5-5667c44f58.zip +0 -0
- package/.yarn/cache/@lit-reactive-element-npm-2.0.4-4836436301-368d788d9e.zip +0 -0
- package/.yarn/cache/app-datepicker-npm-6.0.0-rc.33-f74d593ddf-6490949c45.zip +0 -0
- package/.yarn/cache/lit-ntml-npm-3.0.6-98ebc6c1ac-2917c778d9.zip +0 -0
- package/.yarn/cache/lodash-es-npm-4.17.21-b45832dfce-05cbffad6e.zip +0 -0
- package/.yarn/cache/nodemod-npm-3.0.6-844d650911-47ffe619b3.zip +0 -0
- package/.yarn/cache/normalize-diacritics-npm-3.0.12-93e2346015-5ddc2cfaf8.zip +0 -0
- package/.yarn/cache/parse5-npm-6.0.1-70a35a494a-7d569a176c.zip +0 -0
- package/.yarn/cache/prosemirror-commands-npm-1.5.2-27f8f3fee9-ff65063a8c.zip +0 -0
- package/.yarn/cache/prosemirror-history-npm-1.3.2-cc128c8ee6-b85fe6378a.zip +0 -0
- package/.yarn/cache/prosemirror-keymap-npm-1.2.2-efb8276b00-85fe4fc303.zip +0 -0
- package/.yarn/cache/prosemirror-markdown-npm-1.12.0-28e990f443-d7607ee1a6.zip +0 -0
- package/.yarn/cache/prosemirror-model-npm-1.19.4-4fd32211c8-12c277ed30.zip +0 -0
- package/.yarn/cache/prosemirror-model-npm-1.23.0-57eb718541-f5ab1593cb.zip +0 -0
- package/.yarn/cache/prosemirror-schema-basic-npm-1.2.2-def7bf2ec7-1f93f8678c.zip +0 -0
- package/.yarn/cache/prosemirror-schema-list-npm-1.3.0-23c1830a7e-03654e37c8.zip +0 -0
- package/.yarn/cache/prosemirror-transform-npm-1.10.2-1c2da9123e-93b0c03aff.zip +0 -0
- package/.yarn/cache/prosemirror-transform-npm-1.8.0-ea3ca0411f-6d16ca4f95.zip +0 -0
- package/.yarn/cache/prosemirror-view-npm-1.32.7-63c3e4b182-40c9038a52.zip +0 -0
- package/.yarn/cache/prosemirror-view-npm-1.36.0-830888802f-38986f55e4.zip +0 -0
- package/components/icure-text-field/schema/items-list.d.ts +0 -3
- package/components/icure-text-field/schema/items-list.js +0 -31
- package/components/icure-text-field/schema/items-list.js.map +0 -1
- package/components/themes/ehr-lite/index.d.ts +0 -1
- package/components/themes/ehr-lite/index.js +0 -321
- package/components/themes/ehr-lite/index.js.map +0 -1
- package/utils/form-value-container.d.ts +0 -3
- package/utils/form-value-container.js +0 -34
- package/utils/form-value-container.js.map +0 -1
- package/utils/icure-utils.d.ts +0 -16
- package/utils/icure-utils.js +0 -105
- package/utils/icure-utils.js.map +0 -1
|
@@ -18,7 +18,6 @@ const dates_1 = require("../utils/dates");
|
|
|
18
18
|
const uuid_1 = require("uuid");
|
|
19
19
|
const code_utils_1 = require("../utils/code-utils");
|
|
20
20
|
function notify(l, fvc) {
|
|
21
|
-
//console.log('Notifying', l, fvc.toString())
|
|
22
21
|
l(fvc);
|
|
23
22
|
}
|
|
24
23
|
/** This class is a bridge between the ICure API and the generic FormValuesContainer interface.
|
|
@@ -47,16 +46,17 @@ class BridgedFormValuesContainer {
|
|
|
47
46
|
/**
|
|
48
47
|
* Creates an instance of BridgedFormValuesContainer.
|
|
49
48
|
* @param responsible The id of the data owner responsible for the creation of the values
|
|
50
|
-
* @param contact The displayed contact (may be in the past). === to currentContact if the contact is the contact of the day
|
|
51
49
|
* @param contactFormValuesContainer The wrapped ContactFormValuesContainer
|
|
52
50
|
* @param interpreter A function that can interpret formulas
|
|
51
|
+
* @param contact The displayed contact (may be in the past). === to currentContact if the contact is the contact of the day
|
|
52
|
+
* @param initialValuesProvider A lambda that provides the initial values of the form
|
|
53
53
|
* @param dependentValuesProvider A function that provides the dependent values (computed on the basis of other values) for a given anchorId and templateId
|
|
54
54
|
* @param validatorsProvider A function that provides the validators for a given anchorId and templateId
|
|
55
55
|
* @param language The language in which the values are displayed
|
|
56
56
|
* @param changeListeners The listeners that will be notified when the values change
|
|
57
|
-
* @param
|
|
57
|
+
* @param interpreterContext A map with keys that are the names of the variables and values that are the functions that return the values of the variables
|
|
58
58
|
*/
|
|
59
|
-
constructor(responsible, contactFormValuesContainer, interpreter, contact, initialValuesProvider = () => [], dependentValuesProvider = () => [], validatorsProvider = () => [], language = 'en', changeListeners = []) {
|
|
59
|
+
constructor(responsible, contactFormValuesContainer, interpreter, contact, initialValuesProvider = () => [], dependentValuesProvider = () => [], validatorsProvider = () => [], language = 'en', changeListeners = [], interpreterContext = {}) {
|
|
60
60
|
this.responsible = responsible;
|
|
61
61
|
this.interpreter = interpreter;
|
|
62
62
|
this.initialValuesProvider = initialValuesProvider;
|
|
@@ -64,22 +64,28 @@ class BridgedFormValuesContainer {
|
|
|
64
64
|
this.validatorsProvider = validatorsProvider;
|
|
65
65
|
this.language = language;
|
|
66
66
|
this.changeListeners = changeListeners;
|
|
67
|
+
this.interpreterContext = interpreterContext;
|
|
67
68
|
this._id = (0, uuid_1.v4)();
|
|
68
69
|
console.log(`Creating bridge FVC (${contactFormValuesContainer.rootForm.formTemplateId}) with ${contactFormValuesContainer.children.length} children [${this._id}]`);
|
|
69
70
|
//Before start to broadcast changes, we need to fill in the contactFormValuesContainer with the dependent values
|
|
70
71
|
this.contactFormValuesContainer = contactFormValuesContainer;
|
|
71
|
-
this.mutateAndNotify = (newContactFormValuesContainer) => {
|
|
72
|
+
this.mutateAndNotify = (newContactFormValuesContainer) => __awaiter(this, void 0, void 0, function* () {
|
|
72
73
|
newContactFormValuesContainer.unregisterChangeListener(this.mutateAndNotify);
|
|
73
|
-
const newBridgedFormValueContainer = new BridgedFormValuesContainer(this.responsible, newContactFormValuesContainer, this.interpreter, this.contact === this.contactFormValuesContainer.currentContact ? newContactFormValuesContainer.currentContact : this.contact, this.initialValuesProvider, this.dependentValuesProvider, this.validatorsProvider, this.language, this.changeListeners);
|
|
74
|
+
const newBridgedFormValueContainer = yield new BridgedFormValuesContainer(this.responsible, newContactFormValuesContainer, this.interpreter, this.contact === this.contactFormValuesContainer.currentContact ? newContactFormValuesContainer.currentContact : this.contact, this.initialValuesProvider, this.dependentValuesProvider, this.validatorsProvider, this.language, this.changeListeners, this.interpreterContext).init();
|
|
74
75
|
this.changeListeners.forEach((l) => notify(l, newBridgedFormValueContainer));
|
|
75
76
|
return newBridgedFormValueContainer;
|
|
76
|
-
};
|
|
77
|
+
});
|
|
77
78
|
this.contactFormValuesContainer.registerChangeListener(this.mutateAndNotify);
|
|
78
79
|
this.contact = contact !== null && contact !== void 0 ? contact : contactFormValuesContainer.currentContact;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
}
|
|
81
|
+
init() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
if (this.contactFormValuesContainer.mustBeInitialised()) {
|
|
84
|
+
yield this.computeInitialValues();
|
|
85
|
+
}
|
|
86
|
+
yield this.computeDependentValues();
|
|
87
|
+
return this;
|
|
88
|
+
});
|
|
83
89
|
}
|
|
84
90
|
getLabel() {
|
|
85
91
|
return this.contactFormValuesContainer.getLabel();
|
|
@@ -96,6 +102,13 @@ class BridgedFormValuesContainer {
|
|
|
96
102
|
unregisterChangeListener(listener) {
|
|
97
103
|
this.changeListeners = this.changeListeners.filter((l) => l !== listener);
|
|
98
104
|
}
|
|
105
|
+
getDefaultValue(label) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
var _a;
|
|
108
|
+
const formula = (_a = this.initialValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).find(({ metadata }) => metadata.label === label)) === null || _a === void 0 ? void 0 : _a.formula;
|
|
109
|
+
return formula ? this.convertRawValue(yield this.compute(formula)) : undefined;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
99
112
|
getValues(revisionsFilter) {
|
|
100
113
|
return Object.entries(this.contactFormValuesContainer.getValues((id, history) => revisionsFilter(id, history
|
|
101
114
|
.filter(({ modified }) => !this.contact.created || !modified || modified <= this.contact.created)
|
|
@@ -144,70 +157,109 @@ class BridgedFormValuesContainer {
|
|
|
144
157
|
},
|
|
145
158
|
})) })), {});
|
|
146
159
|
}
|
|
160
|
+
convertRawValue(rawValue) {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
if (rawValue && typeof rawValue === 'object' && 'content' in rawValue) {
|
|
163
|
+
return rawValue;
|
|
164
|
+
}
|
|
165
|
+
if (Array.isArray(rawValue)) {
|
|
166
|
+
return rawValue.reduce((acc, it, idx) => {
|
|
167
|
+
var _a, _b, _c, _d, _e;
|
|
168
|
+
const fv = this.convertRawValue(it);
|
|
169
|
+
if (fv === undefined) {
|
|
170
|
+
return acc;
|
|
171
|
+
}
|
|
172
|
+
acc.codes = [...((_a = fv.codes) !== null && _a !== void 0 ? _a : []), ...((_b = acc.codes) !== null && _b !== void 0 ? _b : [])];
|
|
173
|
+
acc.content['*'] = ((_c = fv.content['*']) === null || _c === void 0 ? void 0 : _c.value)
|
|
174
|
+
? Object.assign(Object.assign({}, acc.content['*']), { [(_e = ((_d = fv.codes) !== null && _d !== void 0 ? _d : [])[0].id) !== null && _e !== void 0 ? _e : idx.toString()]: fv.content['*'].value }) : acc.content['*'];
|
|
175
|
+
return acc;
|
|
176
|
+
}, { content: { '*': { type: 'compound', value: {} } } });
|
|
177
|
+
}
|
|
178
|
+
if (typeof rawValue === 'number') {
|
|
179
|
+
return { content: { '*': { type: 'number', value: rawValue } } };
|
|
180
|
+
}
|
|
181
|
+
if (typeof rawValue === 'string') {
|
|
182
|
+
return { content: { '*': { type: 'string', value: rawValue } } };
|
|
183
|
+
}
|
|
184
|
+
if (typeof rawValue === 'boolean') {
|
|
185
|
+
return { content: { '*': { type: 'boolean', value: rawValue } } };
|
|
186
|
+
}
|
|
187
|
+
if (rawValue instanceof Date) {
|
|
188
|
+
return { content: { '*': { type: 'timestamp', value: (0, dates_1.dateToFuzzyDate)(rawValue) } } };
|
|
189
|
+
}
|
|
190
|
+
if (rawValue && typeof rawValue === 'object' && 'unit' in rawValue && 'value' in rawValue && typeof rawValue.value === 'number') {
|
|
191
|
+
return { content: { '*': { type: 'measure', value: rawValue.value, unit: (_b = (_a = rawValue.unit) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '' } } };
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
147
195
|
//This method mutates the BridgedFormValuesContainer but can only be called from the constructor
|
|
148
196
|
computeInitialValues() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
if (this.contactFormValuesContainer.rootForm.formTemplateId) {
|
|
199
|
+
yield Promise.all(this.initialValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).map((_a) => __awaiter(this, [_a], void 0, function* ({ metadata, revisionsFilter, formula }) {
|
|
200
|
+
var _b;
|
|
201
|
+
try {
|
|
202
|
+
const currentValue = this.getValues(revisionsFilter);
|
|
203
|
+
if (!currentValue || !Object.keys(currentValue).length) {
|
|
204
|
+
const newValue = this.convertRawValue((yield this.compute(formula)));
|
|
205
|
+
if (newValue !== undefined) {
|
|
206
|
+
const lng = (_b = this.language) !== null && _b !== void 0 ? _b : 'en';
|
|
207
|
+
if (newValue && !newValue.content[lng] && newValue.content['*']) {
|
|
208
|
+
newValue.content[lng] = newValue.content['*'];
|
|
209
|
+
}
|
|
210
|
+
if (newValue) {
|
|
211
|
+
delete newValue.content['*'];
|
|
212
|
+
}
|
|
213
|
+
setValueOnContactFormValuesContainer(this.contactFormValuesContainer, metadata.label, lng, newValue, undefined, metadata, (fvc) => {
|
|
214
|
+
const currentContact = this.contactFormValuesContainer.currentContact;
|
|
215
|
+
this.contactFormValuesContainer = fvc;
|
|
216
|
+
if (this.contact === currentContact) {
|
|
217
|
+
this.contact = fvc.currentContact;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
console.log(`Error while computing formula : ${formula}`, e);
|
|
225
|
+
}
|
|
226
|
+
})));
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
//This method mutates the BridgedFormValuesContainer but can only be called from the constructor
|
|
231
|
+
computeDependentValues() {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
if (this.contactFormValuesContainer.rootForm.formTemplateId) {
|
|
234
|
+
yield Promise.all(this.dependentValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).map((_a) => __awaiter(this, [_a], void 0, function* ({ metadata, revisionsFilter, formula }) {
|
|
235
|
+
var _b;
|
|
236
|
+
try {
|
|
237
|
+
const currentValue = this.getValues(revisionsFilter);
|
|
238
|
+
const newValue = this.convertRawValue((yield this.compute(formula)));
|
|
239
|
+
if (newValue !== undefined || currentValue != undefined) {
|
|
240
|
+
const lng = (_b = this.language) !== null && _b !== void 0 ? _b : 'en';
|
|
158
241
|
if (newValue && !newValue.content[lng] && newValue.content['*']) {
|
|
159
242
|
newValue.content[lng] = newValue.content['*'];
|
|
160
243
|
}
|
|
161
244
|
if (newValue) {
|
|
162
245
|
delete newValue.content['*'];
|
|
163
246
|
}
|
|
164
|
-
|
|
247
|
+
const interceptor = (fvc) => {
|
|
165
248
|
const currentContact = this.contactFormValuesContainer.currentContact;
|
|
166
249
|
this.contactFormValuesContainer = fvc;
|
|
167
250
|
if (this.contact === currentContact) {
|
|
168
251
|
this.contact = fvc.currentContact;
|
|
169
252
|
}
|
|
170
|
-
}
|
|
253
|
+
};
|
|
254
|
+
setValueOnContactFormValuesContainer(this.contactFormValuesContainer, metadata.label, lng, newValue, Object.keys(currentValue !== null && currentValue !== void 0 ? currentValue : {})[0], metadata, interceptor);
|
|
171
255
|
}
|
|
172
256
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
console.log(`Error while computing formula : ${formula}`, e);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
//This method mutates the BridgedFormValuesContainer but can only be called from the constructor
|
|
181
|
-
computeDependentValues() {
|
|
182
|
-
if (this.contactFormValuesContainer.rootForm.formTemplateId) {
|
|
183
|
-
this.dependentValuesProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).forEach(({ metadata, revisionsFilter, formula }) => {
|
|
184
|
-
var _a;
|
|
185
|
-
try {
|
|
186
|
-
const currentValue = this.getValues(revisionsFilter);
|
|
187
|
-
const newValue = this.compute(formula);
|
|
188
|
-
if (newValue !== undefined || currentValue != undefined) {
|
|
189
|
-
const lng = (_a = this.language) !== null && _a !== void 0 ? _a : 'en';
|
|
190
|
-
if (newValue && !newValue.content[lng] && newValue.content['*']) {
|
|
191
|
-
newValue.content[lng] = newValue.content['*'];
|
|
192
|
-
}
|
|
193
|
-
if (newValue) {
|
|
194
|
-
delete newValue.content['*'];
|
|
195
|
-
}
|
|
196
|
-
const interceptor = (fvc) => {
|
|
197
|
-
const currentContact = this.contactFormValuesContainer.currentContact;
|
|
198
|
-
this.contactFormValuesContainer = fvc;
|
|
199
|
-
if (this.contact === currentContact) {
|
|
200
|
-
this.contact = fvc.currentContact;
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
setValueOnContactFormValuesContainer(this.contactFormValuesContainer, metadata.label, lng, newValue, Object.keys(currentValue !== null && currentValue !== void 0 ? currentValue : {})[0], metadata, interceptor);
|
|
257
|
+
catch (e) {
|
|
258
|
+
console.log(`Error while computing formula : ${formula}`, e);
|
|
204
259
|
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
260
|
+
})));
|
|
261
|
+
}
|
|
262
|
+
});
|
|
211
263
|
}
|
|
212
264
|
setValue(label, language, fv, id, metadata) {
|
|
213
265
|
setValueOnContactFormValuesContainer(this.contactFormValuesContainer, label, language, fv, id, metadata);
|
|
@@ -227,76 +279,111 @@ class BridgedFormValuesContainer {
|
|
|
227
279
|
return this.getValues((id, history) => { var _a, _b, _c; return (((_b = (_a = history === null || history === void 0 ? void 0 : history[0]) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.label) && key === history[0].value.label ? [(_c = history === null || history === void 0 ? void 0 : history[0]) === null || _c === void 0 ? void 0 : _c.revision] : []); });
|
|
228
280
|
}
|
|
229
281
|
compute(formula, sandbox) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
const primitive = (_b = (_a = content[this.language]) !== null && _a !== void 0 ? _a : content['*']) !== null && _b !== void 0 ? _b : content[Object.keys(content)[0]];
|
|
238
|
-
return primitive && (0, primitive_1.parsePrimitive)(primitive);
|
|
239
|
-
};
|
|
240
|
-
const log = console.log;
|
|
241
|
-
const native = {
|
|
242
|
-
parseInt: parseInt,
|
|
243
|
-
parseFloat: parseFloat,
|
|
244
|
-
Date: Date,
|
|
245
|
-
Math: Math,
|
|
246
|
-
Number: Number,
|
|
247
|
-
String: String,
|
|
248
|
-
Boolean: Boolean,
|
|
249
|
-
Array: Array,
|
|
250
|
-
Object: Object,
|
|
251
|
-
parseContent,
|
|
252
|
-
validate: {
|
|
253
|
-
notBlank: (self, label) => {
|
|
254
|
-
var _a, _b, _c;
|
|
255
|
-
const value = parseContent((_b = (_a = self[label]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content);
|
|
256
|
-
return !!((_c = value === null || value === void 0 ? void 0 : value.trim()) === null || _c === void 0 ? void 0 : _c.length);
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
log,
|
|
260
|
-
};
|
|
261
|
-
const proxy = new Proxy({}, {
|
|
262
|
-
has: (target, key) => { var _a; return !!native[key] || key === 'self' || Object.keys((_a = this.getVersionedValuesForKey(key)) !== null && _a !== void 0 ? _a : {}).length > 0; },
|
|
263
|
-
get: (target, key) => {
|
|
264
|
-
if (key === 'undefined') {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
var _a;
|
|
284
|
+
// noinspection JSUnusedGlobalSymbols
|
|
285
|
+
const parseContent = (content, toString = false) => {
|
|
286
|
+
var _a, _b;
|
|
287
|
+
if (!content) {
|
|
265
288
|
return undefined;
|
|
266
289
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
290
|
+
const primitive = (_b = (_a = content[this.language]) !== null && _a !== void 0 ? _a : content['*']) !== null && _b !== void 0 ? _b : content[Object.keys(content)[0]];
|
|
291
|
+
return primitive && (0, primitive_1.parsePrimitive)(primitive, toString);
|
|
292
|
+
};
|
|
293
|
+
const text = (item) => {
|
|
294
|
+
if (!item) {
|
|
295
|
+
return undefined;
|
|
270
296
|
}
|
|
271
|
-
|
|
272
|
-
|
|
297
|
+
const items = Array.isArray(item) ? item : [item];
|
|
298
|
+
return items
|
|
299
|
+
.map((it) => { var _a; return (_a = parseContent(it.content, true)) === null || _a === void 0 ? void 0 : _a.toString(); })
|
|
300
|
+
.filter((it) => !!it)
|
|
301
|
+
.join(', ');
|
|
302
|
+
};
|
|
303
|
+
const log = console.log;
|
|
304
|
+
const native = {
|
|
305
|
+
parseInt: parseInt,
|
|
306
|
+
parseFloat: parseFloat,
|
|
307
|
+
Date: Date,
|
|
308
|
+
Math: Math,
|
|
309
|
+
Number: Number,
|
|
310
|
+
String: String,
|
|
311
|
+
Boolean: Boolean,
|
|
312
|
+
Array: Array,
|
|
313
|
+
Object: Object,
|
|
314
|
+
hasOption: (it, option) => { var _a; return it && ((_a = it.codes) === null || _a === void 0 ? void 0 : _a.some((c) => { var _a, _b; return c.id === option || ((_b = (_a = c.id) === null || _a === void 0 ? void 0 : _a.split('|')) === null || _b === void 0 ? void 0 : _b[1]) === option; })); },
|
|
315
|
+
score: (it) => {
|
|
316
|
+
var _a;
|
|
317
|
+
return it
|
|
318
|
+
? ((_a = it.codes) !== null && _a !== void 0 ? _a : []).reduce((acc, c) => {
|
|
319
|
+
var _a, _b, _c;
|
|
320
|
+
try {
|
|
321
|
+
return acc + parseInt((_c = (_b = (_a = c.id) === null || _a === void 0 ? void 0 : _a.split('|')) === null || _b === void 0 ? void 0 : _b[1]) !== null && _c !== void 0 ? _c : '0');
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
return acc;
|
|
325
|
+
}
|
|
326
|
+
}, 0)
|
|
327
|
+
: 0;
|
|
328
|
+
},
|
|
329
|
+
parseContent,
|
|
330
|
+
validate: {
|
|
331
|
+
notBlank: (self, label) => {
|
|
332
|
+
var _a, _b, _c;
|
|
333
|
+
const value = parseContent((_b = (_a = self[label]) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.content);
|
|
334
|
+
return !!((_c = value === null || value === void 0 ? void 0 : value.trim()) === null || _c === void 0 ? void 0 : _c.length);
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
text,
|
|
338
|
+
log,
|
|
339
|
+
Promise,
|
|
340
|
+
};
|
|
341
|
+
const proxy = new Proxy({}, {
|
|
342
|
+
has: (target, key) => { var _a; return !!native[key] || key === 'self' || !!this.interpreterContext[key] || Object.keys((_a = this.getVersionedValuesForKey(key)) !== null && _a !== void 0 ? _a : {}).length > 0; },
|
|
343
|
+
get: (target, key) => {
|
|
344
|
+
if (key === 'undefined') {
|
|
345
|
+
return undefined;
|
|
346
|
+
}
|
|
347
|
+
const nativeValue = native[key];
|
|
348
|
+
if (!!nativeValue) {
|
|
349
|
+
return nativeValue;
|
|
350
|
+
}
|
|
351
|
+
return key === 'self' ? proxy : this.interpreterContext[key] ? this.interpreterContext[key]() : Object.values(this.getVersionedValuesForKey(key)).map((v) => { var _a; return (_a = v[0]) === null || _a === void 0 ? void 0 : _a.value; });
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
return (_a = this.interpreter) === null || _a === void 0 ? void 0 : _a.call(this, formula, sandbox !== null && sandbox !== void 0 ? sandbox : proxy);
|
|
273
355
|
});
|
|
274
|
-
return (_a = this.interpreter) === null || _a === void 0 ? void 0 : _a.call(this, formula, sandbox !== null && sandbox !== void 0 ? sandbox : proxy);
|
|
275
356
|
}
|
|
276
357
|
getChildren() {
|
|
277
|
-
|
|
278
|
-
.getChildren()
|
|
279
|
-
.
|
|
280
|
-
|
|
281
|
-
|
|
358
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
359
|
+
const children = yield Promise.all((yield this.contactFormValuesContainer.getChildren()).map((fvc) => new BridgedFormValuesContainer(this.responsible, fvc, this.interpreter, this.contact, this.initialValuesProvider, this.dependentValuesProvider, this.validatorsProvider, this.language, [], this.interpreterContext).init()));
|
|
360
|
+
console.log(`${children.length} children found in ${this.contactFormValuesContainer.rootForm.formTemplateId} initialised with `, this.initialValuesProvider);
|
|
361
|
+
return children;
|
|
362
|
+
});
|
|
282
363
|
}
|
|
283
364
|
getValidationErrors() {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
365
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
+
if (this.contactFormValuesContainer.rootForm.formTemplateId) {
|
|
367
|
+
// noinspection ES6MissingAwait
|
|
368
|
+
return yield this.validatorsProvider(this.contactFormValuesContainer.rootForm.descr, this.contactFormValuesContainer.rootForm.formTemplateId).reduce((resPromise_1, _a) => __awaiter(this, [resPromise_1, _a], void 0, function* (resPromise, { metadata, validators }) {
|
|
369
|
+
return yield validators.reduce((resPromise_2, _a) => __awaiter(this, [resPromise_2, _a], void 0, function* (resPromise, { validation, message }) {
|
|
370
|
+
const res = yield resPromise;
|
|
371
|
+
try {
|
|
372
|
+
if (!(yield this.compute(validation))) {
|
|
373
|
+
res.push([metadata, message]);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch (e) {
|
|
377
|
+
console.log(`Error while computing validation : ${validation}`, e);
|
|
378
|
+
}
|
|
379
|
+
return res;
|
|
380
|
+
}), resPromise);
|
|
381
|
+
}), Promise.resolve([]));
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
return [];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
300
387
|
}
|
|
301
388
|
addChild(anchorId, templateId, label) {
|
|
302
389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -362,6 +449,19 @@ class ContactFormValuesContainer {
|
|
|
362
449
|
this.formRecycler = formRecycler;
|
|
363
450
|
this.changeListeners = changeListeners;
|
|
364
451
|
this._initialised = initialised;
|
|
452
|
+
this.indexedServices = [this.currentContact].concat(this.contactsHistory).reduce((acc, ctc) => {
|
|
453
|
+
var _a, _b, _c;
|
|
454
|
+
const services = (_c = (_b = (_a = ctc.services) === null || _a === void 0 ? void 0 : _a.filter((s) => { var _a; return (_a = ctc.subContacts) === null || _a === void 0 ? void 0 : _a.some((sc) => { var _a; return sc.formId === this.rootForm.id && ((_a = sc.services) === null || _a === void 0 ? void 0 : _a.some((sss) => sss.serviceId === s.id)); }); })) === null || _b === void 0 ? void 0 : _b.reduce((acc, s) => {
|
|
455
|
+
var _a, _b;
|
|
456
|
+
return s.id
|
|
457
|
+
? Object.assign(Object.assign({}, acc), { [s.id]: ((_a = acc[s.id]) !== null && _a !== void 0 ? _a : (acc[s.id] = [])).concat({
|
|
458
|
+
revision: (_b = ctc.rev) !== null && _b !== void 0 ? _b : null,
|
|
459
|
+
modified: ctc.created,
|
|
460
|
+
value: s,
|
|
461
|
+
}) }) : acc;
|
|
462
|
+
}, acc)) !== null && _c !== void 0 ? _c : acc;
|
|
463
|
+
return services;
|
|
464
|
+
}, {});
|
|
365
465
|
this.synchronise();
|
|
366
466
|
}
|
|
367
467
|
synchronise() {
|
|
@@ -408,10 +508,17 @@ class ContactFormValuesContainer {
|
|
|
408
508
|
this.changeListeners = this.changeListeners.filter((l) => l !== listener);
|
|
409
509
|
}
|
|
410
510
|
getChildren() {
|
|
411
|
-
return this
|
|
511
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
return this.children;
|
|
513
|
+
});
|
|
412
514
|
}
|
|
413
515
|
getValidationErrors() {
|
|
414
|
-
|
|
516
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
517
|
+
throw new Error('Validation not supported at contact level');
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
getDefaultValue() {
|
|
521
|
+
return Promise.resolve(undefined);
|
|
415
522
|
}
|
|
416
523
|
getValues(revisionsFilter) {
|
|
417
524
|
return Object.entries(this.getServicesInHistory(revisionsFilter)).reduce((acc, [id, history]) => history.length
|
|
@@ -530,7 +637,9 @@ class ContactFormValuesContainer {
|
|
|
530
637
|
}
|
|
531
638
|
}
|
|
532
639
|
compute() {
|
|
533
|
-
|
|
640
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
641
|
+
throw new Error('Compute not supported at contact level');
|
|
642
|
+
});
|
|
534
643
|
}
|
|
535
644
|
/** returns all services in history that match a selector
|
|
536
645
|
*
|
|
@@ -538,20 +647,8 @@ class ContactFormValuesContainer {
|
|
|
538
647
|
* @param revisionsFilter
|
|
539
648
|
*/
|
|
540
649
|
getServicesInHistory(revisionsFilter) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const services = (_c = (_b = (_a = ctc.services) === null || _a === void 0 ? void 0 : _a.filter((s) => { var _a; return (_a = ctc.subContacts) === null || _a === void 0 ? void 0 : _a.some((sc) => { var _a; return sc.formId === this.rootForm.id && ((_a = sc.services) === null || _a === void 0 ? void 0 : _a.some((sss) => sss.serviceId === s.id)); }); })) === null || _b === void 0 ? void 0 : _b.reduce((acc, s) => {
|
|
544
|
-
var _a, _b;
|
|
545
|
-
return s.id
|
|
546
|
-
? Object.assign(Object.assign({}, acc), { [s.id]: ((_a = acc[s.id]) !== null && _a !== void 0 ? _a : (acc[s.id] = [])).concat({
|
|
547
|
-
revision: (_b = ctc.rev) !== null && _b !== void 0 ? _b : null,
|
|
548
|
-
modified: ctc.created,
|
|
549
|
-
value: s,
|
|
550
|
-
}) }) : acc;
|
|
551
|
-
}, acc)) !== null && _c !== void 0 ? _c : acc;
|
|
552
|
-
return services;
|
|
553
|
-
}, {}); //index services in history by id
|
|
554
|
-
return Object.entries(indexedServices)
|
|
650
|
+
//index services in history by id
|
|
651
|
+
return Object.entries(this.indexedServices)
|
|
555
652
|
.map(([id, history]) => {
|
|
556
653
|
const keptRevisions = revisionsFilter(id, history.map(({ revision, modified, value: s }) => {
|
|
557
654
|
var _a, _b;
|