/** Angular Imports */ import { Component , OnInit , ViewChild } from '@angular/core' ; import { MatDialog } from '@angular/material/dialog' ; import { MatPaginator } from '@angular/material/paginator' ; import { MatSort } from '@angular/material/sort' ; import { MatTableDataSource } from '@angular/material/table' ; import { ActivatedRoute } from '@angular/router' ; /** rxjs Imports */ import { of } from 'rxjs' ; /** Custom Services */ import { OrganizationService } from '../organization.service' ; /** Custom Components */ import { DeleteDialogComponent } from '../../shared/delete-dialog/delete-dialog.component' ; /**
 * Payment Types component.
 */ @ Component ( { selector : 'mifosx-payment-types' , templateUrl : './payment-types.component.html' , styleUrls : [ './payment-types.component.scss' ] } ) export class PaymentTypesComponent implements OnInit { /** Payment Types data. */ paymentTypesData : any ; /** Columns to be displayed in payment types table. */ displayedColumns : string [ ] = [ 'name' , 'description' , 'isCashPayment' , 'position' , 'actions' ] ; /** Data source for payment types table. */ dataSource : MatTableDataSource < any > ; /** Paginator for payment types table. */ @ ViewChild ( MatPaginator , { static : true } ) paginator : MatPaginator ; /** Sorter for payment types table. */ @ ViewChild ( MatSort , { static : true } ) sort : MatSort ; param { OrganizationService } organizationService param { ActivatedRoute } route param { MatDialog } dialog constructor ( private organizationService , private route , private dialog ) { this . route . data . subscribe ( ( data ) => { this . paymentTypesData = data . paymentTypes ; } ) ; } param { string } filterValue applyFilter ( filterValue ) { this . dataSource . filter = filterValue . trim ( ) . toLowerCase ( ) ; } /**
     * Sets the payment types table.
     */ ngOnInit ( ) { this . setPaymentTypes ( ) ; } /**
     * Initializes the data source, paginator and sorter for payment types table.
     */ setPaymentTypes ( ) { this . dataSource = new MatTableDataSource ( this . paymentTypesData ) ; this . dataSource . paginator = this . paginator ; this . dataSource . sort = this . sort ; } param { string } paymentTypeId deletePaymentType ( paymentTypeId ) { const deletePaymentTypeDialogRef = this . dialog . open ( DeleteDialogComponent , { data : { deleteContext : `payment type ${ paymentTypeId }` } } ) ; deletePaymentTypeDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . organizationService . deletePaymentType ( paymentTypeId ) . subscribe ( ( ) => { this . paymentTypesData = this . paymentTypesData . filter ( ( paymentType ) => paymentType . id !== paymentTypeId ) ; this . setPaymentTypes ( ) ; } ) ; } } ) ; } }