All files / src/app/pages/account-recurring-orders/recurring-order-list recurring-order-list.component.ts

63.63% Statements 7/11
75% Branches 6/8
25% Functions 1/4
60% Lines 6/10

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 55 56 57 58 592x 2x   2x                                     2x   5x                           5x                                        
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
 
import { AccountFacade } from 'ish-core/facades/account.facade';
import { RecurringOrder } from 'ish-core/models/recurring-order/recurring-order.model';
import { ModalDialogComponent } from 'ish-shared/components/common/modal-dialog/modal-dialog.component';
 
export type RecurringOrderColumnsType =
  | 'recurringOrderNo'
  | 'creationDate'
  | 'frequency'
  | 'lastOrderDate'
  | 'nextOrderDate'
  | 'buyer'
  | 'orderTotal'
  | 'actions';
 
@Component({
  selector: 'ish-recurring-order-list',
  templateUrl: './recurring-order-list.component.html',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RecurringOrderListComponent {
  @Input({ required: true }) recurringOrders: RecurringOrder[];
  @Input() columnsToDisplay: RecurringOrderColumnsType[] = [
    'recurringOrderNo',
    'creationDate',
    'frequency',
    'lastOrderDate',
    'nextOrderDate',
    'orderTotal',
    'actions',
  ];
  // decides whether the recurring orders of the customer or the logged-in user are returned
  // - context 'ADMIN' for the customer
  // - otherwise for the logged-in user
  @Input() context: string;
 
  constructor(private accountFacade: AccountFacade, private translate: TranslateService) {}
 
  /** Emits the id of the recurring order to delete. */
  delete(recurringOrderId: string) {
    this.accountFacade.deleteRecurringOrder(recurringOrderId);
  }
 
  /** Emits id and active state to update the active state for the recurring order */
  switchActiveStatus(recurringOrder: { active: boolean; id: string }) {
    this.accountFacade.setActiveRecurringOrder(recurringOrder.id, recurringOrder.active);
  }
 
  /** Determine the heading of the delete modal and opens the modal. */
  openDeleteConfirmationDialog(recurringOrder: RecurringOrder, modal: ModalDialogComponent<string>) {
    modal.options.titleText = this.translate.instant('account.recurring_order.delete_dialog.header', {
      0: recurringOrder.documentNo,
    });
    modal.show(recurringOrder.id);
  }
}