From 2f42c6c8c85b1ff93ae7c5a59644fd240dccc074 Mon Sep 17 00:00:00 2001 From: Lorenz Hilpert Date: Tue, 23 Jun 2020 12:32:15 +0200 Subject: [PATCH] #537 - Meldetext von Downloads und NonBooks richtig anzeigen --- .../product-details.component.ts | 73 ++++++++++++++----- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/apps/sales/src/app/modules/product/pages/product-details/product-details.component.ts b/apps/sales/src/app/modules/product/pages/product-details/product-details.component.ts index a580f3b76..ae39d8c8c 100644 --- a/apps/sales/src/app/modules/product/pages/product-details/product-details.component.ts +++ b/apps/sales/src/app/modules/product/pages/product-details/product-details.component.ts @@ -68,8 +68,28 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { _halfStars = 0; _emptyStars = 0; loadBranchesInfoComponent = false; - availabilityStatus: string; - availabilityStatusText: string; + + ssc: { + store: { status?: string; text?: string }; + shipping: { status?: string; text?: string }; + download: { status?: string; text?: string }; + } = { + download: {}, + shipping: {}, + store: {}, + }; + + // availabilityStatus: string; + // availabilityStatusText: string; + + get availabilityStatus() { + return this.ssc.download.status || this.ssc.store.status || this.ssc.shipping.status; + } + + get availabilityStatusText() { + return this.ssc.download.text || this.ssc.store.text || this.ssc.shipping.text; + } + currentPickUpDate = ''; currentDeliveryDate = ''; storeError: string; @@ -267,7 +287,7 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { private cdrf: ChangeDetectorRef, private printer: PrinterService, private datePipe: DatePipe - ) { } + ) {} ngOnInit() { this.loadCartState(); @@ -314,6 +334,11 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { } if (item) { this.availability = []; + this.ssc = { + download: {}, + shipping: {}, + store: {}, + }; this.addSelectedItemToProcessIfMissingOrChanged(item); this.addItemIfDoesNotExistToProductState(item); this.item = item; @@ -350,7 +375,7 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { } private loadTempData() { - combineLatest(this.store.select(SharedSelectors.getProcessSelectedItem), this.route.params, this.route.queryParams) + combineLatest([this.store.select(SharedSelectors.getProcessSelectedItem), this.route.params, this.route.queryParams]) .pipe(takeUntil(this.destroy$), this.filterTempData) .subscribe((item) => { if (this.productDetailContainer) { @@ -426,10 +451,10 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { review.length === 0 ? 0 : review - .map((t) => t.rating) - .reduce((total, num) => { - return total + num; - }) / review.length, + .map((t) => t.rating) + .reduce((total, num) => { + return total + num; + }) / review.length, employeeReviews: review.length, reviews: review.map((t) => { return { @@ -633,7 +658,7 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { .getShippingAvailabilityWithCheck(item, ean, branch.id) .pipe(takeUntil(this.destroy$)) .subscribe((response) => { - if ((response as { error: boolean; message: string; type: CheckoutType; }).error) { + if ((response as { error: boolean; message: string; type: CheckoutType }).error) { this.downloadError = true; this.downloadLoaded = true; if (this.addToCartBtn) { @@ -648,8 +673,10 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { if (successfulResponse) { const preferredAvailability = successfulResponse.av.find((t) => t.preferred === 1 && t.supplier === 'DIG'); if (preferredAvailability) { - this.availabilityStatus = preferredAvailability.ssc; - this.availabilityStatusText = preferredAvailability.sscText; + this.ssc.download = { + status: preferredAvailability.ssc, + text: preferredAvailability.sscText, + }; if (preferredAvailability.price && preferredAvailability.price.value && preferredAvailability.price.value.value) { this.downloadPrice = preferredAvailability.price.value.value; } @@ -686,7 +713,7 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { async loadAvailability(it: ItemDTO, ean: string): Promise { const availabilityObservables: Observable< - { branchId: number; type: CheckoutType; av: AvailabilityDTO[]; } | { error: boolean; message: string; type: CheckoutType; } + { branchId: number; type: CheckoutType; av: AvailabilityDTO[] } | { error: boolean; message: string; type: CheckoutType } >[] = []; const userBranchNumber = this.store.selectSnapshot(BranchSelectors.getUserBranch); const branch = this.store.selectSnapshot(BranchSelectors.getBranchesIterable).find((t) => t.branchNumber === userBranchNumber); @@ -711,11 +738,11 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { ( response: | { - branchId: number; - type: CheckoutType; - av: AvailabilityDTO[]; - } - | { error: boolean; message: string; type: CheckoutType; } + branchId: number; + type: CheckoutType; + av: AvailabilityDTO[]; + } + | { error: boolean; message: string; type: CheckoutType } ) => { if ( (response as { @@ -753,8 +780,10 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { return; } if (item.type === CheckoutType.store) { - this.availabilityStatus = preferredAvailability.ssc; - this.availabilityStatusText = preferredAvailability.sscText; + this.ssc.store = { + status: preferredAvailability.ssc, + text: preferredAvailability.sscText, + }; this.currentPickUpDate = preferredAvailability.at ? this.datePipe.transform(new Date(preferredAvailability.at), 'dd.MM.yy') : null; @@ -771,6 +800,10 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { if (preferredAvailability.price && preferredAvailability.price.value && preferredAvailability.price.value.value) { this.deliveryPrice = preferredAvailability.price.value.value; } + this.ssc.shipping = { + status: preferredAvailability.ssc, + text: preferredAvailability.sscText, + }; } item.av.forEach((av) => { @@ -851,7 +884,7 @@ export class ProductDetailsComponent implements OnInit, OnDestroy { } } - cartActionCompleted(open: boolean) { } + cartActionCompleted(open: boolean) {} formatDate(date: Date | string): string { if (!!date) {