All files / projects/organization-management/src/app/components/cost-center-users-list cost-center-users-list.component.ts

62.5% Statements 10/16
57.14% Branches 4/7
50% Functions 3/6
60% Lines 9/15

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 54 552x   2x     2x                               2x   3x   3x       3x     3x 15x                                          
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
 
import { CostCenter, CostCenterBuyer } from 'ish-core/models/cost-center/cost-center.model';
import { ModalDialogComponent } from 'ish-shared/components/common/modal-dialog/modal-dialog.component';
 
import { OrganizationManagementFacade } from '../../facades/organization-management.facade';
import { CostCenterBuyerEditDialogComponent } from '../cost-center-buyer-edit-dialog/cost-center-buyer-edit-dialog.component';
 
type CostCenterBuyersListColumnsType = 'buyerName' | 'orders' | 'pendingOrders' | 'budget' | 'actions';
 
/**
 * The Cost Center User List Component displays the users assigned to the cost center, their budgets, orders and pending orders.
 *
 * @example
 * <ish-cost-center-users-list [costCenter]="costCenter"></ish-cost-center-users-list>
 */
@Component({
  selector: 'ish-cost-center-users-list',
  templateUrl: './cost-center-users-list.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CostCenterUsersListComponent implements OnInit {
  @Input({ required: true }) costCenter: CostCenter;
  @Input() isEditable = false;
 
  columnsToDisplay: CostCenterBuyersListColumnsType[] = ['buyerName', 'pendingOrders', 'orders', 'budget', 'actions'];
 
  selectedBuyer: CostCenterBuyer;
 
  constructor(private organizationManagementFacade: OrganizationManagementFacade) {}
 
  ngOnInit() {
    if (!this.isEditable) {
      this.columnsToDisplay = this.columnsToDisplay.filter(col => col !== 'actions');
    }
  }
 
  openEditCostCenterBuyerDialog(buyer: CostCenterBuyer, modal: CostCenterBuyerEditDialogComponent) {
    modal.show(buyer);
  }
 
  removeBuyerConfirmation(buyer: CostCenterBuyer, modal: ModalDialogComponent<string>) {
    this.selectedBuyer = buyer;
    if (buyer.pendingOrders) {
      modal.show();
    } else {
      this.removeBuyerFromCostCenter();
    }
  }
 
  removeBuyerFromCostCenter() {
    this.organizationManagementFacade.removeBuyerFromCostCenter(this.selectedBuyer.login);
  }
}