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 | 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 6x 4x 6x 3x 3x 6x 4x | import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { PriceItemHelper } from 'ish-core/models/price-item/price-item.helper';
import { Price, PriceHelper } from 'ish-core/models/price/price.model';
import { GenerateLazyComponent } from 'ish-core/utils/module-loader/generate-lazy-component.decorator';
import { RequisitionManagementFacade } from '../../facades/requisition-management.facade';
import { Requisition } from '../../models/requisition/requisition.model';
@Component({
selector: 'ish-approval-widget',
templateUrl: './approval-widget.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
@GenerateLazyComponent()
export class ApprovalWidgetComponent implements OnInit {
numPendingApprovals$: Observable<number>;
totalAmountApprovals$: Observable<Price>;
requisitionsLoading$: Observable<boolean>;
constructor(private requisitionFacade: RequisitionManagementFacade) {}
ngOnInit() {
const pendingApprovals$ = this.requisitionFacade.requisitions$('approver', 'PENDING');
this.numPendingApprovals$ = pendingApprovals$.pipe(
startWith([] as Requisition[]),
map(requisitions => requisitions.length)
);
this.totalAmountApprovals$ = pendingApprovals$.pipe(
map(requisitions => requisitions?.map(req => PriceItemHelper.selectType(req.totals?.total, 'gross'))),
map(prices => {
if (prices.length > 0) {
return prices?.reduce(
(curr: Price, acc: Price) => PriceHelper.sum(curr, acc),
PriceHelper.empty(prices[0].currency ?? undefined)
);
} else E{
return PriceHelper.empty();
}
})
);
this.requisitionsLoading$ = this.requisitionFacade.requisitionsLoading$;
}
}
|