All files / projects/organization-management/src/app/pages/cost-center-import cost-center-import-page.component.ts

100% Statements 11/11
66.66% Branches 4/6
100% Functions 3/3
100% Lines 11/11

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 441x 1x       1x             1x 2x               2x   2x     2x   2x       2x               2x      
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Observable, combineLatest, map, of } from 'rxjs';
 
import { CostCenterImportResult } from 'ish-core/models/cost-center/cost-center.model';
 
import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
 
@Component({
  selector: 'ish-cost-center-import-page',
  templateUrl: './cost-center-import-page.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CostCenterImportPageComponent implements OnInit {
  importedCostCenters$: Observable<CostCenterImportResult[]> = of([]);
  importProgress$: Observable<{
    total: number;
    current: number;
    percentage: number;
  }>;
  loading$: Observable<boolean>;
 
  columnsToDisplay = ['costCenterId', 'costCenterName', 'costCenterManager', 'costCenterBudget', 'status'];
 
  constructor(private organizationManagementFacade: OrganizationManagementFacade) {}
 
  ngOnInit(): void {
    this.importedCostCenters$ = this.organizationManagementFacade.costCentersImportResults$;
 
    this.importProgress$ = combineLatest([
      this.organizationManagementFacade.costCentersImportTotal$,
      this.importedCostCenters$,
    ]).pipe(
      map(([totalCostCentersToImport, importedCostCenters]) => ({
        total: totalCostCentersToImport,
        current: importedCostCenters.length,
        percentage:
          totalCostCentersToImport > 0 ? Math.round((importedCostCenters.length / totalCostCentersToImport) * 100) : 0,
      }))
    );
 
    this.loading$ = this.organizationManagementFacade.costCentersLoading$;
  }
}