@veloceapps/sdk 6.0.0-2 → 6.0.0-21

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.
Files changed (135) hide show
  1. package/bundles/veloceapps-sdk-cms.umd.js +144 -72
  2. package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
  3. package/bundles/veloceapps-sdk-core.umd.js +708 -615
  4. package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
  5. package/bundles/veloceapps-sdk-runtime.umd.js +209 -142
  6. package/bundles/veloceapps-sdk-runtime.umd.js.map +1 -1
  7. package/bundles/veloceapps-sdk.umd.js +354 -280
  8. package/bundles/veloceapps-sdk.umd.js.map +1 -1
  9. package/cms/vendor-map.d.ts +24 -14
  10. package/core/modules/configuration/services/configuration-runtime.service.d.ts +1 -1
  11. package/core/modules/configuration/services/configuration.service.d.ts +2 -1
  12. package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +6 -3
  13. package/core/services/metric-calculation/metric-calculation.service.d.ts +5 -1
  14. package/esm2015/cms/components/element-children/element-children.component.js +3 -3
  15. package/esm2015/cms/components/element-children/element-children.module.js +4 -4
  16. package/esm2015/cms/components/element-renderer/element-renderer.component.js +3 -3
  17. package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
  18. package/esm2015/cms/components/plugin.component.js +3 -3
  19. package/esm2015/cms/components/preview/preview.component.js +3 -3
  20. package/esm2015/cms/components/preview/preview.module.js +4 -4
  21. package/esm2015/cms/directives/custom-template.directive.js +3 -3
  22. package/esm2015/cms/launcher.module.js +4 -4
  23. package/esm2015/cms/modules/federated/federated.component.js +3 -3
  24. package/esm2015/cms/modules/federated/federated.module.js +4 -4
  25. package/esm2015/cms/plugins/configuration.plugin.js +3 -3
  26. package/esm2015/cms/plugins/io.plugin.js +3 -3
  27. package/esm2015/cms/plugins/script.plugin.js +3 -3
  28. package/esm2015/cms/services/dynamic-module.service.js +3 -3
  29. package/esm2015/cms/services/element-context.service.js +3 -3
  30. package/esm2015/cms/services/integration.state.js +3 -3
  31. package/esm2015/cms/services/io-provider.service.js +3 -3
  32. package/esm2015/cms/services/launcher.service.js +6 -5
  33. package/esm2015/cms/services/templates.service.js +3 -3
  34. package/esm2015/cms/vendor-map.js +11 -4
  35. package/esm2015/core/core.module.js +4 -4
  36. package/esm2015/core/modules/configuration/configuration.module.js +4 -4
  37. package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -5
  38. package/esm2015/core/modules/configuration/services/configuration.service.js +11 -10
  39. package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
  40. package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
  41. package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +17 -9
  42. package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +3 -3
  43. package/esm2015/core/services/context.service.js +3 -3
  44. package/esm2015/core/services/metric-calculation/metric-calculation.service.js +18 -9
  45. package/esm2015/core/services/product-images.service.js +3 -3
  46. package/esm2015/core/services/quote-draft.service.js +3 -3
  47. package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
  48. package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
  49. package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
  50. package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
  51. package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
  52. package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
  53. package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
  54. package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
  55. package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
  56. package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
  57. package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
  58. package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
  59. package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
  60. package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
  61. package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
  62. package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
  63. package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
  64. package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
  65. package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
  66. package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
  67. package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
  68. package/esm2015/runtime/execution/directives/vl-quote.directive.js +3 -3
  69. package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
  70. package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
  71. package/esm2015/runtime/runtime.module.js +4 -4
  72. package/esm2015/runtime/services/cart.service.js +3 -3
  73. package/esm2015/runtime/services/collapsible-state.service.js +3 -3
  74. package/esm2015/runtime/services/configuration.service.js +3 -3
  75. package/esm2015/runtime/services/current-state.service.js +3 -3
  76. package/esm2015/runtime/services/form-scope.service.js +3 -3
  77. package/esm2015/runtime/services/product-model-cache.service.js +3 -3
  78. package/esm2015/runtime/services/runtime-context.service.js +3 -3
  79. package/esm2015/runtime/services/runtime-form.service.js +3 -3
  80. package/esm2015/runtime/services/runtime.service.js +3 -3
  81. package/esm2015/runtime/services/section-helper.service.js +3 -3
  82. package/esm2015/runtime/services/section-scope.service.js +3 -3
  83. package/esm2015/runtime/services/section-store.service.js +3 -3
  84. package/esm2015/runtime/services/section.service.js +6 -6
  85. package/esm2015/src/components/dialog/dialog.component.js +3 -3
  86. package/esm2015/src/components/dialog/dialog.module.js +4 -4
  87. package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
  88. package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
  89. package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
  90. package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
  91. package/esm2015/src/components/header/header.component.js +3 -3
  92. package/esm2015/src/components/header/header.module.js +4 -4
  93. package/esm2015/src/components/header/metrics/metrics.component.js +79 -67
  94. package/esm2015/src/components/header/metrics/metrics.definitions.js +1 -8
  95. package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
  96. package/esm2015/src/flow-routing.module.js +4 -4
  97. package/esm2015/src/flow.component.js +3 -3
  98. package/esm2015/src/flow.module.js +4 -4
  99. package/esm2015/src/guards/context.guard.js +3 -3
  100. package/esm2015/src/guards/product-unload.guard.js +3 -3
  101. package/esm2015/src/guards/root.guard.js +3 -3
  102. package/esm2015/src/pages/catalog/catalog.component.js +3 -3
  103. package/esm2015/src/pages/catalog/catalog.module.js +4 -4
  104. package/esm2015/src/pages/debug/debug.component.js +3 -3
  105. package/esm2015/src/pages/debug/debug.module.js +4 -4
  106. package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
  107. package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
  108. package/esm2015/src/pages/legacy-product/legacy-product.component.js +3 -3
  109. package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
  110. package/esm2015/src/pages/product/product.component.js +3 -3
  111. package/esm2015/src/pages/product/product.module.js +4 -4
  112. package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
  113. package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
  114. package/esm2015/src/pages/remote/remote.component.js +3 -3
  115. package/esm2015/src/pages/remote/remote.module.js +4 -4
  116. package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +3 -3
  117. package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
  118. package/esm2015/src/resolvers/flow.resolver.js +3 -3
  119. package/esm2015/src/resolvers/quote.resolver.js +6 -6
  120. package/esm2015/src/services/doc-gen.service.js +3 -3
  121. package/esm2015/src/services/flow-dialog.service.js +3 -3
  122. package/esm2015/src/services/flow-router.service.js +3 -3
  123. package/esm2015/src/services/flow.service.js +3 -3
  124. package/esm2015/src/utils/flow.utils.js +3 -3
  125. package/fesm2015/veloceapps-sdk-cms.js +74 -67
  126. package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
  127. package/fesm2015/veloceapps-sdk-core.js +475 -460
  128. package/fesm2015/veloceapps-sdk-core.js.map +1 -1
  129. package/fesm2015/veloceapps-sdk-runtime.js +138 -138
  130. package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
  131. package/fesm2015/veloceapps-sdk.js +232 -226
  132. package/fesm2015/veloceapps-sdk.js.map +1 -1
  133. package/package.json +1 -1
  134. package/src/components/header/metrics/metrics.component.d.ts +15 -6
  135. package/src/components/header/metrics/metrics.definitions.d.ts +0 -3
@@ -1,14 +1,14 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, NgModule } from '@angular/core';
3
- import { UUID, ConfigurationContext, ConfigurationContextMode, RuntimeModel, SalesforceIdUtils, ConfigurationMode, ChargeGroupUtils } from '@veloceapps/core';
4
- import { BehaviorSubject, zip, noop, combineLatest, Subject, take as take$1, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
5
- import { filter, tap, map, switchMap, skip, take, shareReplay, first, catchError as catchError$1, finalize } from 'rxjs/operators';
3
+ import { UUID, ConfigurationContext, RuntimeModel, ConfigurationContextMode, SalesforceIdUtils, ConfigurationMode, ChargeGroupUtils } from '@veloceapps/core';
4
+ import { BehaviorSubject, combineLatest, zip, noop, throwError, shareReplay as shareReplay$1, tap as tap$1, map as map$2, of, switchMap as switchMap$1, catchError as catchError$1, Subject, take as take$1, distinctUntilChanged } from 'rxjs';
5
+ import { filter, tap, map, first, switchMap, skip, take, shareReplay, catchError, finalize } from 'rxjs/operators';
6
6
  import * as i1 from '@veloceapps/api';
7
7
  import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloceapps/api';
8
- import { merge, isEqual, uniq, flatten, sortBy, map as map$2, cloneDeep } from 'lodash';
8
+ import { merge, flatten, sortBy, map as map$1, isEqual, cloneDeep, uniq } from 'lodash';
9
9
  import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
10
- import * as i4 from 'primeng/api';
11
- import * as i5 from 'primeng/dynamicdialog';
10
+ import * as i5 from 'primeng/api';
11
+ import * as i6 from 'primeng/dynamicdialog';
12
12
  import moment from 'moment';
13
13
 
14
14
  const getDefaultLineItem = (context, uiDefinitionProperties, qty = 1) => {
@@ -72,357 +72,13 @@ class ContextService {
72
72
  this.context.next(null);
73
73
  }
74
74
  }
75
- ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
76
- ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, providedIn: 'root' });
77
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ContextService, decorators: [{
75
+ ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
76
+ ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, providedIn: 'root' });
77
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, decorators: [{
78
78
  type: Injectable,
79
79
  args: [{ providedIn: 'root' }]
80
80
  }], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
81
81
 
82
- function calculateMetricByMethod(lineItems, metric, method) {
83
- const items = getLineItemsByMethod(lineItems, method);
84
- return items.reduce((acc, li) => {
85
- let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
86
- if (method === 'avg' && li.length > 0) {
87
- value /= li.length;
88
- }
89
- return acc + value;
90
- }, 0);
91
- }
92
- function getLineItemsByMethod(lineItems, method) {
93
- switch (method) {
94
- case 'first': {
95
- return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
96
- }
97
- case 'last': {
98
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
99
- const products = rootTermItems.map(lineItem => [
100
- lineItem,
101
- ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
102
- ]);
103
- return products
104
- .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
105
- .filter((li) => Boolean(li))
106
- .map(item => [item]);
107
- }
108
- case 'avg': {
109
- const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
110
- return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
111
- }
112
- case 'sum': {
113
- return lineItems.map(item => [item]);
114
- }
115
- default: {
116
- return lineItems.map(item => [item]);
117
- }
118
- }
119
- }
120
- function getDateValue(date) {
121
- return date ? new Date(date).getTime() : 0;
122
- }
123
-
124
- class QuoteDraftService {
125
- constructor(context, quoteApiService, priceApiService) {
126
- this.context = context;
127
- this.quoteApiService = quoteApiService;
128
- this.priceApiService = priceApiService;
129
- this.quoteSubj$ = new BehaviorSubject(null);
130
- this.resetSubj$ = new BehaviorSubject(true);
131
- this.isInitializedSubj$ = new BehaviorSubject(false);
132
- this.initialCurrentState = [];
133
- this._hasUnsavedChanges = false;
134
- this.allPriceLists = [];
135
- this.assetPriceLists = [];
136
- this.reset$ = this.resetSubj$.asObservable();
137
- this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList !== null && priceList !== void 0 ? priceList : null));
138
- this.isInitializedSubj$
139
- .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
140
- .subscribe();
141
- }
142
- get isInitialized() {
143
- return this.isInitializedSubj$.getValue();
144
- }
145
- set isInitialized(value) {
146
- if (this.isInitialized !== value) {
147
- this.isInitializedSubj$.next(value);
148
- }
149
- }
150
- get hasUnsavedChanges() {
151
- return this._hasUnsavedChanges;
152
- }
153
- set hasUnsavedChanges(value) {
154
- var _a, _b;
155
- this._hasUnsavedChanges = value;
156
- if (!this._hasUnsavedChanges) {
157
- this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
158
- }
159
- }
160
- get hasAssets$() {
161
- return this.quoteSubj$.pipe(map(() => this.hasAssets));
162
- }
163
- get hasAssets() {
164
- const quoteDraft = this.quoteSubj$.value;
165
- return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
166
- }
167
- reset() {
168
- this.resetSubj$.next(true);
169
- this.quoteSubj$.next(null);
170
- this.hasUnsavedChanges = false;
171
- }
172
- init(quoteId, params) {
173
- return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
174
- this.allPriceLists = allPriceLists;
175
- this.quoteSubj$.next(quote);
176
- this.context.update(quote.context);
177
- this.populateActivePriceLists$();
178
- }), map(() => noop()), take(1));
179
- }
180
- setCurrentLineItemState(lineItems) {
181
- const quoteDraft = this.quoteSubj$.value;
182
- if (!quoteDraft) {
183
- return;
184
- }
185
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
186
- }
187
- updateQuoteDraft(update) {
188
- const quoteDraft = this.quoteSubj$.value;
189
- if (!quoteDraft) {
190
- return;
191
- }
192
- if (update.context) {
193
- this.context.set(update.context);
194
- }
195
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
196
- }
197
- updateByPriceSummary(priceSummary) {
198
- const quoteDraft = this.quoteSubj$.value;
199
- if (!quoteDraft) {
200
- return;
201
- }
202
- const updatedCurrentState = this.currentState.map(lineItem => {
203
- const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
204
- return updated !== null && updated !== void 0 ? updated : lineItem;
205
- });
206
- this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
207
- }
208
- get quoteDraft$() {
209
- return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
210
- }
211
- get quoteDraft() {
212
- const quote = this.quoteSubj$.value;
213
- if (!quote) {
214
- return null;
215
- }
216
- return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
217
- }
218
- get quoteDraftForActivePriceList() {
219
- const quoteDraft = this.quoteDraft;
220
- if (!quoteDraft) {
221
- return null;
222
- }
223
- return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
224
- }
225
- get currentState$() {
226
- return this.quoteDraft$.pipe(map(quote => quote.currentState));
227
- }
228
- get currentState() {
229
- var _a, _b;
230
- return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
231
- }
232
- /**
233
- * Stream of activeCurrentState
234
- */
235
- get activeCurrentState$() {
236
- return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
237
- }
238
- /**
239
- * activeCurrentState is currentState passed through additional filters
240
- */
241
- get activeCurrentState() {
242
- var _a, _b;
243
- let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
244
- currentState = this.filterByActivePriceList(currentState);
245
- return currentState;
246
- }
247
- /**
248
- * Stream of activeInitialState
249
- */
250
- get activeInitialState$() {
251
- return this.quoteDraft$.pipe(map(() => this.activeInitialState));
252
- }
253
- /**
254
- * activeInitialState is initialState passed through additional filters
255
- */
256
- get activeInitialState() {
257
- var _a, _b;
258
- const ctx = this.context.resolve();
259
- let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
260
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
261
- initialState = this.filterByActivePriceList(initialState);
262
- }
263
- return initialState;
264
- }
265
- get isStandalone() {
266
- return this.context.resolve().properties.standalone === 'true';
267
- }
268
- get isStandalone$() {
269
- return this.context.resolve$().pipe(map(() => this.isStandalone));
270
- }
271
- getInitialCurrentState() {
272
- return this.initialCurrentState;
273
- }
274
- isEditMode$() {
275
- return this.context.resolve$().pipe(map(() => this.isEditMode()));
276
- }
277
- isEditMode() {
278
- const context = this.context.resolve();
279
- if (context.mode === ConfigurationContextMode.ACCOUNT) {
280
- return true;
281
- }
282
- if (context.mode === ConfigurationContextMode.QUOTE) {
283
- return context.properties.Status === 'Draft';
284
- }
285
- return false;
286
- }
287
- updateActivePriceList(priceListId) {
288
- this.context.update({ properties: { PriceListId: priceListId } });
289
- }
290
- populateActivePriceLists$() {
291
- const ctx = this.context.resolve();
292
- const quoteDraft = this.quoteDraft;
293
- if (!quoteDraft) {
294
- return;
295
- }
296
- // In ACCOUNT mode populate price lists from related assets
297
- if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
298
- // Populate list of price lists
299
- this.assetPriceLists = quoteDraft.currentState
300
- .map(({ priceListId }) => priceListId)
301
- .reduce((trunk, priceListId) => {
302
- var _a, _b;
303
- if (!priceListId || trunk.some(item => item.id === priceListId)) {
304
- return trunk;
305
- }
306
- return [
307
- ...trunk,
308
- { id: priceListId, name: (_b = (_a = this.allPriceLists.find(item => item.id === priceListId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
309
- ];
310
- }, []);
311
- }
312
- }
313
- filterByActivePriceList(lineItems) {
314
- const ctx = this.context.resolve();
315
- return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
316
- }
317
- markAsUpdated(quote) {
318
- if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
319
- this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
320
- }
321
- else {
322
- this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
323
- }
324
- }
325
- }
326
- QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
327
- QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
328
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, decorators: [{
329
- type: Injectable,
330
- args: [{ providedIn: 'root' }]
331
- }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
332
-
333
- class MetricsCalculationService {
334
- constructor(quoteDraftService, settingsService) {
335
- this.quoteDraftService = quoteDraftService;
336
- this.settingsService = settingsService;
337
- this.metricsUpdated$ = new Subject();
338
- this.quoteMetricsSettings = {};
339
- this.metricsCalculationMethodMap = {};
340
- this.metricsData = {};
341
- combineLatest([
342
- this.quoteDraftService.currentState$,
343
- this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
344
- ]).subscribe(([lineItems, setting]) => {
345
- let settingsData = {};
346
- try {
347
- settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
348
- }
349
- catch (error) {
350
- settingsData = {};
351
- }
352
- this.quoteMetricsSettings = settingsData;
353
- this.updateMetrics(lineItems);
354
- });
355
- }
356
- get onMetricsUpdate$() {
357
- return this.metricsUpdated$.asObservable();
358
- }
359
- getMetricValue(metric) {
360
- return this.metricsData[metric] || 0;
361
- }
362
- updateMetrics(lineItems) {
363
- const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
364
- this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
365
- this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
366
- this.metricsUpdated$.next();
367
- }
368
- calculateMetric(lineItems, metric) {
369
- return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
370
- }
371
- buildMetricsCalculationMethods(metricKeys, initial) {
372
- return metricKeys.reduce((acc, name) => {
373
- if (acc[name]) {
374
- return acc;
375
- }
376
- acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
377
- const settingKey = name.replace(/VDM_|Total_/g, '');
378
- if (this.quoteMetricsSettings[settingKey]) {
379
- acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
380
- }
381
- return acc;
382
- }, initial);
383
- }
384
- collectMetricKeys(lineItems) {
385
- const keys = [];
386
- lineItems.forEach(lineItem => {
387
- keys.push(...Object.keys(lineItem.totalMetrics || {}));
388
- keys.push(...this.collectMetricKeys(lineItem.lineItems));
389
- });
390
- return uniq(keys);
391
- }
392
- }
393
- MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
394
- MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
395
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: MetricsCalculationService, decorators: [{
396
- type: Injectable,
397
- args: [{ providedIn: 'root' }]
398
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: i1.ConfigurationSettingsApiService }]; } });
399
-
400
- class ProductImagesService {
401
- constructor(productApiService) {
402
- this.productApiService = productApiService;
403
- this.imagesMap$ = new BehaviorSubject({});
404
- }
405
- getImageUrl$(productId) {
406
- if (this.imagesMap$.value[productId] == null) {
407
- this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
408
- this.fetchProductImage(productId);
409
- }
410
- return this.imagesMap$.pipe(map$1(imagesMap => imagesMap[productId]), distinctUntilChanged());
411
- }
412
- fetchProductImage(productId) {
413
- this.productApiService
414
- .fetchImage$(productId)
415
- .pipe(map$1(file => URL.createObjectURL(file)), catchError(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
416
- .subscribe();
417
- }
418
- }
419
- ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
420
- ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
421
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ProductImagesService, decorators: [{
422
- type: Injectable,
423
- args: [{ providedIn: 'root' }]
424
- }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
425
-
426
82
  class RuntimeContextService {
427
83
  constructor(configurationApiService) {
428
84
  this.configurationApiService = configurationApiService;
@@ -462,9 +118,9 @@ class RuntimeContextService {
462
118
  return uiDefinition;
463
119
  }
464
120
  }
465
- RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
466
- RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService });
467
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: RuntimeContextService, decorators: [{
121
+ RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
122
+ RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService });
123
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService, decorators: [{
468
124
  type: Injectable
469
125
  }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
470
126
 
@@ -545,9 +201,9 @@ class ConfigurationRuntimeService {
545
201
  return this._runtimeContext;
546
202
  }
547
203
  }
548
- ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
549
- ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService });
550
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
204
+ ConfigurationRuntimeService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService, deps: [{ token: i1.ConfigurationApiService }, { token: ContextService }, { token: RuntimeContextService }], target: i0.ɵɵFactoryTarget.Injectable });
205
+ ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService });
206
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationRuntimeService, decorators: [{
551
207
  type: Injectable
552
208
  }], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }, { type: ContextService }, { type: RuntimeContextService }]; } });
553
209
 
@@ -622,78 +278,287 @@ const patchAttributes = (rootLineItem, id, attrs) => {
622
278
  if (!lineItem) {
623
279
  return rootLineItem;
624
280
  }
625
- const attributes = upsertAttributes(lineItem.attributes, attrs);
626
- return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
627
- };
628
- const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
629
- const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
630
- return {
631
- id: UUID.UUID(),
632
- port,
633
- type,
634
- actionCode: 'ADD',
635
- cfgStatus: 'New',
636
- attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
637
- lineItems,
638
- parentId,
639
- qty: 1,
640
- };
641
- };
642
- const getRecommendedPrices = (portDomain, type) => {
643
- var _a, _b;
644
- const domainType = portDomain.domainTypes.find(({ name }) => name === type);
645
- const [net, list] = (_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME').reduce((acc, rp) => {
646
- const [netPrice, listPrice] = acc;
647
- return [netPrice + rp.netPrice, listPrice + rp.listPrice];
648
- }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
649
- return { net, list };
650
- };
651
- const multiplyLineItems = (lineItem, qty, split) => {
652
- if (split) {
653
- const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
654
- return map$2(new Array(qty), () => unifyIds(lineItem));
281
+ const attributes = upsertAttributes(lineItem.attributes, attrs);
282
+ return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
283
+ };
284
+ const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
285
+ const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
286
+ return {
287
+ id: UUID.UUID(),
288
+ port,
289
+ type,
290
+ actionCode: 'ADD',
291
+ cfgStatus: 'New',
292
+ attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
293
+ lineItems,
294
+ parentId,
295
+ qty: 1,
296
+ };
297
+ };
298
+ const getRecommendedPrices = (portDomain, type) => {
299
+ var _a, _b;
300
+ const domainType = portDomain.domainTypes.find(({ name }) => name === type);
301
+ const [net, list] = (_b = (_a = domainType === null || domainType === void 0 ? void 0 : domainType.recommendedPrices) === null || _a === void 0 ? void 0 : _a.filter(({ chargeMethod }) => chargeMethod === 'ONE_TIME').reduce((acc, rp) => {
302
+ const [netPrice, listPrice] = acc;
303
+ return [netPrice + rp.netPrice, listPrice + rp.listPrice];
304
+ }, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
305
+ return { net, list };
306
+ };
307
+ const multiplyLineItems = (lineItem, qty, split) => {
308
+ if (split) {
309
+ const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
310
+ return map$1(new Array(qty), () => unifyIds(lineItem));
311
+ }
312
+ else {
313
+ return [
314
+ Object.assign(Object.assign({}, lineItem), { qty: qty }),
315
+ ];
316
+ }
317
+ };
318
+
319
+ var lineItem_utils = /*#__PURE__*/Object.freeze({
320
+ __proto__: null,
321
+ findLineItem: findLineItem,
322
+ findLineItemWithComparator: findLineItemWithComparator,
323
+ insertLineItem: insertLineItem,
324
+ removeLineItem: removeLineItem,
325
+ replaceLineItem: replaceLineItem,
326
+ mapAttributes: mapAttributes,
327
+ getAttributes: getAttributes,
328
+ upsertAttributes: upsertAttributes,
329
+ patchAttributes: patchAttributes,
330
+ getAttributeValue: getAttributeValue,
331
+ generateLineItem: generateLineItem,
332
+ getRecommendedPrices: getRecommendedPrices,
333
+ multiplyLineItems: multiplyLineItems
334
+ });
335
+
336
+ class LineItemWorker {
337
+ constructor(src) {
338
+ this.li = Object.assign({}, src);
339
+ }
340
+ insert(parentId, toInsert) {
341
+ return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
342
+ }
343
+ remove(id) {
344
+ return new LineItemWorker(removeLineItem(this.li, id));
345
+ }
346
+ replace(toReplace) {
347
+ return new LineItemWorker(replaceLineItem(this.li, toReplace));
348
+ }
349
+ patchAttribute(attrs, id) {
350
+ return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
351
+ }
352
+ }
353
+
354
+ class QuoteDraftService {
355
+ constructor(context, quoteApiService, priceApiService) {
356
+ this.context = context;
357
+ this.quoteApiService = quoteApiService;
358
+ this.priceApiService = priceApiService;
359
+ this.quoteSubj$ = new BehaviorSubject(null);
360
+ this.resetSubj$ = new BehaviorSubject(true);
361
+ this.isInitializedSubj$ = new BehaviorSubject(false);
362
+ this.initialCurrentState = [];
363
+ this._hasUnsavedChanges = false;
364
+ this.allPriceLists = [];
365
+ this.assetPriceLists = [];
366
+ this.reset$ = this.resetSubj$.asObservable();
367
+ this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), map(priceList => priceList !== null && priceList !== void 0 ? priceList : null));
368
+ this.isInitializedSubj$
369
+ .pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
370
+ .subscribe();
371
+ }
372
+ get isInitialized() {
373
+ return this.isInitializedSubj$.getValue();
374
+ }
375
+ set isInitialized(value) {
376
+ if (this.isInitialized !== value) {
377
+ this.isInitializedSubj$.next(value);
378
+ }
379
+ }
380
+ get hasUnsavedChanges() {
381
+ return this._hasUnsavedChanges;
382
+ }
383
+ set hasUnsavedChanges(value) {
384
+ var _a, _b;
385
+ this._hasUnsavedChanges = value;
386
+ if (!this._hasUnsavedChanges) {
387
+ this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
388
+ }
389
+ }
390
+ get hasAssets$() {
391
+ return this.quoteSubj$.pipe(map(() => this.hasAssets));
392
+ }
393
+ get hasAssets() {
394
+ const quoteDraft = this.quoteSubj$.value;
395
+ return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
396
+ }
397
+ reset() {
398
+ this.resetSubj$.next(true);
399
+ this.quoteSubj$.next(null);
400
+ this.hasUnsavedChanges = false;
401
+ }
402
+ init(quoteId, params) {
403
+ return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
404
+ this.allPriceLists = allPriceLists;
405
+ this.quoteSubj$.next(quote);
406
+ this.context.update(quote.context);
407
+ this.populateActivePriceLists$();
408
+ }), map(() => noop()), take(1));
409
+ }
410
+ setCurrentLineItemState(lineItems) {
411
+ const quoteDraft = this.quoteSubj$.value;
412
+ if (!quoteDraft) {
413
+ return;
414
+ }
415
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
416
+ }
417
+ updateQuoteDraft(update) {
418
+ const quoteDraft = this.quoteSubj$.value;
419
+ if (!quoteDraft) {
420
+ return;
421
+ }
422
+ if (update.context) {
423
+ this.context.set(update.context);
424
+ }
425
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
426
+ }
427
+ updateByPriceSummary(priceSummary) {
428
+ const quoteDraft = this.quoteSubj$.value;
429
+ if (!quoteDraft) {
430
+ return;
431
+ }
432
+ const updatedCurrentState = this.currentState.map(lineItem => {
433
+ const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
434
+ return updated !== null && updated !== void 0 ? updated : lineItem;
435
+ });
436
+ this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
437
+ }
438
+ get quoteDraft$() {
439
+ return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
440
+ }
441
+ get quoteDraft() {
442
+ const quote = this.quoteSubj$.value;
443
+ if (!quote) {
444
+ return null;
445
+ }
446
+ return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
447
+ }
448
+ get quoteDraftForActivePriceList() {
449
+ const quoteDraft = this.quoteDraft;
450
+ if (!quoteDraft) {
451
+ return null;
452
+ }
453
+ return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
454
+ }
455
+ get currentState$() {
456
+ return this.quoteDraft$.pipe(map(quote => quote.currentState));
457
+ }
458
+ get currentState() {
459
+ var _a, _b;
460
+ return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
461
+ }
462
+ /**
463
+ * Stream of activeCurrentState
464
+ */
465
+ get activeCurrentState$() {
466
+ return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
467
+ }
468
+ /**
469
+ * activeCurrentState is currentState passed through additional filters
470
+ */
471
+ get activeCurrentState() {
472
+ var _a, _b;
473
+ let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
474
+ currentState = this.filterByActivePriceList(currentState);
475
+ return currentState;
476
+ }
477
+ /**
478
+ * Stream of activeInitialState
479
+ */
480
+ get activeInitialState$() {
481
+ return this.quoteDraft$.pipe(map(() => this.activeInitialState));
482
+ }
483
+ /**
484
+ * activeInitialState is initialState passed through additional filters
485
+ */
486
+ get activeInitialState() {
487
+ var _a, _b;
488
+ const ctx = this.context.resolve();
489
+ let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
490
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
491
+ initialState = this.filterByActivePriceList(initialState);
492
+ }
493
+ return initialState;
494
+ }
495
+ get isStandalone() {
496
+ return this.context.resolve().properties.standalone === 'true';
655
497
  }
656
- else {
657
- return [
658
- Object.assign(Object.assign({}, lineItem), { qty: qty }),
659
- ];
498
+ get isStandalone$() {
499
+ return this.context.resolve$().pipe(map(() => this.isStandalone));
660
500
  }
661
- };
662
-
663
- var lineItem_utils = /*#__PURE__*/Object.freeze({
664
- __proto__: null,
665
- findLineItem: findLineItem,
666
- findLineItemWithComparator: findLineItemWithComparator,
667
- insertLineItem: insertLineItem,
668
- removeLineItem: removeLineItem,
669
- replaceLineItem: replaceLineItem,
670
- mapAttributes: mapAttributes,
671
- getAttributes: getAttributes,
672
- upsertAttributes: upsertAttributes,
673
- patchAttributes: patchAttributes,
674
- getAttributeValue: getAttributeValue,
675
- generateLineItem: generateLineItem,
676
- getRecommendedPrices: getRecommendedPrices,
677
- multiplyLineItems: multiplyLineItems
678
- });
679
-
680
- class LineItemWorker {
681
- constructor(src) {
682
- this.li = Object.assign({}, src);
501
+ getInitialCurrentState() {
502
+ return this.initialCurrentState;
683
503
  }
684
- insert(parentId, toInsert) {
685
- return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
504
+ isEditMode$() {
505
+ return this.context.resolve$().pipe(map(() => this.isEditMode()));
686
506
  }
687
- remove(id) {
688
- return new LineItemWorker(removeLineItem(this.li, id));
507
+ isEditMode() {
508
+ const context = this.context.resolve();
509
+ if (context.mode === ConfigurationContextMode.ACCOUNT) {
510
+ return true;
511
+ }
512
+ if (context.mode === ConfigurationContextMode.QUOTE) {
513
+ return context.properties.Status === 'Draft';
514
+ }
515
+ return false;
689
516
  }
690
- replace(toReplace) {
691
- return new LineItemWorker(replaceLineItem(this.li, toReplace));
517
+ updateActivePriceList(priceListId) {
518
+ this.context.update({ properties: { PriceListId: priceListId } });
692
519
  }
693
- patchAttribute(attrs, id) {
694
- return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
520
+ populateActivePriceLists$() {
521
+ const ctx = this.context.resolve();
522
+ const quoteDraft = this.quoteDraft;
523
+ if (!quoteDraft) {
524
+ return;
525
+ }
526
+ // In ACCOUNT mode populate price lists from related assets
527
+ if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
528
+ // Populate list of price lists
529
+ this.assetPriceLists = quoteDraft.currentState
530
+ .map(({ priceListId }) => priceListId)
531
+ .reduce((trunk, priceListId) => {
532
+ var _a, _b;
533
+ if (!priceListId || trunk.some(item => item.id === priceListId)) {
534
+ return trunk;
535
+ }
536
+ return [
537
+ ...trunk,
538
+ { id: priceListId, name: (_b = (_a = this.allPriceLists.find(item => item.id === priceListId)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '' },
539
+ ];
540
+ }, []);
541
+ }
542
+ }
543
+ filterByActivePriceList(lineItems) {
544
+ const ctx = this.context.resolve();
545
+ return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
546
+ }
547
+ markAsUpdated(quote) {
548
+ if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
549
+ this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
550
+ }
551
+ else {
552
+ this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
553
+ }
695
554
  }
696
555
  }
556
+ QuoteDraftService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, deps: [{ token: ContextService }, { token: i1.QuoteApiService }, { token: i1.PriceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
557
+ QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
558
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, decorators: [{
559
+ type: Injectable,
560
+ args: [{ providedIn: 'root' }]
561
+ }], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
697
562
 
698
563
  class ConfigurationService {
699
564
  constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
@@ -726,7 +591,7 @@ class ConfigurationService {
726
591
  this.states.asset = this.states.configurableRamp
727
592
  ? this.runtimeService.getAsset(this.states.configurableRamp)
728
593
  : undefined;
729
- return this.configure().pipe(catchError$1(error => {
594
+ return this.configure().pipe(catchError(error => {
730
595
  console.error(error);
731
596
  if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
732
597
  this.messageService.add({ severity: 'error', summary: error });
@@ -800,13 +665,13 @@ class ConfigurationService {
800
665
  }
801
666
  return lineItem;
802
667
  }))
803
- .pipe(tap(lineItem => lineItem && this.lineItem.next(lineItem)), catchError$1(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })));
668
+ .pipe(tap(lineItem => lineItem && this.lineItem.next(lineItem)), catchError(error => throwError(() => { var _a; return new Error(((_a = error.error) === null || _a === void 0 ? void 0 : _a.message) || error.message || JSON.stringify(error)); })));
804
669
  }
805
670
  configureExternal$(productId, qty) {
806
671
  this.updateCurrentStates({
807
672
  currentState: this.quoteDraftService.currentState,
808
673
  });
809
- return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError$1(error => {
674
+ return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError(error => {
810
675
  this.messageService.add({ severity: ToastType.error, summary: error });
811
676
  throw error;
812
677
  }), finalize(() => this.reset()));
@@ -848,11 +713,11 @@ class ConfigurationService {
848
713
  });
849
714
  }
850
715
  }
851
- ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i4.MessageService }, { token: i5.DialogService }], target: i0.ɵɵFactoryTarget.Injectable });
852
- ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService });
853
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationService, decorators: [{
716
+ ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService, deps: [{ token: QuoteDraftService }, { token: ConfigurationRuntimeService }, { token: ContextService }, { token: i1.ConfigurationApiService }, { token: i5.MessageService }, { token: i6.DialogService }], target: i0.ɵɵFactoryTarget.Injectable });
717
+ ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService });
718
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService, decorators: [{
854
719
  type: Injectable
855
- }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i4.MessageService }, { type: i5.DialogService }]; } });
720
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }]; } });
856
721
 
857
722
  class FlowUpdateService {
858
723
  update(rootLineItems, updates) {
@@ -971,9 +836,9 @@ class FlowUpdateService {
971
836
  return true;
972
837
  }
973
838
  }
974
- FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
975
- FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService });
976
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowUpdateService, decorators: [{
839
+ FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
840
+ FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService });
841
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, decorators: [{
977
842
  type: Injectable
978
843
  }] });
979
844
 
@@ -993,7 +858,7 @@ class FlowConfigurationService {
993
858
  .slice()
994
859
  .sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
995
860
  this.quoteDraftService.updateQuoteDraft(result);
996
- }), map$1(noop));
861
+ }), map$2(noop));
997
862
  }
998
863
  calculate(quoteDraft) {
999
864
  this.calculate$(quoteDraft).subscribe();
@@ -1003,11 +868,11 @@ class FlowConfigurationService {
1003
868
  if (!quoteDraft) {
1004
869
  return of(null);
1005
870
  }
1006
- return of([]).pipe(map$1(() => {
871
+ return of([]).pipe(map$2(() => {
1007
872
  const updatedState = cloneDeep(quoteDraft.currentState);
1008
873
  this.updateService.update(updatedState, updates);
1009
874
  return updatedState;
1010
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
875
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1011
876
  }
1012
877
  update(updates) {
1013
878
  this.update$(updates).subscribe();
@@ -1026,7 +891,7 @@ class FlowConfigurationService {
1026
891
  updatedState.splice(currentLineItemIndex, 1, initialLineItem);
1027
892
  return of([]).pipe(tap$1(() => {
1028
893
  this.quoteDraftService.setCurrentLineItemState(updatedState);
1029
- }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
894
+ }), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1030
895
  }
1031
896
  revert(lineItemId) {
1032
897
  this.revert$(lineItemId).subscribe();
@@ -1037,7 +902,7 @@ class FlowConfigurationService {
1037
902
  if (!quoteDraft) {
1038
903
  return of(null);
1039
904
  }
1040
- return of([]).pipe(map$1(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
905
+ return of([]).pipe(map$2(() => ids.reduce((result, id) => this.updateService.delete(result, id), currentState)), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1041
906
  }
1042
907
  delete(ids) {
1043
908
  this.delete$(ids).subscribe();
@@ -1048,33 +913,36 @@ class FlowConfigurationService {
1048
913
  return of(null);
1049
914
  }
1050
915
  const updatedState = [...quoteDraft.currentState, term];
1051
- return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
916
+ return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1052
917
  }
1053
918
  addToCart$(productId, qty) {
1054
919
  const quoteDraft = this.quoteDraftService.quoteDraft;
1055
920
  if (!quoteDraft) {
1056
921
  return of(null);
1057
922
  }
1058
- return this.configurationService.configureExternal$(productId, qty).pipe(map$1(lineItem => {
923
+ return this.configurationService.configureExternal$(productId, qty).pipe(map$2(lineItem => {
1059
924
  var _a, _b;
1060
925
  const model = this.configurationService.getRuntimeModel();
1061
926
  const split = (_b = (_a = model === null || model === void 0 ? void 0 : model.types.find(type => type.name === lineItem.type)) === null || _a === void 0 ? void 0 : _a.split) !== null && _b !== void 0 ? _b : false;
1062
927
  const lineItems = multiplyLineItems(lineItem, qty !== null && qty !== void 0 ? qty : 1, split);
1063
928
  return [...quoteDraft.currentState, ...lineItems];
1064
- }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
929
+ }), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
1065
930
  }
1066
931
  get() {
1067
- return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
932
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
1068
933
  }
1069
934
  getSnapshot() {
1070
935
  var _a, _b;
1071
936
  return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
1072
937
  }
1073
938
  get charges$() {
1074
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
939
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
1075
940
  }
1076
941
  get pricePlans$() {
1077
- return this.quoteDraftService.quoteDraft$.pipe(map$1(({ pricePlans }) => pricePlans));
942
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
943
+ }
944
+ get activeMetrics$() {
945
+ return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
1078
946
  }
1079
947
  get chargesSnapshot() {
1080
948
  var _a, _b;
@@ -1084,6 +952,10 @@ class FlowConfigurationService {
1084
952
  var _a, _b;
1085
953
  return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
1086
954
  }
955
+ get activeMetricsSnapshot() {
956
+ var _a, _b;
957
+ return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
958
+ }
1087
959
  get contextSnapshot() {
1088
960
  return this.contextService.resolve();
1089
961
  }
@@ -1092,7 +964,7 @@ class FlowConfigurationService {
1092
964
  }
1093
965
  handleErrorAndBounceBack() {
1094
966
  return (source$) => {
1095
- return source$.pipe(catchError(error => {
967
+ return source$.pipe(catchError$1(error => {
1096
968
  console.error(error);
1097
969
  // bounce back if configuration call has failed
1098
970
  const quoteDraft = this.quoteDraftService.quoteDraft;
@@ -1104,18 +976,18 @@ class FlowConfigurationService {
1104
976
  };
1105
977
  }
1106
978
  }
1107
- FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
1108
- FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService });
1109
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, decorators: [{
979
+ FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.ProceduresApiService }, { token: ContextService }, { token: QuoteDraftService }, { token: FlowUpdateService }, { token: ConfigurationService }], target: i0.ɵɵFactoryTarget.Injectable });
980
+ FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService });
981
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService, decorators: [{
1110
982
  type: Injectable
1111
983
  }], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
1112
984
 
1113
985
  class FlowConfigurationModule {
1114
986
  }
1115
- FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1116
- FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule });
1117
- FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
1118
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationModule, decorators: [{
987
+ FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
988
+ FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule });
989
+ FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
990
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, decorators: [{
1119
991
  type: NgModule,
1120
992
  args: [{
1121
993
  imports: [],
@@ -1125,9 +997,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1125
997
 
1126
998
  class ConfigurationModule {
1127
999
  }
1128
- ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1129
- ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1130
- ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, providers: [
1000
+ ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1001
+ ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
1002
+ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, providers: [
1131
1003
  ContextApiService,
1132
1004
  ProductModelApiService,
1133
1005
  ConfigurationApiService,
@@ -1135,7 +1007,7 @@ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
1135
1007
  RuntimeContextService,
1136
1008
  ConfigurationService,
1137
1009
  ], imports: [[ConfirmationDialogModule]] });
1138
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: ConfigurationModule, decorators: [{
1010
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, decorators: [{
1139
1011
  type: NgModule,
1140
1012
  args: [{
1141
1013
  imports: [ConfirmationDialogModule],
@@ -1150,12 +1022,155 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
1150
1022
  }]
1151
1023
  }] });
1152
1024
 
1025
+ function calculateMetricByMethod(lineItems, metric, method) {
1026
+ const items = getLineItemsByMethod(lineItems, method);
1027
+ return items.reduce((acc, li) => {
1028
+ let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
1029
+ if (method === 'avg' && li.length > 0) {
1030
+ value /= li.length;
1031
+ }
1032
+ return acc + value;
1033
+ }, 0);
1034
+ }
1035
+ function getLineItemsByMethod(lineItems, method) {
1036
+ switch (method) {
1037
+ case 'first': {
1038
+ return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
1039
+ }
1040
+ case 'last': {
1041
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1042
+ const products = rootTermItems.map(lineItem => [
1043
+ lineItem,
1044
+ ...lineItems.filter(li => li.rampInstanceId === lineItem.id),
1045
+ ]);
1046
+ return products
1047
+ .map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
1048
+ .filter((li) => Boolean(li))
1049
+ .map(item => [item]);
1050
+ }
1051
+ case 'avg': {
1052
+ const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
1053
+ return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
1054
+ }
1055
+ case 'sum': {
1056
+ return lineItems.map(item => [item]);
1057
+ }
1058
+ default: {
1059
+ return lineItems.map(item => [item]);
1060
+ }
1061
+ }
1062
+ }
1063
+ function getDateValue(date) {
1064
+ return date ? new Date(date).getTime() : 0;
1065
+ }
1066
+
1067
+ class MetricsCalculationService {
1068
+ constructor(quoteDraftService, flowConfiguration, settingsService) {
1069
+ this.quoteDraftService = quoteDraftService;
1070
+ this.flowConfiguration = flowConfiguration;
1071
+ this.settingsService = settingsService;
1072
+ this.metricsUpdated$ = new Subject();
1073
+ this.quoteMetricsSettings = {};
1074
+ this.metricsCalculationMethodMap = {};
1075
+ this.metricsData = {};
1076
+ this.activeMetricRules = [];
1077
+ this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
1078
+ combineLatest([
1079
+ this.quoteDraftService.currentState$,
1080
+ this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
1081
+ ]).subscribe(([lineItems, setting]) => {
1082
+ let settingsData = {};
1083
+ try {
1084
+ settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
1085
+ }
1086
+ catch (error) {
1087
+ settingsData = {};
1088
+ }
1089
+ this.quoteMetricsSettings = settingsData;
1090
+ this.updateMetrics(lineItems);
1091
+ });
1092
+ }
1093
+ get onMetricsUpdate$() {
1094
+ return this.metricsUpdated$.asObservable();
1095
+ }
1096
+ getMetricValue(metric) {
1097
+ return this.metricsData[metric] || 0;
1098
+ }
1099
+ updateMetrics(lineItems) {
1100
+ const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
1101
+ this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
1102
+ this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
1103
+ this.metricsUpdated$.next();
1104
+ }
1105
+ calculateMetric(lineItems, metric) {
1106
+ return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
1107
+ }
1108
+ buildMetricsCalculationMethods(metricKeys, initial) {
1109
+ return metricKeys.reduce((acc, name) => {
1110
+ var _a, _b;
1111
+ if (acc[name]) {
1112
+ return acc;
1113
+ }
1114
+ acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
1115
+ const metricRule = this.getMetricRuleByTotalMetricName(name);
1116
+ const settingKey = ((_b = (_a = metricRule === null || metricRule === void 0 ? void 0 : metricRule.metrics) === null || _a === void 0 ? void 0 : _a.find(metric => metric.totalName === name)) === null || _b === void 0 ? void 0 : _b.name) || name;
1117
+ if (this.quoteMetricsSettings[settingKey]) {
1118
+ acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
1119
+ }
1120
+ return acc;
1121
+ }, initial);
1122
+ }
1123
+ collectMetricKeys(lineItems) {
1124
+ const keys = [];
1125
+ lineItems.forEach(lineItem => {
1126
+ keys.push(...Object.keys(lineItem.totalMetrics || {}));
1127
+ keys.push(...this.collectMetricKeys(lineItem.lineItems));
1128
+ });
1129
+ return uniq(keys);
1130
+ }
1131
+ getMetricRuleByTotalMetricName(name) {
1132
+ return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
1133
+ }
1134
+ }
1135
+ MetricsCalculationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: FlowConfigurationService }, { token: i1.ConfigurationSettingsApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1136
+ MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
1137
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, decorators: [{
1138
+ type: Injectable,
1139
+ args: [{ providedIn: 'root' }]
1140
+ }], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
1141
+
1142
+ class ProductImagesService {
1143
+ constructor(productApiService) {
1144
+ this.productApiService = productApiService;
1145
+ this.imagesMap$ = new BehaviorSubject({});
1146
+ }
1147
+ getImageUrl$(productId) {
1148
+ if (this.imagesMap$.value[productId] == null) {
1149
+ this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
1150
+ this.fetchProductImage(productId);
1151
+ }
1152
+ return this.imagesMap$.pipe(map$2(imagesMap => imagesMap[productId]), distinctUntilChanged());
1153
+ }
1154
+ fetchProductImage(productId) {
1155
+ this.productApiService
1156
+ .fetchImage$(productId)
1157
+ .pipe(map$2(file => URL.createObjectURL(file)), catchError$1(() => of('')), tap$1(url => this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: url }))))
1158
+ .subscribe();
1159
+ }
1160
+ }
1161
+ ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
1162
+ ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
1163
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, decorators: [{
1164
+ type: Injectable,
1165
+ args: [{ providedIn: 'root' }]
1166
+ }], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
1167
+
1153
1168
  class SdkCoreModule {
1154
1169
  }
1155
- SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1156
- SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1157
- SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1158
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: SdkCoreModule, decorators: [{
1170
+ SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1171
+ SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
1172
+ SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
1173
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, decorators: [{
1159
1174
  type: NgModule,
1160
1175
  args: [{
1161
1176
  imports: [ConfigurationModule, FlowConfigurationModule],