@veloceapps/sdk 3.1.18 → 3.1.20
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/bundles/veloce-sdk-core.umd.js +193 -71
- package/bundles/veloce-sdk-core.umd.js.map +1 -1
- package/bundles/veloce-sdk-runtime.umd.js +5 -6
- package/bundles/veloce-sdk-runtime.umd.js.map +1 -1
- package/bundles/veloce-sdk.umd.js +52 -38
- package/bundles/veloce-sdk.umd.js.map +1 -1
- package/core/modules/flow-configuration/services/flow-configuration.service.d.ts +11 -17
- package/core/services/quote-draft.service.d.ts +31 -7
- package/esm2015/core/modules/configuration/services/configuration.service.js +6 -7
- package/esm2015/core/modules/flow-configuration/services/flow-configuration.service.js +43 -49
- package/esm2015/core/services/quote-draft.service.js +118 -21
- package/esm2015/runtime/components/ui-runtime/runtime.component.js +2 -2
- package/esm2015/runtime/execution/directives/section-script.directive.js +2 -2
- package/esm2015/runtime/services/cart.service.js +2 -3
- package/esm2015/runtime/services/section.service.js +1 -1
- package/esm2015/src/components/header/header.component.js +23 -19
- package/esm2015/src/components/header/header.types.js +1 -1
- package/esm2015/src/pages/legacy-product/legacy-product.component.js +4 -4
- package/esm2015/src/pages/product/product.component.js +8 -5
- package/esm2015/src/resolvers/flow.resolver.js +8 -4
- package/esm2015/src/resolvers/quote.resolver.js +4 -11
- package/esm2015/src/services/flow.service.js +6 -5
- package/fesm2015/veloce-sdk-core.js +160 -69
- package/fesm2015/veloce-sdk-core.js.map +1 -1
- package/fesm2015/veloce-sdk-runtime.js +3 -4
- package/fesm2015/veloce-sdk-runtime.js.map +1 -1
- package/fesm2015/veloce-sdk.js +44 -39
- package/fesm2015/veloce-sdk.js.map +1 -1
- package/package.json +1 -1
- package/runtime/services/cart.service.d.ts +1 -1
- package/src/components/header/header.component.d.ts +5 -2
- package/src/components/header/header.types.d.ts +0 -1
- package/src/pages/product/product.component.d.ts +1 -0
- package/src/resolvers/flow.resolver.d.ts +3 -1
- package/src/resolvers/quote.resolver.d.ts +0 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
import { HttpErrorResponse } from '@angular/common/http';
|
2
2
|
import { Injectable } from '@angular/core';
|
3
|
-
import { catchError, from, of
|
3
|
+
import { catchError, from, of } from 'rxjs';
|
4
4
|
import * as i0 from "@angular/core";
|
5
5
|
import * as i1 from "@angular/router";
|
6
6
|
import * as i2 from "@veloce/sdk/core";
|
@@ -17,21 +17,14 @@ export class QuoteResolver {
|
|
17
17
|
const parentUrl = this.routerService.getFlowRootPath(route);
|
18
18
|
return from(this.router.navigate([parentUrl, '404'], { state: { message } }));
|
19
19
|
}
|
20
|
-
initFlow$() {
|
21
|
-
if (this.quoteDraftService.isStandalone) {
|
22
|
-
return of(undefined);
|
23
|
-
}
|
24
|
-
return this.flowConfiguration.initialize$();
|
25
|
-
}
|
26
20
|
resolve(route) {
|
27
21
|
const { headerId } = this.contextService.resolve();
|
28
|
-
const quote = this.quoteDraftService.
|
22
|
+
const quote = this.quoteDraftService.quoteDraft;
|
29
23
|
if (quote && quote.quoteId === headerId) {
|
30
24
|
return of(true);
|
31
25
|
}
|
32
26
|
const { queryParams } = route;
|
33
|
-
this.
|
34
|
-
return this.quoteDraftService.init(headerId, queryParams).pipe(switchMap(() => this.initFlow$()), catchError(e => {
|
27
|
+
return this.quoteDraftService.init(headerId, queryParams).pipe(catchError(e => {
|
35
28
|
const message = e instanceof HttpErrorResponse ? e.error.message : e;
|
36
29
|
return this.handleError(route, message);
|
37
30
|
}));
|
@@ -42,4 +35,4 @@ QuoteResolver.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", versio
|
|
42
35
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteResolver, decorators: [{
|
43
36
|
type: Injectable
|
44
37
|
}], ctorParameters: function () { return [{ type: i1.Router }, { type: i2.QuoteDraftService }, { type: i3.FlowRouterService }, { type: i2.ContextService }, { type: i2.FlowConf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4gICAgcmV0dXJuIGZyb20odGhpcy5yb3V0ZXIubmF2aWdhdGUoW3BhcmVudFVybCwgJzQwNCddLCB7IHN0YXRlOiB7IG1lc3NhZ2UgfSB9KSk7XG4gIH1cblxuICByZXNvbHZlKHJvdXRlOiBBY3RpdmF0ZWRSb3V0ZVNuYXBzaG90KTogT2JzZXJ2YWJsZTx2b2lkIHwgYm9vbGVhbj4ge1xuICAgIGNvbnN0IHsgaGVhZGVySWQgfSA9IHRoaXMuY29udGV4dFNlcnZpY2UucmVzb2x2ZSgpO1xuICAgIGNvbnN0IHF1b3RlID0gdGhpcy5xdW90ZURyYWZ0U2VydmljZS5xdW90ZURyYWZ0O1xuXG4gICAgaWYgKHF1b3RlICYmIHF1b3RlLnF1b3RlSWQgPT09IGhlYWRlcklkKSB7XG4gICAgICByZXR1cm4gb2YodHJ1ZSk7XG4gICAgfVxuXG4gICAgY29uc3QgeyBxdWVyeVBhcmFtcyB9ID0gcm91dGU7XG5cbiAgICByZXR1cm4gdGhpcy5xdW90ZURyYWZ0U2VydmljZS5pbml0KGhlYWRlcklkLCBxdWVyeVBhcmFtcykucGlwZShcbiAgICAgIGNhdGNoRXJyb3IoZSA9PiB7XG4gICAgICAgIGNvbnN0IG1lc3NhZ2UgPSBlIGluc3RhbmNlb2YgSHR0cEVycm9yUmVzcG9uc2UgPyBlLmVycm9yLm1lc3NhZ2UgOiBlO1xuICAgICAgICByZXR1cm4gdGhpcy5oYW5kbGVFcnJvcihyb3V0ZSwgbWVzc2FnZSk7XG4gICAgICB9KSxcbiAgICApO1xuICB9XG59XG4iXX0=
|
@@ -18,8 +18,8 @@ export class FlowService {
|
|
18
18
|
this.integrationState
|
19
19
|
.listen$(FlowAction.FLOW_CONFIGURE_PRODUCT)
|
20
20
|
.pipe(takeUntil(this.cleanup$), tap(payload => {
|
21
|
-
var _a, _b
|
22
|
-
const productId = (_a = payload.productId) !== null && _a !== void 0 ? _a : (
|
21
|
+
var _a, _b;
|
22
|
+
const productId = (_a = payload.productId) !== null && _a !== void 0 ? _a : (_b = this.quoteDraftService.currentState.find(li => li.id === payload.lineItemId)) === null || _b === void 0 ? void 0 : _b.productId;
|
23
23
|
if (productId) {
|
24
24
|
this.flowRouterService.navigateToProductConfiguration(productId, payload.lineItemId);
|
25
25
|
}
|
@@ -39,7 +39,7 @@ export class FlowService {
|
|
39
39
|
if (!lineItem) {
|
40
40
|
return of(undefined);
|
41
41
|
}
|
42
|
-
const currentState = this.
|
42
|
+
const currentState = this.quoteDraftService.currentState;
|
43
43
|
const isNewLineItem = currentState.every(li => li.id !== lineItem.id);
|
44
44
|
let updatedState;
|
45
45
|
if (isNewLineItem) {
|
@@ -48,7 +48,8 @@ export class FlowService {
|
|
48
48
|
else {
|
49
49
|
updatedState = currentState.map(li => (li.id === lineItem.id ? lineItem : li));
|
50
50
|
}
|
51
|
-
|
51
|
+
this.quoteDraftService.setCurrentLineItemState(updatedState);
|
52
|
+
return this.flowConfigurationService.calculate$();
|
52
53
|
}), tap(() => {
|
53
54
|
this.configurationService.hasUnsavedChanges = false;
|
54
55
|
this.flowRouterService.navigateToShoppingCart();
|
@@ -64,4 +65,4 @@ FlowService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version:
|
|
64
65
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowService, decorators: [{
|
65
66
|
type: Injectable
|
66
67
|
}], ctorParameters: function () { return [{ type: i1.IntegrationState }, { type: i2.FlowRouterService }, { type: i3.QuoteDraftService }, { type: i3.ConfigurationService }, { type: i3.FlowConfigurationService }]; } });
|
67
|
-
//# sourceMappingURL=data:application/json;base64,
|
68
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmxvdy5zZXJ2aWNlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vbGlicy9zZGsvc3JjL3NlcnZpY2V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Zsb3dDb25maWd1cmF0aW9uU2VydmljZS5jYWxjdWxhdGUkKCk7XG4gICAgICAgIH0pLFxuICAgICAgICB0YXAoKCkgPT4ge1xuICAgICAgICAgIHRoaXMuY29uZmlndXJhdGlvblNlcnZpY2UuaGFzVW5zYXZlZENoYW5nZXMgPSBmYWxzZTtcbiAgICAgICAgICB0aGlzLmZsb3dSb3V0ZXJTZXJ2aWNlLm5hdmlnYXRlVG9TaG9wcGluZ0NhcnQoKTtcbiAgICAgICAgfSksXG4gICAgICApXG4gICAgICAuc3Vic2NyaWJlKCk7XG4gIH1cblxuICBwdWJsaWMgY2xlYW51cCgpOiB2b2lkIHtcbiAgICB0aGlzLmNsZWFudXAkLm5leHQoKTtcbiAgfVxufVxuIl19
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import * as i0 from '@angular/core';
|
2
2
|
import { Injectable, NgModule } from '@angular/core';
|
3
3
|
import { UUID, ConfigurationContext, ConfigurationContextMode, RuntimeModel, SalesforceIdUtils, ConfigurationMode } from '@veloce/core';
|
4
|
-
import { BehaviorSubject, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, zip, combineLatest, throwError, shareReplay
|
5
|
-
import { filter, tap, map, take, first, catchError as catchError$1, switchMap, finalize } from 'rxjs/operators';
|
4
|
+
import { BehaviorSubject, map as map$1, distinctUntilChanged, catchError, of, tap as tap$1, zip, noop, combineLatest, throwError, shareReplay as shareReplay$1, switchMap as switchMap$1 } from 'rxjs';
|
5
|
+
import { filter, tap, map, take, shareReplay, first, catchError as catchError$1, switchMap, finalize } from 'rxjs/operators';
|
6
6
|
import * as i1 from '@veloce/api';
|
7
7
|
import { PriceApiService, ContextApiService, ProductModelApiService, ConfigurationApiService } from '@veloce/api';
|
8
8
|
import { merge, flatten, sortBy, cloneDeep } from 'lodash';
|
@@ -100,57 +100,117 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
100
100
|
}], ctorParameters: function () { return [{ type: i1.ProductApiService }]; } });
|
101
101
|
|
102
102
|
class QuoteDraftService {
|
103
|
-
constructor(context, quoteApiService, priceApiService) {
|
103
|
+
constructor(context, quoteApiService, priceApiService, sfApiService) {
|
104
104
|
this.context = context;
|
105
105
|
this.quoteApiService = quoteApiService;
|
106
106
|
this.priceApiService = priceApiService;
|
107
|
+
this.sfApiService = sfApiService;
|
107
108
|
this.quoteSubj$ = new BehaviorSubject(null);
|
108
109
|
this.resetSubj$ = new BehaviorSubject(true);
|
109
|
-
this.priceLists = [];
|
110
110
|
this.isInitialized = false;
|
111
|
+
this.allPriceLists = [];
|
112
|
+
this.assetPriceLists = [];
|
111
113
|
this.hasUnsavedChanges = false;
|
112
114
|
this.reset$ = this.resetSubj$.asObservable();
|
115
|
+
this.activePriceList$ = this.context.resolve$().pipe(map(ctx => this.allPriceLists.find(priceList => priceList.id === ctx.properties.PriceListId)), filter((priceList) => Boolean(priceList)));
|
113
116
|
}
|
114
117
|
reset() {
|
115
118
|
this.resetSubj$.next(true);
|
116
119
|
this.quoteSubj$.next(null);
|
117
120
|
}
|
118
121
|
init(quoteId, params) {
|
119
|
-
return zip(this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()
|
122
|
+
return zip(this.context.resolve$(), this.quoteApiService.getQuoteDraft(quoteId, params), this.priceApiService.getPriceLists()).pipe(tap(([context, quote, allPriceLists]) => {
|
123
|
+
this.allPriceLists = allPriceLists;
|
120
124
|
this.quoteSubj$.next(quote);
|
121
|
-
this.priceLists = priceLists;
|
122
|
-
this.quotePriceList = priceLists.find(p => p.id === context.properties.PriceListId);
|
123
125
|
this.context.update(Object.assign(Object.assign(Object.assign({}, context), quote.context), { properties: Object.assign(Object.assign({}, context.properties), quote.context.properties) }));
|
124
|
-
}),
|
126
|
+
}), tap(() => {
|
127
|
+
this.populateActivePriceLists$();
|
125
128
|
this.isInitialized = true;
|
126
|
-
}), take(1));
|
129
|
+
}), map(() => noop()), take(1));
|
127
130
|
}
|
128
131
|
setCurrentLineItemState(lineItems) {
|
129
|
-
const
|
130
|
-
if (!
|
132
|
+
const quoteDraft = this.quoteSubj$.value;
|
133
|
+
if (!quoteDraft) {
|
131
134
|
return;
|
132
135
|
}
|
133
|
-
this.quoteSubj$.next(Object.assign(Object.assign({},
|
136
|
+
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: lineItems }));
|
134
137
|
this.markAsUpdated();
|
135
138
|
}
|
139
|
+
updateQuoteDraft(update) {
|
140
|
+
const quoteDraft = this.quoteSubj$.value;
|
141
|
+
if (!quoteDraft) {
|
142
|
+
return;
|
143
|
+
}
|
144
|
+
if (update.context) {
|
145
|
+
this.context.update(update.context);
|
146
|
+
}
|
147
|
+
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), update));
|
148
|
+
}
|
136
149
|
updateByPriceSummary(priceSummary) {
|
137
|
-
const
|
138
|
-
if (!
|
150
|
+
const quoteDraft = this.quoteSubj$.value;
|
151
|
+
if (!quoteDraft) {
|
139
152
|
return;
|
140
153
|
}
|
141
|
-
this.
|
154
|
+
const updatedCurrentState = this.currentState.map(lineItem => {
|
155
|
+
const updated = priceSummary.lineItems.find(li => li.id === lineItem.id);
|
156
|
+
return updated !== null && updated !== void 0 ? updated : lineItem;
|
157
|
+
});
|
158
|
+
this.quoteSubj$.next(Object.assign(Object.assign({}, quoteDraft), { currentState: updatedCurrentState, totalPrices: priceSummary.totalPrices, approvalItems: priceSummary.approvalItems }));
|
142
159
|
this.markAsUpdated();
|
143
160
|
}
|
144
|
-
get
|
145
|
-
return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.
|
161
|
+
get quoteDraft$() {
|
162
|
+
return combineLatest([this.quoteSubj$, this.context.resolve$()]).pipe(map(() => this.quoteDraft), filter((quote) => Boolean(quote)), shareReplay());
|
146
163
|
}
|
147
|
-
get
|
164
|
+
get quoteDraft() {
|
148
165
|
const quote = this.quoteSubj$.value;
|
149
166
|
if (!quote) {
|
150
167
|
return null;
|
151
168
|
}
|
152
169
|
return Object.assign(Object.assign({}, quote), { context: this.context.resolve() });
|
153
170
|
}
|
171
|
+
get currentState$() {
|
172
|
+
return this.quoteDraft$.pipe(map(quote => quote.currentState));
|
173
|
+
}
|
174
|
+
get currentState() {
|
175
|
+
var _a, _b;
|
176
|
+
return (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
177
|
+
}
|
178
|
+
/**
|
179
|
+
* Stream of activeCurrentState
|
180
|
+
*/
|
181
|
+
get activeCurrentState$() {
|
182
|
+
return this.quoteDraft$.pipe(map(() => this.activeCurrentState));
|
183
|
+
}
|
184
|
+
/**
|
185
|
+
* activeCurrentState is currentState passed through additional filters
|
186
|
+
*/
|
187
|
+
get activeCurrentState() {
|
188
|
+
var _a, _b;
|
189
|
+
const ctx = this.context.resolve();
|
190
|
+
let currentState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.currentState) !== null && _b !== void 0 ? _b : [];
|
191
|
+
if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
|
192
|
+
currentState = this.filterByActivePriceList(currentState);
|
193
|
+
}
|
194
|
+
return currentState;
|
195
|
+
}
|
196
|
+
/**
|
197
|
+
* Stream of activeInitialState
|
198
|
+
*/
|
199
|
+
get activeInitialState$() {
|
200
|
+
return this.quoteDraft$.pipe(map(() => this.activeInitialState));
|
201
|
+
}
|
202
|
+
/**
|
203
|
+
* activeInitialState is initialState passed through additional filters
|
204
|
+
*/
|
205
|
+
get activeInitialState() {
|
206
|
+
var _a, _b;
|
207
|
+
const ctx = this.context.resolve();
|
208
|
+
let initialState = (_b = (_a = this.quoteDraft) === null || _a === void 0 ? void 0 : _a.initialState) !== null && _b !== void 0 ? _b : [];
|
209
|
+
if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
|
210
|
+
initialState = this.filterByActivePriceList(initialState);
|
211
|
+
}
|
212
|
+
return initialState;
|
213
|
+
}
|
154
214
|
get isStandalone() {
|
155
215
|
return this.context.resolve().properties.standalone === 'true';
|
156
216
|
}
|
@@ -167,18 +227,55 @@ class QuoteDraftService {
|
|
167
227
|
}
|
168
228
|
return false;
|
169
229
|
}
|
230
|
+
updateActivePriceList(priceListId) {
|
231
|
+
this.context.update({ properties: { PriceListId: priceListId } });
|
232
|
+
}
|
233
|
+
populateActivePriceLists$() {
|
234
|
+
const ctx = this.context.resolve();
|
235
|
+
const quoteDraft = this.quoteDraft;
|
236
|
+
if (!quoteDraft) {
|
237
|
+
return;
|
238
|
+
}
|
239
|
+
// In ACCOUNT mode populate price lists from related assets
|
240
|
+
if (ctx.mode === ConfigurationContextMode.ACCOUNT) {
|
241
|
+
// Populate list of price lists
|
242
|
+
this.assetPriceLists = quoteDraft.currentState
|
243
|
+
.map(({ priceListId }) => priceListId)
|
244
|
+
.reduce((trunk, priceListId) => {
|
245
|
+
var _a, _b;
|
246
|
+
if (!priceListId || trunk.some(item => item.id === priceListId)) {
|
247
|
+
return trunk;
|
248
|
+
}
|
249
|
+
return [
|
250
|
+
...trunk,
|
251
|
+
{ 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 : '' },
|
252
|
+
];
|
253
|
+
}, []);
|
254
|
+
const activePriceList = this.assetPriceLists[0];
|
255
|
+
this.updateActivePriceList(activePriceList.id);
|
256
|
+
// Update PriceListId in context properties
|
257
|
+
// TODO: remove it when backend will have such logic
|
258
|
+
if (this.assetPriceLists.length) {
|
259
|
+
this.context.update({ properties: { PriceListId: activePriceList.id } });
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
filterByActivePriceList(lineItems) {
|
264
|
+
const ctx = this.context.resolve();
|
265
|
+
return lineItems.filter(li => !li.priceListId || li.priceListId === ctx.properties.PriceListId);
|
266
|
+
}
|
170
267
|
markAsUpdated() {
|
171
268
|
if (this.isInitialized && !this.hasUnsavedChanges) {
|
172
269
|
this.hasUnsavedChanges = true;
|
173
270
|
}
|
174
271
|
}
|
175
272
|
}
|
176
|
-
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 });
|
273
|
+
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 }, { token: i1.SalesforceApiService }], target: i0.ɵɵFactoryTarget.Injectable });
|
177
274
|
QuoteDraftService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, providedIn: 'root' });
|
178
275
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: QuoteDraftService, decorators: [{
|
179
276
|
type: Injectable,
|
180
277
|
args: [{ providedIn: 'root' }]
|
181
|
-
}], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }]; } });
|
278
|
+
}], ctorParameters: function () { return [{ type: ContextService }, { type: i1.QuoteApiService }, { type: i1.PriceApiService }, { type: i1.SalesforceApiService }]; } });
|
182
279
|
|
183
280
|
class RuntimeContextService {
|
184
281
|
constructor(configurationApiService, messageService) {
|
@@ -498,7 +595,7 @@ class ConfigurationService {
|
|
498
595
|
this.states = Object.assign(Object.assign({}, this.states), update);
|
499
596
|
}
|
500
597
|
get() {
|
501
|
-
return this.lineItem.asObservable().pipe(shareReplay());
|
598
|
+
return this.lineItem.asObservable().pipe(shareReplay$1());
|
502
599
|
}
|
503
600
|
getSnapshot() {
|
504
601
|
return this.lineItem.value ? Object.assign({}, this.lineItem.value) : undefined;
|
@@ -532,8 +629,6 @@ class ConfigurationService {
|
|
532
629
|
const qty = (_d = this.runtimeService.initializationProps) === null || _d === void 0 ? void 0 : _d.defaultQty;
|
533
630
|
const lineItem = (_e = this.states.configurableRamp) !== null && _e !== void 0 ? _e : getDefaultLineItem(runtimeContext, uiDefinitionProperties, qty);
|
534
631
|
const configurationRequest = this.createRequest(lineItem);
|
535
|
-
configurationRequest.lineItems = this.states.currentState || [];
|
536
|
-
configurationRequest.asset = this.states.asset;
|
537
632
|
const mainPricingEnabled = (_f = runtimeContext.properties) === null || _f === void 0 ? void 0 : _f.PricingEnabled;
|
538
633
|
const pricingEnabled = mainPricingEnabled ? mainPricingEnabled === 'true' : uiDefinitionProperties.pricingEnabled;
|
539
634
|
return this.configurationApiService
|
@@ -549,10 +644,9 @@ class ConfigurationService {
|
|
549
644
|
.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)); })));
|
550
645
|
}
|
551
646
|
configureExternal$(productId, qty) {
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
// });
|
647
|
+
this.updateCurrentStates({
|
648
|
+
currentState: this.quoteDraftService.currentState,
|
649
|
+
});
|
556
650
|
return this.runtimeService.init({ productId, defaultQty: qty }).pipe(switchMap(() => this.configure()), first(), catchError$1(error => {
|
557
651
|
this.messageService.add({ severity: ToastType.error, summary: error });
|
558
652
|
throw error;
|
@@ -565,6 +659,8 @@ class ConfigurationService {
|
|
565
659
|
step: !this.lineItem.value ? RuntimeStep.START : RuntimeStep.UPDATE,
|
566
660
|
attributeDomainMode: 'ALL',
|
567
661
|
context: this.contextService.resolve(),
|
662
|
+
lineItems: this.states.currentState || [],
|
663
|
+
asset: this.states.asset,
|
568
664
|
};
|
569
665
|
}
|
570
666
|
showInactiveProductsConfirmation() {
|
@@ -709,70 +805,65 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImpo
|
|
709
805
|
}] });
|
710
806
|
|
711
807
|
class FlowConfigurationService {
|
712
|
-
constructor(
|
713
|
-
this.
|
808
|
+
constructor(proceduresApiService, contextService, quoteDraftService, updateService, configurationService) {
|
809
|
+
this.proceduresApiService = proceduresApiService;
|
714
810
|
this.contextService = contextService;
|
715
811
|
this.quoteDraftService = quoteDraftService;
|
716
|
-
this.messageService = messageService;
|
717
812
|
this.updateService = updateService;
|
718
813
|
this.configurationService = configurationService;
|
719
|
-
this.charges = new BehaviorSubject({});
|
720
|
-
this.bounceBackUpdate$ = new BehaviorSubject(true);
|
721
814
|
}
|
722
|
-
|
723
|
-
this.
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
this.resetSubscription = this.quoteDraftService.reset$.subscribe(() => this.reset());
|
729
|
-
return this.calculate$(this.getSnapshot()).pipe(map$1(noop));
|
730
|
-
}
|
731
|
-
calculate$(currentState) {
|
732
|
-
const context = this.contextService.resolve();
|
733
|
-
return this.priceApiService.calculate({ context, currentState }).pipe(tap$1((result) => {
|
734
|
-
this.quoteDraftService.updateByPriceSummary(result);
|
735
|
-
this.charges.next(result.charges);
|
736
|
-
if (context) {
|
737
|
-
this.contextService.update({ properties: context.properties });
|
738
|
-
}
|
739
|
-
}), this.handleError());
|
815
|
+
calculate$() {
|
816
|
+
const quoteDraft = this.quoteDraftService.quoteDraft;
|
817
|
+
if (!quoteDraft || !quoteDraft.currentState.length) {
|
818
|
+
return of(undefined);
|
819
|
+
}
|
820
|
+
return this.proceduresApiService.apply$(quoteDraft).pipe(tap$1(result => this.quoteDraftService.updateQuoteDraft(result)), map$1(noop));
|
740
821
|
}
|
741
|
-
calculate(
|
742
|
-
this.calculate$(
|
822
|
+
calculate() {
|
823
|
+
this.calculate$().subscribe();
|
743
824
|
}
|
744
825
|
update$(updates) {
|
745
|
-
const
|
746
|
-
return of([]).pipe(tap$1(() =>
|
826
|
+
const currentState = this.quoteDraftService.currentState;
|
827
|
+
return of([]).pipe(tap$1(() => {
|
828
|
+
const updatedState = cloneDeep(currentState);
|
829
|
+
this.updateService.update(updatedState, updates);
|
830
|
+
this.quoteDraftService.setCurrentLineItemState(updatedState);
|
831
|
+
}), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
|
747
832
|
}
|
748
833
|
update(updates) {
|
749
834
|
this.update$(updates).subscribe();
|
750
835
|
}
|
751
836
|
delete$(ids) {
|
752
|
-
|
837
|
+
const currentState = this.quoteDraftService.currentState;
|
838
|
+
return of([]).pipe(tap$1(() => {
|
839
|
+
const updatedState = ids.reduce((result, id) => this.updateService.delete(result, id), currentState);
|
840
|
+
this.quoteDraftService.setCurrentLineItemState(updatedState);
|
841
|
+
}), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
|
753
842
|
}
|
754
843
|
delete(ids) {
|
755
844
|
this.delete$(ids).subscribe();
|
756
845
|
}
|
757
|
-
|
758
|
-
|
846
|
+
addTerm$(term) {
|
847
|
+
const currentState = this.quoteDraftService.currentState;
|
848
|
+
return of([]).pipe(tap$1(() => this.quoteDraftService.setCurrentLineItemState([...currentState, term])), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
|
759
849
|
}
|
760
850
|
addToCart$(productId, qty) {
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
851
|
+
const currentState = this.quoteDraftService.currentState;
|
852
|
+
return this.configurationService.configureExternal$(productId, qty).pipe(tap$1(lineItem => this.quoteDraftService.setCurrentLineItemState([...currentState, lineItem])), switchMap$1(() => this.calculate$()), map$1(() => this.quoteDraftService.quoteDraft), this.handleErrorAndBounceBack(currentState));
|
853
|
+
}
|
854
|
+
get() {
|
855
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(() => this.quoteDraftService.activeCurrentState), shareReplay$1());
|
766
856
|
}
|
767
857
|
getSnapshot() {
|
768
858
|
var _a, _b;
|
769
|
-
return (_b = (_a = this.quoteDraftService
|
859
|
+
return (_b = (_a = this.quoteDraftService) === null || _a === void 0 ? void 0 : _a.currentState.slice()) !== null && _b !== void 0 ? _b : [];
|
770
860
|
}
|
771
861
|
get charges$() {
|
772
|
-
return this.
|
862
|
+
return this.quoteDraftService.quoteDraft$.pipe(map$1(({ charges }) => charges));
|
773
863
|
}
|
774
864
|
get chargesSnapshot() {
|
775
|
-
|
865
|
+
var _a, _b;
|
866
|
+
return (_b = (_a = this.quoteDraftService.quoteDraft) === null || _a === void 0 ? void 0 : _a.charges) !== null && _b !== void 0 ? _b : {};
|
776
867
|
}
|
777
868
|
get contextSnapshot() {
|
778
869
|
return this.contextService.resolve();
|
@@ -780,22 +871,22 @@ class FlowConfigurationService {
|
|
780
871
|
get context$() {
|
781
872
|
return this.contextService.resolve$();
|
782
873
|
}
|
783
|
-
|
874
|
+
handleErrorAndBounceBack(stateToRestore) {
|
784
875
|
return (source$) => {
|
785
876
|
return source$.pipe(catchError(error => {
|
786
877
|
console.error(error);
|
787
878
|
// bounce back if configuration call has failed
|
788
|
-
this.
|
879
|
+
this.quoteDraftService.setCurrentLineItemState(stateToRestore);
|
789
880
|
return throwError(() => error);
|
790
881
|
}));
|
791
882
|
};
|
792
883
|
}
|
793
884
|
}
|
794
|
-
FlowConfigurationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, deps: [{ token: i1.
|
885
|
+
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 });
|
795
886
|
FlowConfigurationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService });
|
796
887
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0, type: FlowConfigurationService, decorators: [{
|
797
888
|
type: Injectable
|
798
|
-
}], ctorParameters: function () { return [{ type: i1.
|
889
|
+
}], ctorParameters: function () { return [{ type: i1.ProceduresApiService }, { type: ContextService }, { type: QuoteDraftService }, { type: FlowUpdateService }, { type: ConfigurationService }]; } });
|
799
890
|
|
800
891
|
class FlowConfigurationModule {
|
801
892
|
}
|