@veloceapps/sdk 6.0.0-1 → 6.0.0-100
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/README.md +10 -2
- package/bundles/veloceapps-sdk-cms.umd.js +1270 -798
- package/bundles/veloceapps-sdk-cms.umd.js.map +1 -1
- package/bundles/veloceapps-sdk-core.umd.js +783 -650
- package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
- package/bundles/veloceapps-sdk-runtime.umd.js +216 -150
- package/bundles/veloceapps-sdk-runtime.umd.js.map +1 -1
- package/bundles/veloceapps-sdk.umd.js +574 -309
- package/bundles/veloceapps-sdk.umd.js.map +1 -1
- package/cms/cms.actions.d.ts +2 -4
- package/cms/components/element-children/element-children.component.d.ts +13 -3
- package/cms/components/element-children/element-children.module.d.ts +4 -2
- package/cms/components/element-drop-handle/element-drop-handle.component.d.ts +12 -0
- package/cms/components/element-drop-handle/element-drop-handle.module.d.ts +9 -0
- package/cms/components/element-renderer/element-renderer.component.d.ts +3 -3
- package/cms/components/preview/index.d.ts +1 -0
- package/cms/components/preview/preview.component.d.ts +9 -8
- package/cms/components/preview/preview.module.d.ts +2 -1
- package/cms/components/preview/preview.types.d.ts +11 -0
- package/cms/index.d.ts +2 -0
- package/cms/launcher.module.d.ts +3 -1
- package/cms/modules/migrations/index.d.ts +2 -0
- package/cms/modules/migrations/migrations.d.ts +2 -0
- package/cms/modules/migrations/migrations.module.d.ts +6 -0
- package/cms/modules/migrations/services/migrations.service.d.ts +10 -0
- package/cms/modules/migrations/types/migrations.types.d.ts +2 -0
- package/cms/modules/runtime/index.d.ts +2 -0
- package/cms/modules/runtime/runtime.module.d.ts +8 -0
- package/cms/modules/runtime/services/compilation.service.d.ts +18 -0
- package/cms/modules/runtime/services/runtime-editor.service.d.ts +18 -0
- package/cms/modules/runtime/services/runtime.service.d.ts +27 -0
- package/cms/modules/runtime/tokens.d.ts +3 -0
- package/cms/{types → modules/runtime/types}/compilation.types.d.ts +1 -1
- package/cms/modules/runtime/types/runtime.actions.d.ts +9 -0
- package/cms/services/index.d.ts +1 -1
- package/cms/services/integration.state.d.ts +2 -3
- package/cms/services/io-provider.service.d.ts +3 -3
- package/cms/services/resources.service.d.ts +10 -0
- package/cms/types/common.types.d.ts +1 -1
- package/cms/types/configuration.types.d.ts +1 -0
- package/cms/types/index.d.ts +1 -1
- package/cms/types/integration.types.d.ts +5 -0
- package/cms/utils/elements-resolver.d.ts +3 -2
- package/cms/utils/index.d.ts +1 -0
- package/cms/utils/path.utils.d.ts +0 -1
- package/cms/utils/ui-definition.utils.d.ts +6 -0
- package/cms/vendor-map.d.ts +51 -30
- package/core/modules/configuration/services/configuration-runtime.service.d.ts +2 -4
- package/core/modules/configuration/services/configuration.service.d.ts +6 -4
- package/core/modules/configuration/types/configuration-runtime.types.d.ts +0 -2
- package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +6 -3
- package/core/modules/flow-configuration/services/flow-update.service.d.ts +3 -2
- package/core/services/context.service.d.ts +1 -0
- package/core/services/metric-calculation/metric-calculation.service.d.ts +5 -1
- package/core/services/quote-draft.service.d.ts +2 -2
- package/core/types/index.d.ts +0 -1
- package/core/types/ui-definition.types.d.ts +19 -4
- package/core/utils/index.d.ts +1 -0
- package/core/utils/line-item.utils.d.ts +2 -0
- package/core/utils/ui-definition.utils.d.ts +2 -0
- package/esm2015/cms/cms.actions.js +1 -6
- package/esm2015/cms/components/element-children/element-children.component.js +24 -8
- package/esm2015/cms/components/element-children/element-children.module.js +8 -6
- package/esm2015/cms/components/element-drop-handle/element-drop-handle.component.js +32 -0
- package/esm2015/cms/components/element-drop-handle/element-drop-handle.module.js +19 -0
- package/esm2015/cms/components/element-renderer/element-renderer.component.js +9 -9
- package/esm2015/cms/components/element-renderer/element-renderer.module.js +4 -4
- package/esm2015/cms/components/plugin.component.js +3 -3
- package/esm2015/cms/components/preview/index.js +2 -1
- package/esm2015/cms/components/preview/preview.component.js +21 -36
- package/esm2015/cms/components/preview/preview.module.js +7 -6
- package/esm2015/cms/components/preview/preview.types.js +2 -0
- package/esm2015/cms/directives/custom-template.directive.js +3 -3
- package/esm2015/cms/index.js +3 -1
- package/esm2015/cms/launcher.module.js +11 -10
- package/esm2015/cms/modules/federated/federated.component.js +3 -3
- package/esm2015/cms/modules/federated/federated.module.js +4 -4
- package/esm2015/cms/modules/migrations/index.js +3 -0
- package/esm2015/cms/modules/migrations/migrations.js +11 -0
- package/esm2015/cms/modules/migrations/migrations.module.js +15 -0
- package/esm2015/cms/modules/migrations/services/migrations.service.js +43 -0
- package/esm2015/cms/modules/migrations/types/migrations.types.js +2 -0
- package/esm2015/cms/modules/runtime/index.js +3 -0
- package/esm2015/cms/modules/runtime/runtime.module.js +32 -0
- package/esm2015/cms/modules/runtime/services/compilation.service.js +84 -0
- package/esm2015/cms/modules/runtime/services/runtime-editor.service.js +27 -0
- package/esm2015/cms/modules/runtime/services/runtime.service.js +74 -0
- package/esm2015/cms/modules/runtime/tokens.js +3 -0
- package/esm2015/cms/modules/runtime/types/compilation.types.js +2 -0
- package/esm2015/cms/modules/runtime/types/runtime.actions.js +2 -0
- package/esm2015/cms/plugins/configuration.plugin.js +12 -4
- package/esm2015/cms/plugins/io.plugin.js +3 -3
- package/esm2015/cms/plugins/script.plugin.js +3 -3
- package/esm2015/cms/services/element-context.service.js +3 -3
- package/esm2015/cms/services/index.js +2 -2
- package/esm2015/cms/services/integration.state.js +4 -4
- package/esm2015/cms/services/io-provider.service.js +9 -9
- package/esm2015/cms/services/resources.service.js +50 -0
- package/esm2015/cms/services/templates.service.js +3 -3
- package/esm2015/cms/types/common.types.js +1 -1
- package/esm2015/cms/types/configuration.types.js +1 -1
- package/esm2015/cms/types/index.js +2 -2
- package/esm2015/cms/types/integration.types.js +1 -1
- package/esm2015/cms/utils/elements-resolver.js +18 -8
- package/esm2015/cms/utils/index.js +2 -1
- package/esm2015/cms/utils/path.utils.js +2 -13
- package/esm2015/cms/utils/ui-definition.utils.js +82 -0
- package/esm2015/cms/vendor-map.js +27 -10
- package/esm2015/core/core.module.js +4 -4
- package/esm2015/core/modules/configuration/configuration.module.js +4 -4
- package/esm2015/core/modules/configuration/services/configuration-runtime.service.js +5 -10
- package/esm2015/core/modules/configuration/services/configuration.service.js +38 -34
- package/esm2015/core/modules/configuration/services/runtime-context.service.js +3 -3
- package/esm2015/core/modules/configuration/types/configuration-runtime.types.js +1 -1
- package/esm2015/core/modules/flow-configuration/flow-configuration.module.js +4 -4
- package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +18 -10
- package/esm2015/core/modules/flow-configuration/services/flow-update.service.js +9 -9
- package/esm2015/core/services/context.service.js +7 -4
- package/esm2015/core/services/metric-calculation/metric-calculation.service.js +18 -9
- package/esm2015/core/services/product-images.service.js +3 -3
- package/esm2015/core/services/quote-draft.service.js +7 -7
- package/esm2015/core/types/index.js +1 -2
- package/esm2015/core/types/ui-definition.types.js +2 -2
- package/esm2015/core/utils/index.js +2 -1
- package/esm2015/core/utils/line-item.utils.js +27 -11
- package/esm2015/core/utils/ui-definition.utils.js +9 -0
- package/esm2015/runtime/components/component-preview/component-preview.component.js +4 -4
- package/esm2015/runtime/components/section-renderer/section-renderer.component.js +3 -3
- package/esm2015/runtime/components/ui-runtime/runtime.component.js +3 -3
- package/esm2015/runtime/components/ui-runtime-preview/runtime-preview.component.js +3 -3
- package/esm2015/runtime/execution/components/children-placeholder/children-placeholder.component.js +6 -6
- package/esm2015/runtime/execution/components/context-provider/context-provider.component.js +3 -3
- package/esm2015/runtime/execution/components/execution-section-renderer/execution-section-renderer.component.js +3 -3
- package/esm2015/runtime/execution/components/federated/federated.component.js +3 -3
- package/esm2015/runtime/execution/components/velo-attribute/velo-attribute.component.js +3 -3
- package/esm2015/runtime/execution/components/velo-multiselect/velo-multiselect.component.js +3 -3
- package/esm2015/runtime/execution/components/velo-port-checkbox/velo-port-checkbox.component.js +3 -3
- package/esm2015/runtime/execution/components/velo-port-dropdown/velo-port-dropdown.component.js +3 -3
- package/esm2015/runtime/execution/components/velo-port-radio/velo-port-radio.component.js +3 -3
- package/esm2015/runtime/execution/components/velo-type/velo-type.component.js +3 -3
- package/esm2015/runtime/execution/directives/section-script.directive.js +3 -3
- package/esm2015/runtime/execution/directives/sf-query.directive.js +3 -3
- package/esm2015/runtime/execution/directives/velo-attribute.directive.js +3 -3
- package/esm2015/runtime/execution/directives/velo-port.directive.js +18 -18
- package/esm2015/runtime/execution/directives/vl-approval.directive.js +3 -3
- package/esm2015/runtime/execution/directives/vl-document-attachments.directive.js +3 -3
- package/esm2015/runtime/execution/directives/vl-document-templates.directive.js +3 -3
- package/esm2015/runtime/execution/directives/vl-quote.directive.js +4 -4
- package/esm2015/runtime/execution/directives/vl-ramp.directive.js +3 -3
- package/esm2015/runtime/execution/runtime-execution.module.js +4 -4
- package/esm2015/runtime/runtime.module.js +4 -4
- package/esm2015/runtime/services/cart.service.js +3 -3
- package/esm2015/runtime/services/collapsible-state.service.js +3 -3
- package/esm2015/runtime/services/configuration.service.js +11 -12
- package/esm2015/runtime/services/current-state.service.js +3 -3
- package/esm2015/runtime/services/form-scope.service.js +3 -3
- package/esm2015/runtime/services/product-model-cache.service.js +3 -3
- package/esm2015/runtime/services/runtime-context.service.js +3 -3
- package/esm2015/runtime/services/runtime-form.service.js +3 -3
- package/esm2015/runtime/services/runtime.service.js +4 -4
- package/esm2015/runtime/services/section-helper.service.js +3 -3
- package/esm2015/runtime/services/section-scope.service.js +3 -3
- package/esm2015/runtime/services/section-store.service.js +3 -3
- package/esm2015/runtime/services/section.service.js +6 -6
- package/esm2015/runtime/types/index.js +2 -1
- package/esm2015/runtime/types/quote-states.types.js +2 -0
- package/esm2015/src/components/dialog/dialog.component.js +16 -6
- package/esm2015/src/components/dialog/dialog.module.js +4 -4
- package/esm2015/src/components/dialog/dialog.types.js +1 -1
- package/esm2015/src/components/doc-gen/doc-gen.component.js +3 -3
- package/esm2015/src/components/doc-gen/doc-gen.module.js +4 -4
- package/esm2015/src/components/header/cart-overlay/cart-preview.component.js +3 -3
- package/esm2015/src/components/header/cart-overlay/cart-preview.module.js +4 -4
- package/esm2015/src/components/header/header.component.js +39 -13
- package/esm2015/src/components/header/header.module.js +4 -4
- package/esm2015/src/components/header/metrics/metrics.component.js +79 -67
- package/esm2015/src/components/header/metrics/metrics.definitions.js +1 -8
- package/esm2015/src/components/header/metrics/metrics.module.js +4 -4
- package/esm2015/src/flow-routing.module.js +18 -5
- package/esm2015/src/flow.component.js +3 -3
- package/esm2015/src/flow.module.js +4 -4
- package/esm2015/src/guards/context.guard.js +3 -3
- package/esm2015/src/guards/product-unload.guard.js +5 -5
- package/esm2015/src/guards/root.guard.js +3 -3
- package/esm2015/src/pages/assets/assets.component.js +117 -0
- package/esm2015/src/pages/assets/assets.module.js +20 -0
- package/esm2015/src/pages/catalog/catalog.component.js +6 -6
- package/esm2015/src/pages/catalog/catalog.module.js +4 -4
- package/esm2015/src/pages/debug/debug.component.js +3 -3
- package/esm2015/src/pages/debug/debug.module.js +4 -4
- package/esm2015/src/pages/empty-account/empty-account.component.js +3 -3
- package/esm2015/src/pages/empty-account/empty-account.module.js +4 -4
- package/esm2015/src/pages/legacy-product/legacy-product.component.js +4 -4
- package/esm2015/src/pages/legacy-product/legacy-product.module.js +4 -4
- package/esm2015/src/pages/product/product.component.js +5 -12
- package/esm2015/src/pages/product/product.module.js +4 -4
- package/esm2015/src/pages/record-not-found/record-not-found.component.js +3 -3
- package/esm2015/src/pages/record-not-found/record-not-found.module.js +4 -4
- package/esm2015/src/pages/remote/remote.component.js +5 -8
- package/esm2015/src/pages/remote/remote.module.js +4 -4
- package/esm2015/src/pages/shopping-cart/shopping-cart.component.js +6 -6
- package/esm2015/src/pages/shopping-cart/shopping-cart.module.js +4 -4
- package/esm2015/src/resolvers/flow.resolver.js +3 -3
- package/esm2015/src/resolvers/quote.resolver.js +17 -12
- package/esm2015/src/services/doc-gen.service.js +3 -3
- package/esm2015/src/services/flow-dialog.service.js +5 -4
- package/esm2015/src/services/flow-router.service.js +12 -4
- package/esm2015/src/services/flow.service.js +12 -5
- package/esm2015/src/types/flow-customization.types.js +1 -1
- package/esm2015/src/utils/flow.utils.js +3 -3
- package/fesm2015/veloceapps-sdk-cms.js +1075 -718
- package/fesm2015/veloceapps-sdk-cms.js.map +1 -1
- package/fesm2015/veloceapps-sdk-core.js +573 -529
- package/fesm2015/veloceapps-sdk-core.js.map +1 -1
- package/fesm2015/veloceapps-sdk-runtime.js +145 -146
- package/fesm2015/veloceapps-sdk-runtime.js.map +1 -1
- package/fesm2015/veloceapps-sdk.js +446 -262
- package/fesm2015/veloceapps-sdk.js.map +1 -1
- package/package.json +5 -3
- package/runtime/services/configuration.service.d.ts +2 -1
- package/runtime/services/runtime.service.d.ts +2 -1
- package/runtime/types/index.d.ts +1 -0
- package/src/components/dialog/dialog.types.d.ts +1 -0
- package/src/components/header/header.component.d.ts +10 -3
- package/src/components/header/metrics/metrics.component.d.ts +15 -6
- package/src/components/header/metrics/metrics.definitions.d.ts +0 -3
- package/src/flow-routing.module.d.ts +4 -3
- package/src/pages/assets/assets.component.d.ts +32 -0
- package/src/pages/assets/assets.module.d.ts +10 -0
- package/src/pages/product/product.component.d.ts +0 -1
- package/src/resolvers/quote.resolver.d.ts +1 -0
- package/src/services/flow-router.service.d.ts +2 -0
- package/src/services/flow.service.d.ts +1 -0
- package/src/types/flow-customization.types.d.ts +1 -0
- package/cms/services/dynamic-module.service.d.ts +0 -15
- package/cms/services/launcher.service.d.ts +0 -18
- package/esm2015/cms/services/dynamic-module.service.js +0 -33
- package/esm2015/cms/services/launcher.service.js +0 -57
- package/esm2015/cms/types/compilation.types.js +0 -2
- package/esm2015/core/types/quote-states.types.js +0 -2
- /package/{core → runtime}/types/quote-states.types.d.ts +0 -0
@@ -1,14 +1,14 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
2
|
import { Injectable, NgModule } from '@angular/core';
|
3
|
-
import { UUID, ConfigurationContext,
|
4
|
-
import { BehaviorSubject, zip, noop,
|
5
|
-
import { filter, tap, map, switchMap, skip, take, shareReplay,
|
3
|
+
import { UUID, ConfigurationContext, RuntimeModel, ConfigurationContextMode, SalesforceIdUtils, ConfigurationMode, ConfigurationTranslatorUtils, 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,
|
8
|
+
import { merge, flatten, sortBy, map as map$1, isEqual, omit, cloneDeep, uniq } from 'lodash';
|
9
9
|
import { ToastType, ConfirmationComponent, ConfirmationDialogModule } from '@veloceapps/components';
|
10
|
-
import * as
|
11
|
-
import * as
|
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) => {
|
@@ -36,6 +36,8 @@ var RuntimeStep;
|
|
36
36
|
RuntimeStep["UPDATE"] = "UPDATE";
|
37
37
|
})(RuntimeStep || (RuntimeStep = {}));
|
38
38
|
|
39
|
+
const UI_DEFINITION_VERSION = 3;
|
40
|
+
|
39
41
|
class ContextService {
|
40
42
|
constructor(contextApiService) {
|
41
43
|
this.contextApiService = contextApiService;
|
@@ -44,384 +46,43 @@ class ContextService {
|
|
44
46
|
get isInitialized() {
|
45
47
|
return Boolean(this.context.value);
|
46
48
|
}
|
47
|
-
|
48
|
-
|
49
|
-
throw new Error('Context is not initialized yet!');
|
50
|
-
}
|
51
|
-
return Object.assign({}, this.context.value);
|
52
|
-
}
|
53
|
-
resolve$() {
|
54
|
-
return this.context.pipe(filter((ctx) => Boolean(ctx)));
|
55
|
-
}
|
56
|
-
create(headerId, mode) {
|
57
|
-
return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
|
58
|
-
}
|
59
|
-
update(partialContext) {
|
60
|
-
const originalContext = this.resolve();
|
61
|
-
const updatedContext = Object.assign(Object.assign(Object.assign({}, originalContext), partialContext), { properties: Object.assign(Object.assign({}, originalContext.properties), partialContext.properties) });
|
62
|
-
this.context.next(updatedContext);
|
63
|
-
return updatedContext;
|
64
|
-
}
|
65
|
-
set(context) {
|
66
|
-
const originalContext = this.resolve();
|
67
|
-
const updatedContext = Object.assign(Object.assign({}, originalContext), context);
|
68
|
-
this.context.next(updatedContext);
|
69
|
-
return updatedContext;
|
70
|
-
}
|
71
|
-
delete() {
|
72
|
-
this.context.next(null);
|
73
|
-
}
|
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: [{
|
78
|
-
type: Injectable,
|
79
|
-
args: [{ providedIn: 'root' }]
|
80
|
-
}], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
|
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({});
|
49
|
+
get mode() {
|
50
|
+
return this.resolve().properties.mode;
|
404
51
|
}
|
405
|
-
|
406
|
-
if (this.
|
407
|
-
|
408
|
-
this.fetchProductImage(productId);
|
52
|
+
resolve() {
|
53
|
+
if (!this.context.value) {
|
54
|
+
throw new Error('Context is not initialized yet!');
|
409
55
|
}
|
410
|
-
return
|
56
|
+
return Object.assign({}, this.context.value);
|
411
57
|
}
|
412
|
-
|
413
|
-
this.
|
414
|
-
|
415
|
-
|
416
|
-
|
58
|
+
resolve$() {
|
59
|
+
return this.context.pipe(filter((ctx) => Boolean(ctx)));
|
60
|
+
}
|
61
|
+
create(headerId, mode) {
|
62
|
+
return this.contextApiService.getContext(headerId, mode).pipe(tap(context => this.context.next(merge(new ConfigurationContext(headerId, mode), context))), map(() => this.resolve()));
|
63
|
+
}
|
64
|
+
update(partialContext) {
|
65
|
+
const originalContext = this.resolve();
|
66
|
+
const updatedContext = Object.assign(Object.assign(Object.assign({}, originalContext), partialContext), { properties: Object.assign(Object.assign({}, originalContext.properties), partialContext.properties) });
|
67
|
+
this.context.next(updatedContext);
|
68
|
+
return updatedContext;
|
69
|
+
}
|
70
|
+
set(context) {
|
71
|
+
const originalContext = this.resolve();
|
72
|
+
const updatedContext = Object.assign(Object.assign({}, originalContext), context);
|
73
|
+
this.context.next(updatedContext);
|
74
|
+
return updatedContext;
|
75
|
+
}
|
76
|
+
delete() {
|
77
|
+
this.context.next(null);
|
417
78
|
}
|
418
79
|
}
|
419
|
-
|
420
|
-
|
421
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
80
|
+
ContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, deps: [{ token: i1.ContextApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
81
|
+
ContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, providedIn: 'root' });
|
82
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ContextService, decorators: [{
|
422
83
|
type: Injectable,
|
423
84
|
args: [{ providedIn: 'root' }]
|
424
|
-
}], ctorParameters: function () { return [{ type: i1.
|
85
|
+
}], ctorParameters: function () { return [{ type: i1.ContextApiService }]; } });
|
425
86
|
|
426
87
|
class RuntimeContextService {
|
427
88
|
constructor(configurationApiService) {
|
@@ -462,9 +123,9 @@ class RuntimeContextService {
|
|
462
123
|
return uiDefinition;
|
463
124
|
}
|
464
125
|
}
|
465
|
-
RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
466
|
-
RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.
|
467
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
126
|
+
RuntimeContextService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService, deps: [{ token: i1.ConfigurationApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
127
|
+
RuntimeContextService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService });
|
128
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: RuntimeContextService, decorators: [{
|
468
129
|
type: Injectable
|
469
130
|
}], ctorParameters: function () { return [{ type: i1.ConfigurationApiService }]; } });
|
470
131
|
|
@@ -479,7 +140,6 @@ class ConfigurationRuntimeService {
|
|
479
140
|
reset() {
|
480
141
|
this._isInitialized = false;
|
481
142
|
this._runtimeContext = undefined;
|
482
|
-
this._assets = undefined;
|
483
143
|
this.initializationProps = undefined;
|
484
144
|
this.uiDefinitionProperties = {};
|
485
145
|
}
|
@@ -505,7 +165,6 @@ class ConfigurationRuntimeService {
|
|
505
165
|
}
|
506
166
|
init(props) {
|
507
167
|
this.initializationProps = props;
|
508
|
-
this._assets = props.assets;
|
509
168
|
const context = this.contextService.resolve();
|
510
169
|
return this.runtimeContextService.getRuntimeContext(props.productId, props.offeringId).pipe(tap(runtimeContext => {
|
511
170
|
var _a, _b, _c, _d;
|
@@ -531,9 +190,6 @@ class ConfigurationRuntimeService {
|
|
531
190
|
source[propertyName] = SalesforceIdUtils.generateId18FromId15(value);
|
532
191
|
}
|
533
192
|
}
|
534
|
-
getAsset(lineItem) {
|
535
|
-
return this._assets && this._assets.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
|
536
|
-
}
|
537
193
|
get isInitialized() {
|
538
194
|
return this._isInitialized;
|
539
195
|
}
|
@@ -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.
|
549
|
-
ConfigurationRuntimeService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.
|
550
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
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
|
|
@@ -589,17 +245,33 @@ const removeLineItem = (lineItem, idToRemove) => {
|
|
589
245
|
};
|
590
246
|
const replaceLineItem = (lineItem, replaceTo) => {
|
591
247
|
if (lineItem.id === replaceTo.id) {
|
592
|
-
return Object.assign({}, replaceTo);
|
248
|
+
return Object.assign({}, recalculateCardinalityVariables(lineItem, replaceTo));
|
593
249
|
}
|
594
|
-
return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(li =>
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
250
|
+
return Object.assign(Object.assign({}, lineItem), { lineItems: lineItem.lineItems.map(li => replaceLineItem(li, replaceTo)) });
|
251
|
+
};
|
252
|
+
const calculateCardinalityVariables = (lineItems) => {
|
253
|
+
const cardVars = new Map();
|
254
|
+
lineItems.forEach(li => {
|
255
|
+
var _a;
|
256
|
+
const cardinalityVariableName = `#CV-${li.type}@${li.port}`;
|
257
|
+
cardVars.set(cardinalityVariableName, ((_a = cardVars.get(cardinalityVariableName)) !== null && _a !== void 0 ? _a : 0) + li.qty);
|
258
|
+
});
|
259
|
+
return cardVars;
|
260
|
+
};
|
261
|
+
const recalculateCardinalityVariables = (original, updated) => {
|
262
|
+
const cardinalityVariables = calculateCardinalityVariables(updated.lineItems);
|
263
|
+
const originalCardinalityVariables = calculateCardinalityVariables(original.lineItems);
|
264
|
+
originalCardinalityVariables.forEach((value, key) => {
|
265
|
+
if (cardinalityVariables.get(key) === value) {
|
266
|
+
// no need to update cardinality if no changes
|
267
|
+
cardinalityVariables.delete(key);
|
268
|
+
}
|
269
|
+
else if (!cardinalityVariables.has(key)) {
|
270
|
+
// remove last item from port
|
271
|
+
cardinalityVariables.set(key, 0);
|
272
|
+
}
|
273
|
+
});
|
274
|
+
return Object.assign(Object.assign({}, updated), { attributes: upsertAttributes(updated.attributes, [...cardinalityVariables].map(([name, value]) => ({ name, value }))) });
|
603
275
|
};
|
604
276
|
const mapAttributes = (attributes) => {
|
605
277
|
return attributes.reduce((acc, { name, value }) => (Object.assign(Object.assign({}, acc), { [name]: value })), {});
|
@@ -622,78 +294,289 @@ const patchAttributes = (rootLineItem, id, attrs) => {
|
|
622
294
|
if (!lineItem) {
|
623
295
|
return rootLineItem;
|
624
296
|
}
|
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$
|
297
|
+
const attributes = upsertAttributes(lineItem.attributes, attrs);
|
298
|
+
return replaceLineItem(rootLineItem, Object.assign(Object.assign({}, lineItem), { attributes }));
|
299
|
+
};
|
300
|
+
const getAttributeValue = (attributes, name) => { var _a; return (_a = attributes.find(attr => attr.name === name)) === null || _a === void 0 ? void 0 : _a.value; };
|
301
|
+
const generateLineItem = (port, type, parentId, attributes = [], lineItems = []) => {
|
302
|
+
return {
|
303
|
+
id: UUID.UUID(),
|
304
|
+
port,
|
305
|
+
type,
|
306
|
+
actionCode: 'ADD',
|
307
|
+
cfgStatus: 'New',
|
308
|
+
attributes: attributes.map(({ name, value }) => ({ cfgStatus: 'User', name, value })),
|
309
|
+
lineItems,
|
310
|
+
parentId,
|
311
|
+
qty: 1,
|
312
|
+
};
|
313
|
+
};
|
314
|
+
const getRecommendedPrices = (portDomain, type) => {
|
315
|
+
var _a, _b;
|
316
|
+
const domainType = portDomain.domainTypes.find(({ name }) => name === type);
|
317
|
+
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) => {
|
318
|
+
const [netPrice, listPrice] = acc;
|
319
|
+
return [netPrice + rp.netPrice, listPrice + rp.listPrice];
|
320
|
+
}, [0, 0])) !== null && _b !== void 0 ? _b : [0, 0];
|
321
|
+
return { net, list };
|
322
|
+
};
|
323
|
+
const multiplyLineItems = (lineItem, qty, split) => {
|
324
|
+
if (split) {
|
325
|
+
const unifyIds = (lineItem) => (Object.assign(Object.assign({}, lineItem), { id: UUID.UUID(), lineItems: lineItem.lineItems.map(unifyIds) }));
|
326
|
+
return map$1(new Array(qty), () => unifyIds(lineItem));
|
327
|
+
}
|
328
|
+
else {
|
329
|
+
return [
|
330
|
+
Object.assign(Object.assign({}, lineItem), { qty: qty }),
|
331
|
+
];
|
332
|
+
}
|
333
|
+
};
|
334
|
+
|
335
|
+
var lineItem_utils = /*#__PURE__*/Object.freeze({
|
336
|
+
__proto__: null,
|
337
|
+
findLineItem: findLineItem,
|
338
|
+
findLineItemWithComparator: findLineItemWithComparator,
|
339
|
+
insertLineItem: insertLineItem,
|
340
|
+
removeLineItem: removeLineItem,
|
341
|
+
replaceLineItem: replaceLineItem,
|
342
|
+
calculateCardinalityVariables: calculateCardinalityVariables,
|
343
|
+
recalculateCardinalityVariables: recalculateCardinalityVariables,
|
344
|
+
mapAttributes: mapAttributes,
|
345
|
+
getAttributes: getAttributes,
|
346
|
+
upsertAttributes: upsertAttributes,
|
347
|
+
patchAttributes: patchAttributes,
|
348
|
+
getAttributeValue: getAttributeValue,
|
349
|
+
generateLineItem: generateLineItem,
|
350
|
+
getRecommendedPrices: getRecommendedPrices,
|
351
|
+
multiplyLineItems: multiplyLineItems
|
352
|
+
});
|
353
|
+
|
354
|
+
class LineItemWorker {
|
355
|
+
constructor(src) {
|
356
|
+
this.li = Object.assign({}, src);
|
357
|
+
}
|
358
|
+
insert(parentId, toInsert) {
|
359
|
+
return new LineItemWorker(insertLineItem(this.li, parentId, toInsert));
|
360
|
+
}
|
361
|
+
remove(id) {
|
362
|
+
return new LineItemWorker(removeLineItem(this.li, id));
|
363
|
+
}
|
364
|
+
replace(toReplace) {
|
365
|
+
return new LineItemWorker(replaceLineItem(this.li, toReplace));
|
366
|
+
}
|
367
|
+
patchAttribute(attrs, id) {
|
368
|
+
return new LineItemWorker(patchAttributes(this.li, id !== null && id !== void 0 ? id : this.li.id, attrs));
|
369
|
+
}
|
370
|
+
}
|
371
|
+
|
372
|
+
class QuoteDraftService {
|
373
|
+
constructor(context, quoteApiService, priceApiService) {
|
374
|
+
this.context = context;
|
375
|
+
this.quoteApiService = quoteApiService;
|
376
|
+
this.priceApiService = priceApiService;
|
377
|
+
this.quoteSubj$ = new BehaviorSubject(null);
|
378
|
+
this.resetSubj$ = new BehaviorSubject(true);
|
379
|
+
this.isInitializedSubj$ = new BehaviorSubject(false);
|
380
|
+
this.initialCurrentState = [];
|
381
|
+
this._hasUnsavedChanges = false;
|
382
|
+
this.allPriceLists = [];
|
383
|
+
this.assetPriceLists = [];
|
384
|
+
this.reset$ = this.resetSubj$.asObservable();
|
385
|
+
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));
|
386
|
+
this.isInitializedSubj$
|
387
|
+
.pipe(filter(isInitialized => isInitialized), switchMap(() => this.quoteSubj$.asObservable()), skip(1), tap(quote => this.markAsUpdated(quote)))
|
388
|
+
.subscribe();
|
389
|
+
}
|
390
|
+
get isInitialized() {
|
391
|
+
return this.isInitializedSubj$.getValue();
|
392
|
+
}
|
393
|
+
set isInitialized(value) {
|
394
|
+
if (this.isInitialized !== value) {
|
395
|
+
this.isInitializedSubj$.next(value);
|
396
|
+
}
|
397
|
+
}
|
398
|
+
get hasUnsavedChanges() {
|
399
|
+
return this._hasUnsavedChanges;
|
400
|
+
}
|
401
|
+
set hasUnsavedChanges(value) {
|
402
|
+
var _a, _b;
|
403
|
+
this._hasUnsavedChanges = value;
|
404
|
+
if (!this._hasUnsavedChanges) {
|
405
|
+
this.initialCurrentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
406
|
+
}
|
407
|
+
}
|
408
|
+
get hasProducts$() {
|
409
|
+
return this.quoteSubj$.pipe(map(() => this.hasProducts));
|
410
|
+
}
|
411
|
+
get hasProducts() {
|
412
|
+
const quoteDraft = this.quoteSubj$.value;
|
413
|
+
return Boolean(quoteDraft && quoteDraft.currentState.length > 0);
|
414
|
+
}
|
415
|
+
reset() {
|
416
|
+
this.resetSubj$.next(true);
|
417
|
+
this.quoteSubj$.next(null);
|
418
|
+
this.hasUnsavedChanges = false;
|
419
|
+
}
|
420
|
+
init(quoteId, params) {
|
421
|
+
return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([quote, allPriceLists]) => {
|
422
|
+
this.allPriceLists = allPriceLists;
|
423
|
+
this.quoteSubj$.next(quote);
|
424
|
+
this.context.update(quote.context);
|
425
|
+
this.populateActivePriceLists$();
|
426
|
+
}), map(() => noop()), take(1));
|
427
|
+
}
|
428
|
+
setCurrentLineItemState(lineItems) {
|
429
|
+
const quoteDraft = this.quoteSubj$.value;
|
430
|
+
if (!quoteDraft) {
|
431
|
+
return;
|
432
|
+
}
|
433
|
+
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
|
434
|
+
}
|
435
|
+
updateQuoteDraft(update) {
|
436
|
+
const quoteDraft = this.quoteSubj$.value;
|
437
|
+
if (!quoteDraft) {
|
438
|
+
return;
|
439
|
+
}
|
440
|
+
if (update.context) {
|
441
|
+
this.context.set(update.context);
|
442
|
+
}
|
443
|
+
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
|
444
|
+
}
|
445
|
+
updateByPriceSummary(priceSummary) {
|
446
|
+
const quoteDraft = this.quoteSubj$.value;
|
447
|
+
if (!quoteDraft) {
|
448
|
+
return;
|
449
|
+
}
|
450
|
+
const updatedCurrentState = this.currentState.map(lineItem => {
|
451
|
+
const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
|
452
|
+
return updated !== null && updated !== void 0 ? updated : lineItem;
|
453
|
+
});
|
454
|
+
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
|
455
|
+
}
|
456
|
+
get quoteDraft$() {
|
457
|
+
return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
|
458
|
+
}
|
459
|
+
get quoteDraft() {
|
460
|
+
const quote = this.quoteSubj$.value;
|
461
|
+
if (!quote) {
|
462
|
+
return null;
|
463
|
+
}
|
464
|
+
return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
|
465
|
+
}
|
466
|
+
get quoteDraftForActivePriceList() {
|
467
|
+
const quoteDraft = this.quoteDraft;
|
468
|
+
if (!quoteDraft) {
|
469
|
+
return null;
|
470
|
+
}
|
471
|
+
return Object.assign(Object.assign({}, quoteDraft), { initialState: this.filterByActivePriceList(quoteDraft.initialState), currentState: this.filterByActivePriceList(quoteDraft.currentState) });
|
472
|
+
}
|
473
|
+
get currentState$() {
|
474
|
+
return this.quoteDraft$.pipe(map(quote => quote.currentState));
|
475
|
+
}
|
476
|
+
get currentState() {
|
477
|
+
var _a, _b;
|
478
|
+
return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
479
|
+
}
|
480
|
+
/**
|
481
|
+
* Stream of activeCurrentState
|
482
|
+
*/
|
483
|
+
get activeCurrentState$() {
|
484
|
+
return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
|
485
|
+
}
|
486
|
+
/**
|
487
|
+
* activeCurrentState is currentState passed through additional filters
|
488
|
+
*/
|
489
|
+
get activeCurrentState() {
|
490
|
+
var _a, _b;
|
491
|
+
let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
492
|
+
currentState = this.filterByActivePriceList(currentState);
|
493
|
+
return currentState;
|
494
|
+
}
|
495
|
+
/**
|
496
|
+
* Stream of activeInitialState
|
497
|
+
*/
|
498
|
+
get activeInitialState$() {
|
499
|
+
return this.quoteDraft$.pipe(map(() => this.activeInitialState));
|
500
|
+
}
|
501
|
+
/**
|
502
|
+
* activeInitialState is initialState passed through additional filters
|
503
|
+
*/
|
504
|
+
get activeInitialState() {
|
505
|
+
var _a, _b;
|
506
|
+
const ctx = this.context.resolve();
|
507
|
+
let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
|
508
|
+
if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
|
509
|
+
initialState = this.filterByActivePriceList(initialState);
|
510
|
+
}
|
511
|
+
return initialState;
|
512
|
+
}
|
513
|
+
get isStandalone() {
|
514
|
+
return this.context.resolve().properties.standalone === 'true';
|
515
|
+
}
|
516
|
+
get isStandalone$() {
|
517
|
+
return this.context.resolve$().pipe(map(() => this.isStandalone));
|
655
518
|
}
|
656
|
-
|
657
|
-
return
|
658
|
-
Object.assign(Object.assign({}, lineItem), { qty: qty }),
|
659
|
-
];
|
519
|
+
getInitialCurrentState() {
|
520
|
+
return this.initialCurrentState;
|
660
521
|
}
|
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);
|
522
|
+
isEditMode$() {
|
523
|
+
return this.context.resolve$().pipe(map(() => this.isEditMode()));
|
683
524
|
}
|
684
|
-
|
685
|
-
|
525
|
+
isEditMode() {
|
526
|
+
const context = this.context.resolve();
|
527
|
+
if (context.mode === ConfigurationContextMode.ACCOUNT) {
|
528
|
+
return true;
|
529
|
+
}
|
530
|
+
if (context.mode === ConfigurationContextMode.QUOTE) {
|
531
|
+
return context.properties.Status === 'Draft';
|
532
|
+
}
|
533
|
+
return false;
|
686
534
|
}
|
687
|
-
|
688
|
-
|
535
|
+
updateActivePriceList(priceListId) {
|
536
|
+
this.context.update({ properties: { PriceListId: priceListId } });
|
689
537
|
}
|
690
|
-
|
691
|
-
|
538
|
+
populateActivePriceLists$() {
|
539
|
+
const ctx = this.context.resolve();
|
540
|
+
const quoteDraft = this.quoteDraft;
|
541
|
+
if (!quoteDraft) {
|
542
|
+
return;
|
543
|
+
}
|
544
|
+
// In ACCOUNT mode populate price lists from related assets
|
545
|
+
if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
|
546
|
+
// Populate list of price lists
|
547
|
+
this.assetPriceLists = quoteDraft.currentState
|
548
|
+
.map(({ priceListId }) => priceListId)
|
549
|
+
.reduce((trunk, priceListId) => {
|
550
|
+
var _a, _b;
|
551
|
+
if (!priceListId || trunk.some(item => item.id === priceListId)) {
|
552
|
+
return trunk;
|
553
|
+
}
|
554
|
+
return [
|
555
|
+
...trunk,
|
556
|
+
{ 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 : '' },
|
557
|
+
];
|
558
|
+
}, []);
|
559
|
+
}
|
692
560
|
}
|
693
|
-
|
694
|
-
|
561
|
+
filterByActivePriceList(lineItems) {
|
562
|
+
const ctx = this.context.resolve();
|
563
|
+
return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
|
564
|
+
}
|
565
|
+
markAsUpdated(quote) {
|
566
|
+
if ((quote === null || quote === void 0 ? void 0 : quote.context.properties.mode) === ConfigurationContextMode.ACCOUNT) {
|
567
|
+
this.hasUnsavedChanges = !!quote && !quote.currentState.every(li => li.actionCode === 'EXIST');
|
568
|
+
}
|
569
|
+
else {
|
570
|
+
this.hasUnsavedChanges = !isEqual(this.initialCurrentState, quote === null || quote === void 0 ? void 0 : quote.currentState);
|
571
|
+
}
|
695
572
|
}
|
696
573
|
}
|
574
|
+
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 });
|
575
|
+
QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
|
576
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: QuoteDraftService, decorators: [{
|
577
|
+
type: Injectable,
|
578
|
+
args: [{ providedIn: 'root' }]
|
579
|
+
}], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
|
697
580
|
|
698
581
|
class ConfigurationService {
|
699
582
|
constructor(quoteDraftService, runtimeService, contextService, configurationApiService, messageService, dialogService) {
|
@@ -704,7 +587,6 @@ class ConfigurationService {
|
|
704
587
|
this.messageService = messageService;
|
705
588
|
this.dialogService = dialogService;
|
706
589
|
this.mode = ConfigurationMode.SEARCH;
|
707
|
-
this.states = {};
|
708
590
|
this.lineItem = new BehaviorSubject(undefined);
|
709
591
|
this.charges = new BehaviorSubject({});
|
710
592
|
this.pricePlans = new BehaviorSubject({});
|
@@ -713,7 +595,7 @@ class ConfigurationService {
|
|
713
595
|
reset() {
|
714
596
|
this.hasUnsavedChanges = false;
|
715
597
|
this.runtimeService.reset();
|
716
|
-
this.
|
598
|
+
this.configurableRamp = undefined;
|
717
599
|
this.lineItem.next(undefined);
|
718
600
|
this.charges.next({});
|
719
601
|
this.pricePlans.next({});
|
@@ -722,11 +604,8 @@ class ConfigurationService {
|
|
722
604
|
if (!this.lineItem.value) {
|
723
605
|
return throwError(() => new Error(`Source LineItem not found`));
|
724
606
|
}
|
725
|
-
this.
|
726
|
-
this.
|
727
|
-
? this.runtimeService.getAsset(this.states.configurableRamp)
|
728
|
-
: undefined;
|
729
|
-
return this.configure().pipe(catchError$1(error => {
|
607
|
+
this.configurableRamp = new LineItemWorker(this.lineItem.value).replace(lineItem).li;
|
608
|
+
return this.configure().pipe(catchError(error => {
|
730
609
|
console.error(error);
|
731
610
|
if (!this.runtimeService.uiDefinitionProperties.suppressToastMessages) {
|
732
611
|
this.messageService.add({ severity: 'error', summary: error });
|
@@ -743,8 +622,8 @@ class ConfigurationService {
|
|
743
622
|
patch(lineItem) {
|
744
623
|
this.patch$(lineItem).subscribe();
|
745
624
|
}
|
746
|
-
|
747
|
-
this.
|
625
|
+
setConfigurableRamp(lineItem) {
|
626
|
+
this.configurableRamp = lineItem;
|
748
627
|
}
|
749
628
|
get() {
|
750
629
|
return this.lineItem.asObservable().pipe(shareReplay$1());
|
@@ -785,7 +664,7 @@ class ConfigurationService {
|
|
785
664
|
}
|
786
665
|
const uiDefinitionProperties = Object.assign(Object.assign({}, ((_b = (_a = runtimeContext.uiDefinition) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {})), ((_c = this.runtimeService.uiDefinitionProperties) !== null && _c !== void 0 ? _c : {}));
|
787
666
|
const qty = (_d = this.runtimeService.initializationProps) === null || _d === void 0 ? void 0 : _d.defaultQty;
|
788
|
-
const lineItem = (_e = this.
|
667
|
+
const lineItem = (_e = this.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
|
789
668
|
const configurationRequest = this.createRequest(lineItem);
|
790
669
|
const mainPricingEnabled = (_f = runtimeContext.properties) === null || _f === void 0 ? void 0 : _f.PricingEnabled;
|
791
670
|
const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
|
@@ -800,29 +679,35 @@ class ConfigurationService {
|
|
800
679
|
}
|
801
680
|
return lineItem;
|
802
681
|
}))
|
803
|
-
.pipe(tap(lineItem => lineItem && this.lineItem.next(lineItem)), catchError
|
682
|
+
.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
683
|
}
|
805
684
|
configureExternal$(productId, qty) {
|
806
|
-
this.
|
807
|
-
currentState: this.quoteDraftService.currentState,
|
808
|
-
});
|
809
|
-
return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError$1(error => {
|
685
|
+
return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError(error => {
|
810
686
|
this.messageService.add({ severity: ToastType.error, summary: error });
|
811
687
|
throw error;
|
812
688
|
}), finalize(() => this.reset()));
|
813
689
|
}
|
814
690
|
createRequest(lineItem) {
|
815
|
-
|
691
|
+
var _a;
|
692
|
+
let request = {
|
816
693
|
lineItem,
|
817
694
|
mode: this.mode,
|
818
695
|
step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
|
819
696
|
attributeDomainMode: 'ALL',
|
820
697
|
context: this.contextService.resolve(),
|
821
|
-
lineItems: this.
|
822
|
-
asset: this.
|
698
|
+
lineItems: ((_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) || [],
|
699
|
+
asset: this.getAsset(),
|
823
700
|
};
|
701
|
+
request = ConfigurationTranslatorUtils.lightenConfigurationRequest(request);
|
702
|
+
return request;
|
824
703
|
}
|
825
704
|
showInactiveProductsConfirmation() {
|
705
|
+
const confirmationConfig = {
|
706
|
+
title: ' ',
|
707
|
+
description: 'This quote contains inactive products. Do you want to remove them?',
|
708
|
+
primaryButtonLabel: 'Remove products',
|
709
|
+
secondaryButtonLabel: 'Back to Quote',
|
710
|
+
};
|
826
711
|
this.dialogService
|
827
712
|
.open(ConfirmationComponent, {
|
828
713
|
dismissableMask: false,
|
@@ -831,14 +716,7 @@ class ConfigurationService {
|
|
831
716
|
showHeader: true,
|
832
717
|
header: `Inactive Products in Quote`,
|
833
718
|
width: '440px',
|
834
|
-
data: {
|
835
|
-
confirmationConfig: {
|
836
|
-
title: ' ',
|
837
|
-
description: 'This quote contains inactive products. Do you want to remove them?',
|
838
|
-
submitBtn: 'Remove products',
|
839
|
-
cancelBtn: 'Back to Quote',
|
840
|
-
},
|
841
|
-
},
|
719
|
+
data: { confirmationConfig },
|
842
720
|
})
|
843
721
|
.onClose.subscribe(result => {
|
844
722
|
if (!result) {
|
@@ -847,15 +725,31 @@ class ConfigurationService {
|
|
847
725
|
}
|
848
726
|
});
|
849
727
|
}
|
728
|
+
getAsset() {
|
729
|
+
var _a;
|
730
|
+
const lineItem = this.configurableRamp;
|
731
|
+
if (!lineItem) {
|
732
|
+
return;
|
733
|
+
}
|
734
|
+
return (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState.find(a => a.id === lineItem.openOrderLineItemId || a.id === lineItem.assetId);
|
735
|
+
}
|
850
736
|
}
|
851
|
-
ConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
852
|
-
ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.
|
853
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
737
|
+
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 });
|
738
|
+
ConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService });
|
739
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationService, decorators: [{
|
854
740
|
type: Injectable
|
855
|
-
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type:
|
741
|
+
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: ConfigurationRuntimeService }, { type: ContextService }, { type: i1.ConfigurationApiService }, { type: i5.MessageService }, { type: i6.DialogService }]; } });
|
742
|
+
|
743
|
+
function extractMetadata(uiDefinition) {
|
744
|
+
return omit(uiDefinition, [
|
745
|
+
'children',
|
746
|
+
'pages',
|
747
|
+
'components',
|
748
|
+
]);
|
749
|
+
}
|
856
750
|
|
857
751
|
class FlowUpdateService {
|
858
|
-
update(rootLineItems, updates) {
|
752
|
+
update(rootLineItems, updates, charges) {
|
859
753
|
let remainingUpdates = [...updates];
|
860
754
|
let currentLevel = rootLineItems;
|
861
755
|
while (currentLevel.length && remainingUpdates.length) {
|
@@ -865,7 +759,7 @@ class FlowUpdateService {
|
|
865
759
|
let updated = false;
|
866
760
|
switch (update.dataType) {
|
867
761
|
case 'LINEITEM':
|
868
|
-
updated = this.applyLineItemUpdate(li, update);
|
762
|
+
updated = this.applyLineItemUpdate(li, update, charges);
|
869
763
|
break;
|
870
764
|
case 'CHARGE':
|
871
765
|
updated = this.applyChargeUpdate(li, update);
|
@@ -903,7 +797,7 @@ class FlowUpdateService {
|
|
903
797
|
const filtered = lineItems.filter(lineItem => !idsToRemove.includes(lineItem.id));
|
904
798
|
return filtered.map(lineItem => new LineItemWorker(lineItem).remove(id).li);
|
905
799
|
}
|
906
|
-
applyLineItemUpdate(lineItem, update) {
|
800
|
+
applyLineItemUpdate(lineItem, update, charges) {
|
907
801
|
if (lineItem.id !== update.id) {
|
908
802
|
return false;
|
909
803
|
}
|
@@ -919,7 +813,7 @@ class FlowUpdateService {
|
|
919
813
|
break;
|
920
814
|
case 'PRICE_ADJUSTMENT':
|
921
815
|
{
|
922
|
-
const
|
816
|
+
const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
|
923
817
|
if (charge) {
|
924
818
|
charge.priceAdjustment = update.newValue;
|
925
819
|
}
|
@@ -927,7 +821,7 @@ class FlowUpdateService {
|
|
927
821
|
break;
|
928
822
|
case 'LIST_PRICE_ADJUSTMENT':
|
929
823
|
{
|
930
|
-
const
|
824
|
+
const charge = lineItem.chargeItems.find(charge => { var _a; return (_a = (charges || {})[charge.chargeId]) === null || _a === void 0 ? void 0 : _a.main; });
|
931
825
|
if (charge) {
|
932
826
|
charge.listPriceAdjustment = update.newValue;
|
933
827
|
}
|
@@ -971,9 +865,9 @@ class FlowUpdateService {
|
|
971
865
|
return true;
|
972
866
|
}
|
973
867
|
}
|
974
|
-
FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
975
|
-
FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.
|
976
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
868
|
+
FlowUpdateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
869
|
+
FlowUpdateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService });
|
870
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowUpdateService, decorators: [{
|
977
871
|
type: Injectable
|
978
872
|
}] });
|
979
873
|
|
@@ -993,7 +887,7 @@ class FlowConfigurationService {
|
|
993
887
|
.slice()
|
994
888
|
.sort((a, b) => initialStateIds.indexOf(a.integrationId) - initialStateIds.indexOf(b.integrationId));
|
995
889
|
this.quoteDraftService.updateQuoteDraft(result);
|
996
|
-
}), map$
|
890
|
+
}), map$2(noop));
|
997
891
|
}
|
998
892
|
calculate(quoteDraft) {
|
999
893
|
this.calculate$(quoteDraft).subscribe();
|
@@ -1003,11 +897,11 @@ class FlowConfigurationService {
|
|
1003
897
|
if (!quoteDraft) {
|
1004
898
|
return of(null);
|
1005
899
|
}
|
1006
|
-
return of([]).pipe(map$
|
900
|
+
return of([]).pipe(map$2(() => {
|
1007
901
|
const updatedState = cloneDeep(quoteDraft.currentState);
|
1008
|
-
this.updateService.update(updatedState, updates);
|
902
|
+
this.updateService.update(updatedState, updates, quoteDraft.charges);
|
1009
903
|
return updatedState;
|
1010
|
-
}), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$
|
904
|
+
}), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
|
1011
905
|
}
|
1012
906
|
update(updates) {
|
1013
907
|
this.update$(updates).subscribe();
|
@@ -1026,7 +920,7 @@ class FlowConfigurationService {
|
|
1026
920
|
updatedState.splice(currentLineItemIndex, 1, initialLineItem);
|
1027
921
|
return of([]).pipe(tap$1(() => {
|
1028
922
|
this.quoteDraftService.setCurrentLineItemState(updatedState);
|
1029
|
-
}), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$
|
923
|
+
}), switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
|
1030
924
|
}
|
1031
925
|
revert(lineItemId) {
|
1032
926
|
this.revert$(lineItemId).subscribe();
|
@@ -1037,7 +931,7 @@ class FlowConfigurationService {
|
|
1037
931
|
if (!quoteDraft) {
|
1038
932
|
return of(null);
|
1039
933
|
}
|
1040
|
-
return of([]).pipe(map$
|
934
|
+
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
935
|
}
|
1042
936
|
delete(ids) {
|
1043
937
|
this.delete$(ids).subscribe();
|
@@ -1048,33 +942,36 @@ class FlowConfigurationService {
|
|
1048
942
|
return of(null);
|
1049
943
|
}
|
1050
944
|
const updatedState = [...quoteDraft.currentState, term];
|
1051
|
-
return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$
|
945
|
+
return of([]).pipe(switchMap$1(() => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
|
1052
946
|
}
|
1053
947
|
addToCart$(productId, qty) {
|
1054
948
|
const quoteDraft = this.quoteDraftService.quoteDraft;
|
1055
949
|
if (!quoteDraft) {
|
1056
950
|
return of(null);
|
1057
951
|
}
|
1058
|
-
return this.configurationService.configureExternal$(productId, qty).pipe(map$
|
952
|
+
return this.configurationService.configureExternal$(productId, qty).pipe(map$2(lineItem => {
|
1059
953
|
var _a, _b;
|
1060
954
|
const model = this.configurationService.getRuntimeModel();
|
1061
955
|
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
956
|
const lineItems = multiplyLineItems(lineItem, qty !== null && qty !== void 0 ? qty : 1, split);
|
1063
957
|
return [...quoteDraft.currentState, ...lineItems];
|
1064
|
-
}), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$
|
958
|
+
}), switchMap$1(updatedState => this.calculate$(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedState }))), map$2(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack());
|
1065
959
|
}
|
1066
960
|
get() {
|
1067
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
961
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$2(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
|
1068
962
|
}
|
1069
963
|
getSnapshot() {
|
1070
964
|
var _a, _b;
|
1071
965
|
return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
|
1072
966
|
}
|
1073
967
|
get charges$() {
|
1074
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
968
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$2(({ charges }) => charges));
|
1075
969
|
}
|
1076
970
|
get pricePlans$() {
|
1077
|
-
return this.quoteDraftService.quoteDraft$.pipe(map$
|
971
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$2(({ pricePlans }) => pricePlans));
|
972
|
+
}
|
973
|
+
get activeMetrics$() {
|
974
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$2(({ activeMetrics }) => activeMetrics));
|
1078
975
|
}
|
1079
976
|
get chargesSnapshot() {
|
1080
977
|
var _a, _b;
|
@@ -1084,6 +981,10 @@ class FlowConfigurationService {
|
|
1084
981
|
var _a, _b;
|
1085
982
|
return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.pricePlans) !== null && _b !== void 0 ? _b : {};
|
1086
983
|
}
|
984
|
+
get activeMetricsSnapshot() {
|
985
|
+
var _a, _b;
|
986
|
+
return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.activeMetrics) !== null && _b !== void 0 ? _b : [];
|
987
|
+
}
|
1087
988
|
get contextSnapshot() {
|
1088
989
|
return this.contextService.resolve();
|
1089
990
|
}
|
@@ -1092,7 +993,7 @@ class FlowConfigurationService {
|
|
1092
993
|
}
|
1093
994
|
handleErrorAndBounceBack() {
|
1094
995
|
return (source$) => {
|
1095
|
-
return source$.pipe(catchError(error => {
|
996
|
+
return source$.pipe(catchError$1(error => {
|
1096
997
|
console.error(error);
|
1097
998
|
// bounce back if configuration call has failed
|
1098
999
|
const quoteDraft = this.quoteDraftService.quoteDraft;
|
@@ -1104,18 +1005,18 @@ class FlowConfigurationService {
|
|
1104
1005
|
};
|
1105
1006
|
}
|
1106
1007
|
}
|
1107
|
-
FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
1108
|
-
FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.
|
1109
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
1008
|
+
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 });
|
1009
|
+
FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService });
|
1010
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationService, decorators: [{
|
1110
1011
|
type: Injectable
|
1111
1012
|
}], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
|
1112
1013
|
|
1113
1014
|
class FlowConfigurationModule {
|
1114
1015
|
}
|
1115
|
-
FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
1116
|
-
FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.
|
1117
|
-
FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.
|
1118
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
1016
|
+
FlowConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1017
|
+
FlowConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule });
|
1018
|
+
FlowConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, providers: [FlowConfigurationService, FlowUpdateService, PriceApiService], imports: [[]] });
|
1019
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: FlowConfigurationModule, decorators: [{
|
1119
1020
|
type: NgModule,
|
1120
1021
|
args: [{
|
1121
1022
|
imports: [],
|
@@ -1125,9 +1026,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
1125
1026
|
|
1126
1027
|
class ConfigurationModule {
|
1127
1028
|
}
|
1128
|
-
ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
1129
|
-
ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.
|
1130
|
-
ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.
|
1029
|
+
ConfigurationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1030
|
+
ConfigurationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, imports: [ConfirmationDialogModule] });
|
1031
|
+
ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, providers: [
|
1131
1032
|
ContextApiService,
|
1132
1033
|
ProductModelApiService,
|
1133
1034
|
ConfigurationApiService,
|
@@ -1135,7 +1036,7 @@ ConfigurationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", ver
|
|
1135
1036
|
RuntimeContextService,
|
1136
1037
|
ConfigurationService,
|
1137
1038
|
], imports: [[ConfirmationDialogModule]] });
|
1138
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
1039
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ConfigurationModule, decorators: [{
|
1139
1040
|
type: NgModule,
|
1140
1041
|
args: [{
|
1141
1042
|
imports: [ConfirmationDialogModule],
|
@@ -1150,12 +1051,155 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
1150
1051
|
}]
|
1151
1052
|
}] });
|
1152
1053
|
|
1054
|
+
function calculateMetricByMethod(lineItems, metric, method) {
|
1055
|
+
const items = getLineItemsByMethod(lineItems, method);
|
1056
|
+
return items.reduce((acc, li) => {
|
1057
|
+
let value = li.reduce((accProduct, item) => accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0), 0);
|
1058
|
+
if (method === 'avg' && li.length > 0) {
|
1059
|
+
value /= li.length;
|
1060
|
+
}
|
1061
|
+
return acc + value;
|
1062
|
+
}, 0);
|
1063
|
+
}
|
1064
|
+
function getLineItemsByMethod(lineItems, method) {
|
1065
|
+
switch (method) {
|
1066
|
+
case 'first': {
|
1067
|
+
return lineItems.filter(li => !li.rampInstanceId).map(item => [item]);
|
1068
|
+
}
|
1069
|
+
case 'last': {
|
1070
|
+
const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
|
1071
|
+
const products = rootTermItems.map(lineItem => [
|
1072
|
+
lineItem,
|
1073
|
+
...lineItems.filter(li => li.rampInstanceId === lineItem.id),
|
1074
|
+
]);
|
1075
|
+
return products
|
1076
|
+
.map(items => [...items].sort((a, b) => getDateValue(a.endDate || '') - getDateValue(b.endDate || '')).pop())
|
1077
|
+
.filter((li) => Boolean(li))
|
1078
|
+
.map(item => [item]);
|
1079
|
+
}
|
1080
|
+
case 'avg': {
|
1081
|
+
const rootTermItems = lineItems.filter(li => !li.rampInstanceId);
|
1082
|
+
return rootTermItems.map(lineItem => [lineItem, ...lineItems.filter(li => li.rampInstanceId === lineItem.id)]);
|
1083
|
+
}
|
1084
|
+
case 'sum': {
|
1085
|
+
return lineItems.map(item => [item]);
|
1086
|
+
}
|
1087
|
+
default: {
|
1088
|
+
return lineItems.map(item => [item]);
|
1089
|
+
}
|
1090
|
+
}
|
1091
|
+
}
|
1092
|
+
function getDateValue(date) {
|
1093
|
+
return date ? new Date(date).getTime() : 0;
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
class MetricsCalculationService {
|
1097
|
+
constructor(quoteDraftService, flowConfiguration, settingsService) {
|
1098
|
+
this.quoteDraftService = quoteDraftService;
|
1099
|
+
this.flowConfiguration = flowConfiguration;
|
1100
|
+
this.settingsService = settingsService;
|
1101
|
+
this.metricsUpdated$ = new Subject();
|
1102
|
+
this.quoteMetricsSettings = {};
|
1103
|
+
this.metricsCalculationMethodMap = {};
|
1104
|
+
this.metricsData = {};
|
1105
|
+
this.activeMetricRules = [];
|
1106
|
+
this.activeMetricRules = this.flowConfiguration.activeMetricsSnapshot.filter(metricRule => metricRule.metrics.some(metric => !!metric.totalName));
|
1107
|
+
combineLatest([
|
1108
|
+
this.quoteDraftService.currentState$,
|
1109
|
+
this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(take$1(1)),
|
1110
|
+
]).subscribe(([lineItems, setting]) => {
|
1111
|
+
let settingsData = {};
|
1112
|
+
try {
|
1113
|
+
settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
|
1114
|
+
}
|
1115
|
+
catch (error) {
|
1116
|
+
settingsData = {};
|
1117
|
+
}
|
1118
|
+
this.quoteMetricsSettings = settingsData;
|
1119
|
+
this.updateMetrics(lineItems);
|
1120
|
+
});
|
1121
|
+
}
|
1122
|
+
get onMetricsUpdate$() {
|
1123
|
+
return this.metricsUpdated$.asObservable();
|
1124
|
+
}
|
1125
|
+
getMetricValue(metric) {
|
1126
|
+
return this.metricsData[metric] || 0;
|
1127
|
+
}
|
1128
|
+
updateMetrics(lineItems) {
|
1129
|
+
const metricKeys = this.collectMetricKeys(lineItems).filter(key => !key.includes('Effective_'));
|
1130
|
+
this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
|
1131
|
+
this.metricsData = metricKeys.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: this.calculateMetric(lineItems, key) })), {});
|
1132
|
+
this.metricsUpdated$.next();
|
1133
|
+
}
|
1134
|
+
calculateMetric(lineItems, metric) {
|
1135
|
+
return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
|
1136
|
+
}
|
1137
|
+
buildMetricsCalculationMethods(metricKeys, initial) {
|
1138
|
+
return metricKeys.reduce((acc, name) => {
|
1139
|
+
var _a, _b;
|
1140
|
+
if (acc[name]) {
|
1141
|
+
return acc;
|
1142
|
+
}
|
1143
|
+
acc = Object.assign(Object.assign({}, acc), { [name]: 'sum' });
|
1144
|
+
const metricRule = this.getMetricRuleByTotalMetricName(name);
|
1145
|
+
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;
|
1146
|
+
if (this.quoteMetricsSettings[settingKey]) {
|
1147
|
+
acc = Object.assign(Object.assign({}, acc), { [name]: this.quoteMetricsSettings[settingKey] });
|
1148
|
+
}
|
1149
|
+
return acc;
|
1150
|
+
}, initial);
|
1151
|
+
}
|
1152
|
+
collectMetricKeys(lineItems) {
|
1153
|
+
const keys = [];
|
1154
|
+
lineItems.forEach(lineItem => {
|
1155
|
+
keys.push(...Object.keys(lineItem.totalMetrics || {}));
|
1156
|
+
keys.push(...this.collectMetricKeys(lineItem.lineItems));
|
1157
|
+
});
|
1158
|
+
return uniq(keys);
|
1159
|
+
}
|
1160
|
+
getMetricRuleByTotalMetricName(name) {
|
1161
|
+
return this.activeMetricRules.find(metricRule => metricRule.metrics.find(metric => metric.totalName === name));
|
1162
|
+
}
|
1163
|
+
}
|
1164
|
+
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 });
|
1165
|
+
MetricsCalculationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, providedIn: 'root' });
|
1166
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MetricsCalculationService, decorators: [{
|
1167
|
+
type: Injectable,
|
1168
|
+
args: [{ providedIn: 'root' }]
|
1169
|
+
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: FlowConfigurationService }, { type: i1.ConfigurationSettingsApiService }]; } });
|
1170
|
+
|
1171
|
+
class ProductImagesService {
|
1172
|
+
constructor(productApiService) {
|
1173
|
+
this.productApiService = productApiService;
|
1174
|
+
this.imagesMap$ = new BehaviorSubject({});
|
1175
|
+
}
|
1176
|
+
getImageUrl$(productId) {
|
1177
|
+
if (this.imagesMap$.value[productId] == null) {
|
1178
|
+
this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), { [productId]: '' }));
|
1179
|
+
this.fetchProductImage(productId);
|
1180
|
+
}
|
1181
|
+
return this.imagesMap$.pipe(map$2(imagesMap => imagesMap[productId]), distinctUntilChanged());
|
1182
|
+
}
|
1183
|
+
fetchProductImage(productId) {
|
1184
|
+
this.productApiService
|
1185
|
+
.fetchImage$(productId)
|
1186
|
+
.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 }))))
|
1187
|
+
.subscribe();
|
1188
|
+
}
|
1189
|
+
}
|
1190
|
+
ProductImagesService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, deps: [{ token: i1.ProductApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
1191
|
+
ProductImagesService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, providedIn: 'root' });
|
1192
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: ProductImagesService, decorators: [{
|
1193
|
+
type: Injectable,
|
1194
|
+
args: [{ providedIn: 'root' }]
|
1195
|
+
}], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
|
1196
|
+
|
1153
1197
|
class SdkCoreModule {
|
1154
1198
|
}
|
1155
|
-
SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.
|
1156
|
-
SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.
|
1157
|
-
SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.
|
1158
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.
|
1199
|
+
SdkCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1200
|
+
SdkCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
|
1201
|
+
SdkCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
|
1202
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SdkCoreModule, decorators: [{
|
1159
1203
|
type: NgModule,
|
1160
1204
|
args: [{
|
1161
1205
|
imports: [ConfigurationModule, FlowConfigurationModule],
|
@@ -1167,5 +1211,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
1167
1211
|
* Generated bundle index. Do not edit.
|
1168
1212
|
*/
|
1169
1213
|
|
1170
|
-
export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, removeLineItem, replaceLineItem, upsertAttributes };
|
1214
|
+
export { ConfigurationRuntimeService, ConfigurationService, ContextService, FlowConfigurationModule, FlowConfigurationService, FlowUpdateService, LineItemWorker, MetricsCalculationService, ProductImagesService, QuoteDraftService, RuntimeMode, RuntimeOperation, RuntimeStep, SdkCoreModule, UI_DEFINITION_VERSION, calculateCardinalityVariables, extractMetadata, findLineItem, findLineItemWithComparator, generateLineItem, getAttributeValue, getAttributes, getDefaultLineItem, getRecommendedPrices, insertLineItem, lineItem_utils as lineItemUtils, mapAttributes, multiplyLineItems, patchAttributes, recalculateCardinalityVariables, removeLineItem, replaceLineItem, upsertAttributes };
|
1171
1215
|
//# sourceMappingURL=veloceapps-sdk-core.js.map
|