1 | import { Component, EventEmitter, Input, Output } from '@angular/core';
|
2 | import { Product } from '../shared';
|
3 | import { ContractPricingService } from '@vendasta/core/billing/contract/contract-pricing/contract-pricing.service';
|
4 | import 'rxjs/operators/switchMap';
|
5 | import { isNullOrUndefined } from 'util';
|
6 | var VaAddonListComponent = (function () {
|
7 | function VaAddonListComponent(contractPricingService) {
|
8 | this.contractPricingService = contractPricingService;
|
9 | this.showPricing = true;
|
10 | this._hasVerifiedContract = null;
|
11 | this._canAccessContractPricing = null;
|
12 | this.addonSelected = new EventEmitter();
|
13 | this.addonBilledProductMap = new Map();
|
14 | this.subscriptions = [];
|
15 | }
|
16 | Object.defineProperty(VaAddonListComponent.prototype, "hasVerifiedContract", {
|
17 | set: function (value) {
|
18 | this._hasVerifiedContract = value;
|
19 | this.populateBilledProduct();
|
20 | },
|
21 | enumerable: true,
|
22 | configurable: true
|
23 | });
|
24 | Object.defineProperty(VaAddonListComponent.prototype, "canAccessContractPricing", {
|
25 | set: function (value) {
|
26 | this._canAccessContractPricing = value;
|
27 | this.populateBilledProduct();
|
28 | },
|
29 | enumerable: true,
|
30 | configurable: true
|
31 | });
|
32 | VaAddonListComponent.prototype.ngOnInit = function () {
|
33 | this.populateBilledProduct();
|
34 | };
|
35 | VaAddonListComponent.prototype.populateBilledProduct = function () {
|
36 | var _this = this;
|
37 | if (this.displayContractPricing()) {
|
38 | this.addons.forEach(function (addon) {
|
39 | if (!_this.addonBilledProductMap.has(addon.addonId)) {
|
40 | _this.addonBilledProductMap.set(addon.addonId, { isLoaded: false, billedProduct: null });
|
41 | _this.subscriptions.push(_this.contractPricingService.getContractPricingForProduct(addon.appId, addon.addonId, false)
|
42 | .subscribe(function (bp) {
|
43 | _this.addonBilledProductMap.set(addon.addonId, { isLoaded: true, billedProduct: bp });
|
44 | }));
|
45 | }
|
46 | });
|
47 | }
|
48 | };
|
49 | VaAddonListComponent.prototype.onClick = function (addonId) {
|
50 | this.addonSelected.emit(addonId);
|
51 | };
|
52 | VaAddonListComponent.prototype.instanceOfPricing = function (object) {
|
53 | if (typeof object === 'number') {
|
54 | return false;
|
55 | }
|
56 | return object.currency !== undefined && object.prices !== undefined;
|
57 | };
|
58 | VaAddonListComponent.prototype.getDisplayPricing = function (addon) {
|
59 | var price = addon.price;
|
60 | if (price && this.instanceOfPricing(price)) {
|
61 | return price;
|
62 | }
|
63 | return {
|
64 | currency: this.product.currency,
|
65 | prices: [{
|
66 | price: addon.price,
|
67 | frequency: addon.billingFrequency ? addon.billingFrequency : 'Monthly'
|
68 | }]
|
69 | };
|
70 | };
|
71 | VaAddonListComponent.prototype.noData = function () {
|
72 | return isNullOrUndefined(this._hasVerifiedContract) || isNullOrUndefined(this._canAccessContractPricing);
|
73 | };
|
74 | VaAddonListComponent.prototype.displayContractPricing = function () {
|
75 | return this._canAccessContractPricing && this._hasVerifiedContract;
|
76 | };
|
77 | VaAddonListComponent.prototype.isBilledProductLoaded = function (addon) {
|
78 | if (this.noData()) {
|
79 | return false;
|
80 | }
|
81 | if (this.displayContractPricing()) {
|
82 | var value = this.addonBilledProductMap.get(addon.addonId);
|
83 | return value ? value.isLoaded : false;
|
84 | }
|
85 | return true;
|
86 | };
|
87 | VaAddonListComponent.prototype.getBilledProduct = function (addon) {
|
88 | var value = this.addonBilledProductMap.get(addon.addonId);
|
89 | return value ? value.billedProduct : null;
|
90 | };
|
91 | VaAddonListComponent.prototype.ngOnDestroy = function () {
|
92 | this.subscriptions.forEach(function (subscription) { return subscription.unsubscribe(); });
|
93 | };
|
94 | VaAddonListComponent.decorators = [
|
95 | { type: Component, args: [{
|
96 | selector: 'va-addon-list',
|
97 | template: "<mat-list *ngIf=\"addons\" class=\"addon-list\"> <mat-divider></mat-divider> <ng-container *ngFor=\"let addon of addons\"> <mat-list-item (click)=\"onClick(addon.addonId)\"> <div class=\"addon-icon-title\"> <img *ngIf=\"addon.icon;else noIcon\" class=\"addon-icon\" [src]=\"addon.icon\" mat-list-avatar/> <ng-template #noIcon> <mat-icon class=\"addon-default-icon\" mat-list-icon>add_circle</mat-icon> </ng-template> <div class=\"addon-title-tagline\"> <p class=\"addon-title\" matLine>{{ addon.title }} </p> <p class=\"addon-tagline\" matLine>{{ addon.tagline }}</p> </div> </div> <div *ngIf=\"showPricing\" class=\"price-section\"> <va-pricing [pricing]=\"getDisplayPricing(addon)\" [highlightPrice]=\"false\" [hasVerifiedContract]=\"_hasVerifiedContract\" [billedProduct]=\"getBilledProduct(addon)\" [loaded]=\"isBilledProductLoaded(addon)\"> </va-pricing> </div> </mat-list-item> <mat-divider></mat-divider> </ng-container> </mat-list> ",
|
98 | styles: [":host { display: block; } h2 + :host { margin: -8px 0; } :host ::ng-deep .mat-list-item.mat-2-line { height: auto !important; } :host ::ng-deep .mat-list .mat-list-item .mat-list-item-content { padding: 8px; align-items: flex-start; flex-direction: column; } @media screen and (min-width: 800px) { :host ::ng-deep .mat-list .mat-list-item .mat-list-item-content { flex-direction: row; } } .addon-list { position: relative; } .addon-default-icon { margin: 0 5px; color: #4caf50; } .addon-icon { width: 32px; height: 32px; } .addon-icon-title { flex-grow: 1; display: flex; width: 100%; } @media screen and (min-width: 800px) { .addon-icon-title { width: auto; } } .addon-title-tagline { padding: 0 16px 10px 8px; flex-grow: 1; } .addon-title-tagline .addon-title { color: #212121; font-size: 16px; line-height: 1.2; margin: 6px 0; white-space: normal; } .addon-title-tagline .addon-tagline { color: #616161; font-size: 14px; margin: 0; white-space: normal; } .price-section { min-width: 10em; margin-top: 6px; flex-shrink: 0; } mat-list-item:hover { background-color: #fafafa !important; cursor: pointer !important; } "]
|
99 | },] },
|
100 | ];
|
101 |
|
102 | VaAddonListComponent.ctorParameters = function () { return [
|
103 | { type: ContractPricingService, },
|
104 | ]; };
|
105 | VaAddonListComponent.propDecorators = {
|
106 | "addons": [{ type: Input },],
|
107 | "product": [{ type: Input },],
|
108 | "showPricing": [{ type: Input },],
|
109 | "hasVerifiedContract": [{ type: Input, args: ['hasVerifiedContract',] },],
|
110 | "canAccessContractPricing": [{ type: Input, args: ['canAccessContractPricing',] },],
|
111 | "addonSelected": [{ type: Output },],
|
112 | };
|
113 | return VaAddonListComponent;
|
114 | }());
|
115 | export { VaAddonListComponent };
|