@configura/web-api 1.6.1 → 2.0.0-alpha.2
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/.eslintrc.json +18 -18
- package/LICENSE +201 -201
- package/README.md +1 -1
- package/dist/CatalogueAPI.d.ts +551 -507
- package/dist/CatalogueAPI.js +293 -280
- package/dist/CfgMeasure.d.ts +32 -32
- package/dist/CfgMeasure.js +30 -30
- package/dist/CfgProduct.d.ts +268 -258
- package/dist/CfgProduct.js +778 -747
- package/dist/CfgReferencePathHelper.d.ts +14 -0
- package/dist/CfgReferencePathHelper.js +13 -0
- package/dist/ConfigurationConverter.d.ts +5 -0
- package/dist/ConfigurationConverter.js +72 -0
- package/dist/index.d.ts +23 -20
- package/dist/index.js +23 -20
- package/dist/io/CfgHistoryManager.d.ts +51 -0
- package/dist/io/CfgHistoryManager.js +82 -0
- package/dist/io/CfgHistoryToProdConfConnector.d.ts +21 -0
- package/dist/io/CfgHistoryToProdConfConnector.js +56 -0
- package/dist/io/CfgIOManager.d.ts +49 -0
- package/dist/io/CfgIOManager.js +115 -0
- package/dist/io/CfgIOProdConfConnector.d.ts +53 -0
- package/dist/io/CfgIOProdConfConnector.js +141 -0
- package/dist/io/CfgObservableStateManager.d.ts +22 -0
- package/dist/io/CfgObservableStateManager.js +65 -0
- package/dist/io/CfgObservableStateToProdConfConnector.d.ts +15 -0
- package/dist/io/CfgObservableStateToProdConfConnector.js +16 -0
- package/dist/io/CfgWindowEventManager.d.ts +22 -0
- package/dist/io/CfgWindowEventManager.js +38 -0
- package/dist/io/CfgWindowMessageManager.d.ts +41 -0
- package/dist/io/CfgWindowMessageManager.js +84 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.d.ts +17 -0
- package/dist/io/CfgWindowMessageToProdConfConnector.js +18 -0
- package/dist/io/index.d.ts +9 -0
- package/dist/io/index.js +8 -0
- package/dist/material/CfgMaterialMapping.d.ts +7 -7
- package/dist/material/CfgMaterialMapping.js +181 -181
- package/dist/material/CfgMtrlApplication.d.ts +18 -18
- package/dist/material/CfgMtrlApplication.js +43 -43
- package/dist/material/CfgMtrlApplicationSource.d.ts +7 -7
- package/dist/material/CfgMtrlApplicationSource.js +8 -8
- package/dist/material/CfgMtrlSource.d.ts +19 -19
- package/dist/material/CfgMtrlSource.js +40 -40
- package/dist/material/CfgMtrlSourceWithMetaData.d.ts +7 -7
- package/dist/material/CfgMtrlSourceWithMetaData.js +1 -1
- package/dist/productConfiguration/CfgFeature.d.ts +187 -188
- package/dist/productConfiguration/CfgFeature.js +645 -636
- package/dist/productConfiguration/CfgOption.d.ts +151 -150
- package/dist/productConfiguration/CfgOption.js +416 -426
- package/dist/productConfiguration/CfgProductConfiguration.d.ts +117 -120
- package/dist/productConfiguration/CfgProductConfiguration.js +307 -309
- package/dist/productConfiguration/filters.d.ts +15 -15
- package/dist/productConfiguration/filters.js +70 -70
- package/dist/productConfiguration/productParamsGenerator.d.ts +15 -15
- package/dist/productConfiguration/productParamsGenerator.js +51 -51
- package/dist/productConfiguration/utilitiesProductConfiguration.d.ts +17 -17
- package/dist/productConfiguration/utilitiesProductConfiguration.js +80 -80
- package/dist/productLoader.d.ts +33 -33
- package/dist/productLoader.js +49 -49
- package/dist/syncGroups/SyncGroupsApplyMode.d.ts +20 -20
- package/dist/syncGroups/SyncGroupsApplyMode.js +21 -21
- package/dist/syncGroups/SyncGroupsHandler.d.ts +40 -40
- package/dist/syncGroups/SyncGroupsHandler.js +359 -358
- package/dist/syncGroups/SyncGroupsPathHelper.d.ts +26 -26
- package/dist/syncGroups/SyncGroupsPathHelper.js +90 -90
- package/dist/syncGroups/SyncGroupsState.d.ts +35 -35
- package/dist/syncGroups/SyncGroupsState.js +125 -125
- package/dist/syncGroups/SyncGroupsTransaction.d.ts +154 -154
- package/dist/syncGroups/SyncGroupsTransaction.js +576 -576
- package/dist/tasks/TaskHandler.d.ts +77 -78
- package/dist/tasks/TaskHandler.js +275 -276
- package/dist/tasks/formats.d.ts +4 -4
- package/dist/tasks/formats.js +7 -7
- package/dist/tests/testData/collectorForTest.d.ts +73 -73
- package/dist/tests/testData/collectorForTest.js +194 -194
- package/dist/tests/testData/dummyProductForTest.d.ts +4 -4
- package/dist/tests/testData/dummyProductForTest.js +32 -36
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.d.ts +11 -11
- package/dist/tests/testData/testDataAdditionalProductInAdditionalProductInProductForTest.js +277 -277
- package/dist/tests/testData/testDataCachedGetProduct.d.ts +5 -5
- package/dist/tests/testData/testDataCachedGetProduct.js +185 -185
- package/dist/tests/testData/testDataCachedPostValidate.d.ts +7 -7
- package/dist/tests/testData/testDataCachedPostValidate.js +183 -183
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.d.ts +3 -3
- package/dist/tests/testData/testDataNoAdditionalProductNoPropagateForTest.js +1099 -1099
- package/dist/tests/testData/testDataOptions.d.ts +12 -12
- package/dist/tests/testData/testDataOptions.js +60 -60
- package/dist/tests/testData/testDataProductAggregatedPrice.d.ts +6 -6
- package/dist/tests/testData/testDataProductAggregatedPrice.js +187 -187
- package/dist/tests/testData/testDataUpcharge.d.ts +8 -8
- package/dist/tests/testData/testDataUpcharge.js +119 -119
- package/dist/utilitiesCatalogueData.d.ts +42 -31
- package/dist/utilitiesCatalogueData.js +173 -162
- package/dist/utilitiesCataloguePermission.d.ts +38 -37
- package/dist/utilitiesCataloguePermission.js +79 -80
- package/dist/utilitiesNumericValues.d.ts +24 -24
- package/dist/utilitiesNumericValues.js +109 -109
- package/package.json +3 -3
|
@@ -1,309 +1,307 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { compareArrays, count, isLengthUnit, Observable, toError, toLengthUnit, } from "@configura/web-utilities";
|
|
11
|
-
import { CfgProduct } from "../CfgProduct.js";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
27
|
-
this.
|
|
28
|
-
this.
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* When used internally the notifications are taken care off by the caller, but if set from
|
|
61
|
-
* outside we want notifications to bubble all the way to the root.
|
|
62
|
-
*/
|
|
63
|
-
this.setApiSelection = (selectedOptions, bubbleToRoot) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const featuresLength = this._features.length;
|
|
65
|
-
const selectedOptionsLength = selectedOptions.length;
|
|
66
|
-
if (featuresLength !== selectedOptionsLength) {
|
|
67
|
-
throw new Error(`Wrong selection count. Features on this configuration: ${featuresLength}. Passed feature count: ${selectedOptionsLength}.`);
|
|
68
|
-
}
|
|
69
|
-
const change = (yield Promise.all(this._features.map((f, i) => f._internal.setApiSelection(selectedOptions[i].next)))).some((b) => b);
|
|
70
|
-
if (change) {
|
|
71
|
-
yield this._notifyAllOfChange(bubbleToRoot
|
|
72
|
-
? ProductConfigurationBubbleMode.ToRoot
|
|
73
|
-
: ProductConfigurationBubbleMode.OneLevel);
|
|
74
|
-
}
|
|
75
|
-
return change;
|
|
76
|
-
});
|
|
77
|
-
this.structureCompare = (other, strictOrder, descriptionMatch) => compareArrays(this.features, other.features, (l, r) => l._internal.structureCompare(r._internal, strictOrder, descriptionMatch), strictOrder);
|
|
78
|
-
/**
|
|
79
|
-
* When used internally the notifications are taken care off by the caller, but if set from
|
|
80
|
-
* outside we want notifications to bubble all the way to the root.
|
|
81
|
-
*/
|
|
82
|
-
this.tryMatchSelection = (other, descriptionMatch = false, // Match on case insensitive description, not code
|
|
83
|
-
validate) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
const thisFeatures = this.features;
|
|
85
|
-
const otherFeatures = other.features;
|
|
86
|
-
const change = (yield Promise.all(otherFeatures.map((otherF) => (() => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
if (1 <
|
|
88
|
-
count(otherFeatures, (item) => item._internal.keyMatch(otherF._internal, descriptionMatch))) {
|
|
89
|
-
console.warn("tryMatchSelection will ignore items with same key");
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
const toSetFeatures = thisFeatures.filter((f) => f._internal.keyMatch(otherF._internal, descriptionMatch));
|
|
93
|
-
if (1 < toSetFeatures.length) {
|
|
94
|
-
console.warn("tryMatchSelection will ignore items with same key");
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
if (toSetFeatures.length === 0) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
return yield toSetFeatures[0]._internal.tryMatchSelection(otherF._internal, descriptionMatch);
|
|
101
|
-
}))()))).some((b) => b);
|
|
102
|
-
if (change) {
|
|
103
|
-
yield this._notifyAllOfChange(validate
|
|
104
|
-
? ProductConfigurationBubbleMode.Validate
|
|
105
|
-
: ProductConfigurationBubbleMode.OneLevel);
|
|
106
|
-
}
|
|
107
|
-
return change;
|
|
108
|
-
});
|
|
109
|
-
/** Only selected features. */
|
|
110
|
-
this._getFeaturesWithCode = (code) => this._features.reduce((agg, feature) => {
|
|
111
|
-
agg.push(...feature._internal._getFeaturesWithCode(code));
|
|
112
|
-
return agg;
|
|
113
|
-
}, []);
|
|
114
|
-
this.populateFeatures = (rootFeatureRefs) => {
|
|
115
|
-
this._rootFeatureRefs = rootFeatureRefs;
|
|
116
|
-
this._features = syncCfgFeatures(rootFeatureRefs, this._features, this.allRawFeatures, this, this, this.parentProduct, this.rootProduct);
|
|
117
|
-
};
|
|
118
|
-
this.setStretchReferenceLength = (measureParamCode, referenceLength, unit
|
|
119
|
-
if (measureParamCode === "") {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
if (referenceLength === undefined) {
|
|
123
|
-
// We assume that referenceLength === undefined shall be ignored.
|
|
124
|
-
// One can add a measureParam to a Feature in Catalogue Creator
|
|
125
|
-
// without actually having any numeric values on the Options.
|
|
126
|
-
// Then this will happen. A previous version of the code assumed
|
|
127
|
-
// undefined meant reset. However, this does not seem consistent
|
|
128
|
-
// with CET.
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
const stretchReferenceLengthsByMeasureParamCode = this.stretchReferenceLengthsByMeasureParamCode;
|
|
132
|
-
const stretchReferenceLength = stretchReferenceLengthsByMeasureParamCode.get(measureParamCode);
|
|
133
|
-
const referenceLengthWithUnit = {
|
|
134
|
-
length: referenceLength,
|
|
135
|
-
unit,
|
|
136
|
-
};
|
|
137
|
-
if (stretchReferenceLength === undefined) {
|
|
138
|
-
stretchReferenceLengthsByMeasureParamCode.set(measureParamCode, {
|
|
139
|
-
def: undefined,
|
|
140
|
-
current: referenceLengthWithUnit,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
if (stretchReferenceLength.current
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
stretchReferenceLength.current = referenceLengthWithUnit;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
window[dbgName]
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
* This method will
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
this.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
this.
|
|
255
|
-
this.
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
*
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { compareArrays, count, isEqualLength, isLengthUnit, Observable, toError, toLengthUnit, } from "@configura/web-utilities";
|
|
11
|
+
import { CfgProduct } from "../CfgProduct.js";
|
|
12
|
+
import { convertDtoConfFeaturesToSelOptions } from "../ConfigurationConverter.js";
|
|
13
|
+
import { CfgFeature } from "./CfgFeature.js";
|
|
14
|
+
import { ProductConfigurationBubbleMode } from "./CfgOption.js";
|
|
15
|
+
import { syncCfgFeatures } from "./utilitiesProductConfiguration.js";
|
|
16
|
+
/**
|
|
17
|
+
* This class is meant to only be used through CfgProductConfiguration. It should never be
|
|
18
|
+
* instantiated on its own. Normally the internal state of this class should never be directly
|
|
19
|
+
* modified. CfgProductConfiguration is the class that should be used and interacted with.
|
|
20
|
+
*/
|
|
21
|
+
export class _CfgProductConfigurationInternal {
|
|
22
|
+
constructor(allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
|
|
23
|
+
parentProduct, rootProduct) {
|
|
24
|
+
this.allRawFeatures = allRawFeatures;
|
|
25
|
+
this.parentProduct = parentProduct;
|
|
26
|
+
this.rootProduct = rootProduct;
|
|
27
|
+
this.key = "~";
|
|
28
|
+
this._rootFeatureRefs = [];
|
|
29
|
+
this._features = [];
|
|
30
|
+
this.changeObservable = new Observable();
|
|
31
|
+
this._notifyAllOfChange = (bubbleMode, committed) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
if (bubbleMode === ProductConfigurationBubbleMode.Stop) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const freshRef = CfgProductConfiguration._makeNewRefFrom(this);
|
|
36
|
+
const parent = this.parentProduct;
|
|
37
|
+
this.changeObservable.notifyAll({
|
|
38
|
+
freshRef,
|
|
39
|
+
committed,
|
|
40
|
+
});
|
|
41
|
+
if (parent === undefined) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
yield parent._configurationHasChanged(freshRef, bubbleMode === ProductConfigurationBubbleMode.OneLevel
|
|
45
|
+
? ProductConfigurationBubbleMode.Stop
|
|
46
|
+
: bubbleMode, committed);
|
|
47
|
+
});
|
|
48
|
+
/** Called by child to tell its parent that it has changed. */
|
|
49
|
+
this._childHasChanged = (freshRef, bubbleMode, committed) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const features = this._features;
|
|
51
|
+
const i = features.findIndex((a) => a.isBackedBySame(freshRef));
|
|
52
|
+
if (i === -1) {
|
|
53
|
+
throw Error("Child feature not found");
|
|
54
|
+
}
|
|
55
|
+
features[i] = freshRef;
|
|
56
|
+
yield this._notifyAllOfChange(bubbleMode, committed);
|
|
57
|
+
});
|
|
58
|
+
this.getDtoConf = (includeExtendedData) => this._features.map((f) => f._internal.getDtoConf(includeExtendedData));
|
|
59
|
+
/**
|
|
60
|
+
* When used internally the notifications are taken care off by the caller, but if set from
|
|
61
|
+
* outside we want notifications to bubble all the way to the root.
|
|
62
|
+
*/
|
|
63
|
+
this.setApiSelection = (selectedOptions, bubbleToRoot) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
const featuresLength = this._features.length;
|
|
65
|
+
const selectedOptionsLength = selectedOptions.length;
|
|
66
|
+
if (featuresLength !== selectedOptionsLength) {
|
|
67
|
+
throw new Error(`Wrong selection count. Features on this configuration: ${featuresLength}. Passed feature count: ${selectedOptionsLength}.`);
|
|
68
|
+
}
|
|
69
|
+
const change = (yield Promise.all(this._features.map((f, i) => f._internal.setApiSelection(selectedOptions[i].next)))).some((b) => b);
|
|
70
|
+
if (change) {
|
|
71
|
+
yield this._notifyAllOfChange(bubbleToRoot
|
|
72
|
+
? ProductConfigurationBubbleMode.ToRoot
|
|
73
|
+
: ProductConfigurationBubbleMode.OneLevel, true);
|
|
74
|
+
}
|
|
75
|
+
return change;
|
|
76
|
+
});
|
|
77
|
+
this.structureCompare = (other, strictOrder, descriptionMatch) => compareArrays(this.features, other.features, (l, r) => l._internal.structureCompare(r._internal, strictOrder, descriptionMatch), strictOrder);
|
|
78
|
+
/**
|
|
79
|
+
* When used internally the notifications are taken care off by the caller, but if set from
|
|
80
|
+
* outside we want notifications to bubble all the way to the root.
|
|
81
|
+
*/
|
|
82
|
+
this.tryMatchSelection = (other, descriptionMatch = false, // Match on case insensitive description, not code
|
|
83
|
+
validate) => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const thisFeatures = this.features;
|
|
85
|
+
const otherFeatures = other.features;
|
|
86
|
+
const change = (yield Promise.all(otherFeatures.map((otherF) => (() => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
if (1 <
|
|
88
|
+
count(otherFeatures, (item) => item._internal.keyMatch(otherF._internal, descriptionMatch))) {
|
|
89
|
+
console.warn("tryMatchSelection will ignore items with same key");
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const toSetFeatures = thisFeatures.filter((f) => f._internal.keyMatch(otherF._internal, descriptionMatch));
|
|
93
|
+
if (1 < toSetFeatures.length) {
|
|
94
|
+
console.warn("tryMatchSelection will ignore items with same key");
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (toSetFeatures.length === 0) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return yield toSetFeatures[0]._internal.tryMatchSelection(otherF._internal, descriptionMatch);
|
|
101
|
+
}))()))).some((b) => b);
|
|
102
|
+
if (change) {
|
|
103
|
+
yield this._notifyAllOfChange(validate
|
|
104
|
+
? ProductConfigurationBubbleMode.Validate
|
|
105
|
+
: ProductConfigurationBubbleMode.OneLevel, true);
|
|
106
|
+
}
|
|
107
|
+
return change;
|
|
108
|
+
});
|
|
109
|
+
/** Only selected features. */
|
|
110
|
+
this._getFeaturesWithCode = (code) => this._features.reduce((agg, feature) => {
|
|
111
|
+
agg.push(...feature._internal._getFeaturesWithCode(code));
|
|
112
|
+
return agg;
|
|
113
|
+
}, []);
|
|
114
|
+
this.populateFeatures = (rootFeatureRefs) => {
|
|
115
|
+
this._rootFeatureRefs = rootFeatureRefs;
|
|
116
|
+
this._features = syncCfgFeatures(rootFeatureRefs, this._features, this.allRawFeatures, this, this, this.parentProduct, this.rootProduct);
|
|
117
|
+
};
|
|
118
|
+
this.setStretchReferenceLength = (measureParamCode, referenceLength, unit) => __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
if (measureParamCode === "") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (referenceLength === undefined) {
|
|
123
|
+
// We assume that referenceLength === undefined shall be ignored.
|
|
124
|
+
// One can add a measureParam to a Feature in Catalogue Creator
|
|
125
|
+
// without actually having any numeric values on the Options.
|
|
126
|
+
// Then this will happen. A previous version of the code assumed
|
|
127
|
+
// undefined meant reset. However, this does not seem consistent
|
|
128
|
+
// with CET.
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
const stretchReferenceLengthsByMeasureParamCode = this.stretchReferenceLengthsByMeasureParamCode;
|
|
132
|
+
const stretchReferenceLength = stretchReferenceLengthsByMeasureParamCode.get(measureParamCode);
|
|
133
|
+
const referenceLengthWithUnit = {
|
|
134
|
+
length: referenceLength,
|
|
135
|
+
unit,
|
|
136
|
+
};
|
|
137
|
+
if (stretchReferenceLength === undefined) {
|
|
138
|
+
stretchReferenceLengthsByMeasureParamCode.set(measureParamCode, {
|
|
139
|
+
def: undefined,
|
|
140
|
+
current: referenceLengthWithUnit,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
if (isEqualLength(stretchReferenceLength.current, referenceLengthWithUnit)) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
stretchReferenceLength.current = referenceLengthWithUnit;
|
|
148
|
+
}
|
|
149
|
+
yield this._notifyAllOfChange(ProductConfigurationBubbleMode.ToRoot, false);
|
|
150
|
+
return true;
|
|
151
|
+
});
|
|
152
|
+
/* eslint-disable */
|
|
153
|
+
// Useful debug tool:
|
|
154
|
+
if (false) {
|
|
155
|
+
const dbgName = `conf${parentProduct.refKey || parentProduct.key}`;
|
|
156
|
+
window[dbgName] = this;
|
|
157
|
+
window.conf = this;
|
|
158
|
+
console.log(`Use "window['${dbgName}']" or window.conf to access conf.`);
|
|
159
|
+
}
|
|
160
|
+
/* eslint-enable */
|
|
161
|
+
/**
|
|
162
|
+
* Although the measurement-datas are also passed in validate-calls they are only used at
|
|
163
|
+
* initial product creation. The data is assumed to always be the same for a product, so
|
|
164
|
+
* after a validate call the product configuration values are what controls how stretched
|
|
165
|
+
* things are.
|
|
166
|
+
*/
|
|
167
|
+
const stretchReferenceLengthsByMeasureParamCode = new Map();
|
|
168
|
+
for (const measurementDefinition of parentProduct.measureDefinitions) {
|
|
169
|
+
const { measureParamCode, numericValue } = measurementDefinition;
|
|
170
|
+
if (numericValue === undefined) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
let unit;
|
|
174
|
+
const rawUnit = numericValue.unit;
|
|
175
|
+
if (rawUnit === undefined) {
|
|
176
|
+
unit = parentProduct.unit;
|
|
177
|
+
}
|
|
178
|
+
else if (rawUnit === "") {
|
|
179
|
+
unit = parentProduct.unit;
|
|
180
|
+
console.warn(`MeasureDefinition unit is empty string for code ${measureParamCode}.`);
|
|
181
|
+
}
|
|
182
|
+
else if (isLengthUnit(rawUnit)) {
|
|
183
|
+
unit = toLengthUnit(rawUnit);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.info(`MeasureDefinition unit is non length: "${rawUnit}" for code ${measureParamCode}. Ignored for stretch.`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
const referenceLength = { length: numericValue.value, unit };
|
|
190
|
+
stretchReferenceLengthsByMeasureParamCode.set(measureParamCode, {
|
|
191
|
+
def: referenceLength,
|
|
192
|
+
current: referenceLength,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
this.stretchReferenceLengthsByMeasureParamCode = stretchReferenceLengthsByMeasureParamCode;
|
|
196
|
+
}
|
|
197
|
+
static _makeUninitialized(rootFeatureRefs, allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
|
|
198
|
+
parentProduct, rootProduct) {
|
|
199
|
+
const configuration = new this(allRawFeatures, parentProduct, rootProduct);
|
|
200
|
+
configuration.populateFeatures(rootFeatureRefs);
|
|
201
|
+
return configuration;
|
|
202
|
+
}
|
|
203
|
+
get rootFeatureRefs() {
|
|
204
|
+
return this._rootFeatureRefs;
|
|
205
|
+
}
|
|
206
|
+
// The root features at the root of the selection tree.
|
|
207
|
+
get features() {
|
|
208
|
+
return this._features;
|
|
209
|
+
}
|
|
210
|
+
_freshRefDescendants() {
|
|
211
|
+
const features = this._features;
|
|
212
|
+
for (let i = 0; i < features.length; i++) {
|
|
213
|
+
const featureInternal = features[i]._internal;
|
|
214
|
+
featureInternal._freshRefDescendants();
|
|
215
|
+
features[i] = CfgFeature._makeNewRefFrom(featureInternal);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
export class CfgProductConfiguration {
|
|
220
|
+
/**
|
|
221
|
+
* Private constructor and make-method because make new ref requires the constructor to take an
|
|
222
|
+
* internal and we don't want those who instantiate CfgProductConfiguration to have to be aware
|
|
223
|
+
* of the internal.
|
|
224
|
+
*/
|
|
225
|
+
constructor(_internal) {
|
|
226
|
+
this._internal = _internal;
|
|
227
|
+
this.isBackedBySame = (other) => this._internal === other._internal;
|
|
228
|
+
this.structureCompare = (other, strictOrder = true, descriptionMatch = false) => this._internal.structureCompare(other._internal, strictOrder, descriptionMatch);
|
|
229
|
+
/**
|
|
230
|
+
* This method will try to match the selection from another product configuration
|
|
231
|
+
* This method does not propagate its selections.
|
|
232
|
+
* This method will cause validation calls.
|
|
233
|
+
*/
|
|
234
|
+
this.tryMatchSelection = (other, descriptionMatch = false // Match on case insensitive description, not code
|
|
235
|
+
) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.tryMatchSelection(other._internal, descriptionMatch, true); });
|
|
236
|
+
this.getApiSelection = () => convertDtoConfFeaturesToSelOptions(this._internal.getDtoConf(false), true);
|
|
237
|
+
/**
|
|
238
|
+
* This method does not propagate its selections.
|
|
239
|
+
* This method will not cause validation calls. Data is assumed to already be validated.
|
|
240
|
+
*/
|
|
241
|
+
this.setApiSelection = (selectedOptions) => __awaiter(this, void 0, void 0, function* () { return yield this._internal.setApiSelection(selectedOptions, true); });
|
|
242
|
+
/**
|
|
243
|
+
* Set how stretched a certain measure should be measureParamCode is the measure to be
|
|
244
|
+
* stretched referenceLength is a value relative to the initial length of the measure. If the
|
|
245
|
+
* stretch drawn up in Model Lab was from the start let's say 2.4 units from start point to end
|
|
246
|
+
* point a reference value of 4.8 would stretch the start point to end point to double length.
|
|
247
|
+
* This however does not stop things from extending outside start point to end point. So the
|
|
248
|
+
* actual perceived length after stretching might have little to do with the referenceLength.
|
|
249
|
+
* Undefined as referenceLength will clear, that is, make the stretched thing revert to its
|
|
250
|
+
* default state.
|
|
251
|
+
*/
|
|
252
|
+
this.setStretchReferenceLength = (measureParamCode, referenceLength, unit) => this._internal.setStretchReferenceLength(measureParamCode, referenceLength, unit);
|
|
253
|
+
this.listenForChange = (l) => this._internal.changeObservable.listen(l);
|
|
254
|
+
this.stopListenForChange = (l) => this._internal.changeObservable.stopListen(l);
|
|
255
|
+
this.stopAllListenForChange = () => this._internal.changeObservable.stopAllListen();
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* This method is semi-async. It will immediately give you a reference to the created
|
|
259
|
+
* CfgProductConfiguration, but is not properly initialized until the initDone-callback
|
|
260
|
+
* has been called.
|
|
261
|
+
*/
|
|
262
|
+
static make(initSuccess, initFail, rootFeatureRefs, allRawFeatures, // Flat packed. All the features that can appear anyplace in the selection tree.
|
|
263
|
+
apiSelection, parentProduct, rootProduct) {
|
|
264
|
+
const internal = _CfgProductConfigurationInternal._makeUninitialized(rootFeatureRefs, allRawFeatures, parentProduct, rootProduct);
|
|
265
|
+
const external = new this(internal);
|
|
266
|
+
// Note the async-callback at the end of the following line. The call is async.
|
|
267
|
+
internal
|
|
268
|
+
.setApiSelection(apiSelection, false)
|
|
269
|
+
.then(() => initSuccess(external))
|
|
270
|
+
.catch((e) => initFail(toError(e)));
|
|
271
|
+
return external;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Makes an object wrapping the passed object. This is not a clone method, it is a method to
|
|
275
|
+
* make a new outer reference. Like a shallow copy.
|
|
276
|
+
*
|
|
277
|
+
* We use this to help frameworks that are built around using equals to detect change.
|
|
278
|
+
*/
|
|
279
|
+
static _makeNewRefFrom(internal) {
|
|
280
|
+
return new this(internal);
|
|
281
|
+
}
|
|
282
|
+
get parentProduct() {
|
|
283
|
+
return CfgProduct._makeNewRefFrom(this._internal.parentProduct);
|
|
284
|
+
}
|
|
285
|
+
get rootProduct() {
|
|
286
|
+
return CfgProduct._makeNewRefFrom(this._internal.rootProduct);
|
|
287
|
+
}
|
|
288
|
+
get key() {
|
|
289
|
+
return this._internal.key;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Every (unprocessed) feature which might be used in this product. This is constant for a
|
|
293
|
+
* product load. What features are actually used is controlled by rootFeatureRefs and what
|
|
294
|
+
* options are selected.
|
|
295
|
+
*/
|
|
296
|
+
get allRawFeatures() {
|
|
297
|
+
return this._internal.allRawFeatures;
|
|
298
|
+
}
|
|
299
|
+
/** What features are used in the root of this. This can change with new validate calls. */
|
|
300
|
+
get rootFeatureRefs() {
|
|
301
|
+
return this._internal.rootFeatureRefs;
|
|
302
|
+
}
|
|
303
|
+
/** The root features at the root of the selection tree. */
|
|
304
|
+
get features() {
|
|
305
|
+
return this._internal.features;
|
|
306
|
+
}
|
|
307
|
+
}
|