@veloceapps/sdk 5.0.13-8 → 6.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/veloceapps-sdk-core.umd.js +155 -32
- package/bundles/veloceapps-sdk-core.umd.js.map +1 -1
- package/bundles/veloceapps-sdk.umd.js +13 -9
- package/bundles/veloceapps-sdk.umd.js.map +1 -1
- package/core/services/index.d.ts +1 -0
- package/core/services/metric-calculation/metric-calculation.service.d.ts +21 -0
- package/core/services/metric-calculation/metric-calculation.types.d.ts +1 -0
- package/core/services/metric-calculation/metric-calculation.utils.d.ts +5 -0
- package/esm2015/core/core.module.js +4 -4
- package/esm2015/core/services/index.js +2 -1
- package/esm2015/core/services/metric-calculation/metric-calculation.service.js +74 -0
- package/esm2015/core/services/metric-calculation/metric-calculation.types.js +2 -0
- package/esm2015/core/services/metric-calculation/metric-calculation.utils.js +42 -0
- package/esm2015/src/components/header/metrics/metrics.component.js +11 -7
- package/esm2015/src/components/header/metrics/metrics.definitions.js +6 -6
- package/fesm2015/veloceapps-sdk-core.js +136 -27
- package/fesm2015/veloceapps-sdk-core.js.map +1 -1
- package/fesm2015/veloceapps-sdk.js +13 -9
- package/fesm2015/veloceapps-sdk.js.map +1 -1
- package/package.json +5 -5
- package/src/components/header/metrics/metrics.component.d.ts +3 -2
@@ -423,37 +423,46 @@
|
|
423
423
|
args: [{ providedIn: 'root' }]
|
424
424
|
}], ctorParameters: function () { return [{ type: i1__namespace.ContextApiService }]; } });
|
425
425
|
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
var _a;
|
433
|
-
if (this.imagesMap$.value[productId] == null) {
|
434
|
-
this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
|
435
|
-
this.fetchProductImage(productId);
|
426
|
+
function calculateMetricByMethod(lineItems, metric, method) {
|
427
|
+
var items = getLineItemsByMethod(lineItems, method);
|
428
|
+
return items.reduce(function (acc, li) {
|
429
|
+
var value = li.reduce(function (accProduct, item) { return accProduct + ((item.totalMetrics && item.totalMetrics[metric]) || 0); }, 0);
|
430
|
+
if (method === 'avg' && li.length > 0) {
|
431
|
+
value /= li.length;
|
436
432
|
}
|
437
|
-
return
|
438
|
-
};
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
.
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
.
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
433
|
+
return acc + value;
|
434
|
+
}, 0);
|
435
|
+
}
|
436
|
+
function getLineItemsByMethod(lineItems, method) {
|
437
|
+
switch (method) {
|
438
|
+
case 'first': {
|
439
|
+
return lineItems.filter(function (li) { return !li.rampInstanceId; }).map(function (item) { return [item]; });
|
440
|
+
}
|
441
|
+
case 'last': {
|
442
|
+
var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
|
443
|
+
var products = rootTermItems.map(function (lineItem) { return __spreadArray([
|
444
|
+
lineItem
|
445
|
+
], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
|
446
|
+
return products
|
447
|
+
.map(function (items) { return __spreadArray([], __read(items)).sort(function (a, b) { return getDateValue(a.endDate || '') - getDateValue(b.endDate || ''); }).pop(); })
|
448
|
+
.filter(function (li) { return Boolean(li); })
|
449
|
+
.map(function (item) { return [item]; });
|
450
|
+
}
|
451
|
+
case 'avg': {
|
452
|
+
var rootTermItems = lineItems.filter(function (li) { return !li.rampInstanceId; });
|
453
|
+
return rootTermItems.map(function (lineItem) { return __spreadArray([lineItem], __read(lineItems.filter(function (li) { return li.rampInstanceId === lineItem.id; }))); });
|
454
|
+
}
|
455
|
+
case 'sum': {
|
456
|
+
return lineItems.map(function (item) { return [item]; });
|
457
|
+
}
|
458
|
+
default: {
|
459
|
+
return lineItems.map(function (item) { return [item]; });
|
460
|
+
}
|
461
|
+
}
|
462
|
+
}
|
463
|
+
function getDateValue(date) {
|
464
|
+
return date ? new Date(date).getTime() : 0;
|
465
|
+
}
|
457
466
|
|
458
467
|
var QuoteDraftService = /** @class */ (function () {
|
459
468
|
function QuoteDraftService(context, quoteApiService, priceApiService) {
|
@@ -737,6 +746,119 @@
|
|
737
746
|
args: [{ providedIn: 'root' }]
|
738
747
|
}], ctorParameters: function () { return [{ type: ContextService }, { type: i1__namespace.QuoteApiService }, { type: i1__namespace.PriceApiService }]; } });
|
739
748
|
|
749
|
+
var MetricsCalculationService = /** @class */ (function () {
|
750
|
+
function MetricsCalculationService(quoteDraftService, settingsService) {
|
751
|
+
var _this = this;
|
752
|
+
this.quoteDraftService = quoteDraftService;
|
753
|
+
this.settingsService = settingsService;
|
754
|
+
this.metricsUpdated$ = new rxjs.Subject();
|
755
|
+
this.quoteMetricsSettings = {};
|
756
|
+
this.metricsCalculationMethodMap = {};
|
757
|
+
this.metricsData = {};
|
758
|
+
rxjs.combineLatest([
|
759
|
+
this.quoteDraftService.currentState$,
|
760
|
+
this.settingsService.fetchSetting('QUOTE_LEVEL_METRIC_CALCULATION_METHOD').pipe(rxjs.take(1)),
|
761
|
+
]).subscribe(function (_a) {
|
762
|
+
var _b = __read(_a, 2), lineItems = _b[0], setting = _b[1];
|
763
|
+
var settingsData = {};
|
764
|
+
try {
|
765
|
+
settingsData = JSON.parse((setting === null || setting === void 0 ? void 0 : setting.value) || '{}');
|
766
|
+
}
|
767
|
+
catch (error) {
|
768
|
+
settingsData = {};
|
769
|
+
}
|
770
|
+
_this.quoteMetricsSettings = settingsData;
|
771
|
+
_this.updateMetrics(lineItems);
|
772
|
+
});
|
773
|
+
}
|
774
|
+
Object.defineProperty(MetricsCalculationService.prototype, "onMetricsUpdate$", {
|
775
|
+
get: function () {
|
776
|
+
return this.metricsUpdated$.asObservable();
|
777
|
+
},
|
778
|
+
enumerable: false,
|
779
|
+
configurable: true
|
780
|
+
});
|
781
|
+
MetricsCalculationService.prototype.getMetricValue = function (metric) {
|
782
|
+
return this.metricsData[metric] || 0;
|
783
|
+
};
|
784
|
+
MetricsCalculationService.prototype.updateMetrics = function (lineItems) {
|
785
|
+
var _this = this;
|
786
|
+
var metricKeys = this.collectMetricKeys(lineItems).filter(function (key) { return !key.includes('Effective_'); });
|
787
|
+
this.metricsCalculationMethodMap = this.buildMetricsCalculationMethods(metricKeys, this.metricsCalculationMethodMap);
|
788
|
+
this.metricsData = metricKeys.reduce(function (acc, key) {
|
789
|
+
var _a;
|
790
|
+
return (Object.assign(Object.assign({}, acc), (_a = {}, _a[key] = _this.calculateMetric(lineItems, key), _a)));
|
791
|
+
}, {});
|
792
|
+
this.metricsUpdated$.next();
|
793
|
+
};
|
794
|
+
MetricsCalculationService.prototype.calculateMetric = function (lineItems, metric) {
|
795
|
+
return calculateMetricByMethod(lineItems, metric, this.metricsCalculationMethodMap[metric] || 'sum');
|
796
|
+
};
|
797
|
+
MetricsCalculationService.prototype.buildMetricsCalculationMethods = function (metricKeys, initial) {
|
798
|
+
var _this = this;
|
799
|
+
return metricKeys.reduce(function (acc, name) {
|
800
|
+
var _a, _b;
|
801
|
+
if (acc[name]) {
|
802
|
+
return acc;
|
803
|
+
}
|
804
|
+
acc = Object.assign(Object.assign({}, acc), (_a = {}, _a[name] = 'sum', _a));
|
805
|
+
var settingKey = name.replace(/VDM_|Total_/g, '');
|
806
|
+
if (_this.quoteMetricsSettings[settingKey]) {
|
807
|
+
acc = Object.assign(Object.assign({}, acc), (_b = {}, _b[name] = _this.quoteMetricsSettings[settingKey], _b));
|
808
|
+
}
|
809
|
+
return acc;
|
810
|
+
}, initial);
|
811
|
+
};
|
812
|
+
MetricsCalculationService.prototype.collectMetricKeys = function (lineItems) {
|
813
|
+
var _this = this;
|
814
|
+
var keys = [];
|
815
|
+
lineItems.forEach(function (lineItem) {
|
816
|
+
keys.push.apply(keys, __spreadArray([], __read(Object.keys(lineItem.totalMetrics || {}))));
|
817
|
+
keys.push.apply(keys, __spreadArray([], __read(_this.collectMetricKeys(lineItem.lineItems))));
|
818
|
+
});
|
819
|
+
return lodash.uniq(keys);
|
820
|
+
};
|
821
|
+
return MetricsCalculationService;
|
822
|
+
}());
|
823
|
+
MetricsCalculationService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, deps: [{ token: QuoteDraftService }, { token: i1__namespace.ConfigurationSettingsApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
824
|
+
MetricsCalculationService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, providedIn: 'root' });
|
825
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: MetricsCalculationService, decorators: [{
|
826
|
+
type: i0.Injectable,
|
827
|
+
args: [{ providedIn: 'root' }]
|
828
|
+
}], ctorParameters: function () { return [{ type: QuoteDraftService }, { type: i1__namespace.ConfigurationSettingsApiService }]; } });
|
829
|
+
|
830
|
+
var ProductImagesService = /** @class */ (function () {
|
831
|
+
function ProductImagesService(productApiService) {
|
832
|
+
this.productApiService = productApiService;
|
833
|
+
this.imagesMap$ = new rxjs.BehaviorSubject({});
|
834
|
+
}
|
835
|
+
ProductImagesService.prototype.getImageUrl$ = function (productId) {
|
836
|
+
var _a;
|
837
|
+
if (this.imagesMap$.value[productId] == null) {
|
838
|
+
this.imagesMap$.next(Object.assign(Object.assign({}, this.imagesMap$.value), (_a = {}, _a[productId] = '', _a)));
|
839
|
+
this.fetchProductImage(productId);
|
840
|
+
}
|
841
|
+
return this.imagesMap$.pipe(rxjs.map(function (imagesMap) { return imagesMap[productId]; }), rxjs.distinctUntilChanged());
|
842
|
+
};
|
843
|
+
ProductImagesService.prototype.fetchProductImage = function (productId) {
|
844
|
+
var _this = this;
|
845
|
+
this.productApiService
|
846
|
+
.fetchImage$(productId)
|
847
|
+
.pipe(rxjs.map(function (file) { return URL.createObjectURL(file); }), rxjs.catchError(function () { return rxjs.of(''); }), rxjs.tap(function (url) {
|
848
|
+
var _a;
|
849
|
+
return _this.imagesMap$.next(Object.assign(Object.assign({}, _this.imagesMap$.value), (_a = {}, _a[productId] = url, _a)));
|
850
|
+
}))
|
851
|
+
.subscribe();
|
852
|
+
};
|
853
|
+
return ProductImagesService;
|
854
|
+
}());
|
855
|
+
ProductImagesService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, deps: [{ token: i1__namespace.ProductApiService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
856
|
+
ProductImagesService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, providedIn: 'root' });
|
857
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: ProductImagesService, decorators: [{
|
858
|
+
type: i0.Injectable,
|
859
|
+
args: [{ providedIn: 'root' }]
|
860
|
+
}], ctorParameters: function () { return [{ type: i1__namespace.ProductApiService }]; } });
|
861
|
+
|
740
862
|
var RuntimeContextService = /** @class */ (function () {
|
741
863
|
function RuntimeContextService(configurationApiService) {
|
742
864
|
this.configurationApiService = configurationApiService;
|
@@ -1597,12 +1719,12 @@
|
|
1597
1719
|
}());
|
1598
1720
|
SdkCoreModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
|
1599
1721
|
SdkCoreModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, imports: [ConfigurationModule, FlowConfigurationModule] });
|
1600
|
-
SdkCoreModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
|
1722
|
+
SdkCoreModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService], imports: [[ConfigurationModule, FlowConfigurationModule]] });
|
1601
1723
|
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.15", ngImport: i0__namespace, type: SdkCoreModule, decorators: [{
|
1602
1724
|
type: i0.NgModule,
|
1603
1725
|
args: [{
|
1604
1726
|
imports: [ConfigurationModule, FlowConfigurationModule],
|
1605
|
-
providers: [ContextService, QuoteDraftService, ProductImagesService],
|
1727
|
+
providers: [ContextService, QuoteDraftService, ProductImagesService, MetricsCalculationService],
|
1606
1728
|
}]
|
1607
1729
|
}] });
|
1608
1730
|
|
@@ -1617,6 +1739,7 @@
|
|
1617
1739
|
exports.FlowConfigurationService = FlowConfigurationService;
|
1618
1740
|
exports.FlowUpdateService = FlowUpdateService;
|
1619
1741
|
exports.LineItemWorker = LineItemWorker;
|
1742
|
+
exports.MetricsCalculationService = MetricsCalculationService;
|
1620
1743
|
exports.ProductImagesService = ProductImagesService;
|
1621
1744
|
exports.QuoteDraftService = QuoteDraftService;
|
1622
1745
|
exports.SdkCoreModule = SdkCoreModule;
|