Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | 42x 42x 42x 42x 42x 42x 42x 95x 95x 42x 81x 81x 81x 81x 106x 13x 93x 93x 50x 15x 35x 35x 35x 35x 43x | import { formatCurrency, getCurrencySymbol } from '@angular/common';
import { ChangeDetectorRef, DestroyRef, Pipe, PipeTransform, inject } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { TranslateService } from '@ngx-translate/core';
import { AccountFacade } from 'ish-core/facades/account.facade';
import { PriceItemHelper } from 'ish-core/models/price-item/price-item.helper';
import { PriceItem } from 'ish-core/models/price-item/price-item.model';
import { Price, PriceType } from './price.model';
export function formatPrice(price: Price, lang: string): string {
const symbol = getCurrencySymbol(price.currency, 'narrow', lang);
return symbol ? formatCurrency(price.value, lang, symbol) : price.value?.toString();
}
@Pipe({ name: 'ishPrice', pure: false })
export class PricePipe implements PipeTransform {
displayText: string;
private destroyRef = inject(DestroyRef);
constructor(
private translateService: TranslateService,
private cdRef: ChangeDetectorRef,
private accountFacade: AccountFacade
) {}
transform(data: Price | PriceItem, priceType?: PriceType): string {
if (!data) {
return this.translateService.instant('product.price.na.text');
}
Iif (!this.translateService.currentLang) {
return 'N/A';
}
switch (data.type) {
case 'PriceItem':
if (priceType) {
return formatPrice(PriceItemHelper.selectType(data, priceType), this.translateService.currentLang);
}
this.accountFacade.userPriceDisplayType$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(type => {
this.displayText = formatPrice(PriceItemHelper.selectType(data, type), this.translateService.currentLang);
this.cdRef.markForCheck();
});
return this.displayText;
default:
return formatPrice(data as Price, this.translateService.currentLang);
}
}
}
|