import { Component , OnInit , Input } from '@angular/core' ; import { MatDialog } from '@angular/material/dialog' ; import { FormControl } from '@angular/forms' ; import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component' ; @ Component ( { selector : 'mifosx-fixed-deposit-product-charges-step' , templateUrl : './fixed-deposit-product-charges-step.component.html' , styleUrls : [ './fixed-deposit-product-charges-step.component.scss' ] } ) export class FixedDepositProductChargesStepComponent implements OnInit { @ Input ( ) fixedDepositProductsTemplate : any ; @ Input ( ) currencyCode : FormControl ; chargeData : any ; chargesDataSource : { } [ ] ; displayedColumns : string [ ] = [ 'name' , 'chargeCalculationType' , 'amount' , 'chargeTimeType' , 'action' ] ; constructor ( public dialog ) { } ngOnInit ( ) { this . chargeData = this . fixedDepositProductsTemplate . chargeOptions ; if ( ! ( this . fixedDepositProductsTemplate === undefined ) && this . fixedDepositProductsTemplate . id ) { this . chargesDataSource = this . fixedDepositProductsTemplate . charges ; } else { this . chargesDataSource = [ ] ; } this . currencyCode . valueChanges . subscribe ( ( ) => this . chargesDataSource = [ ] ) ; } addCharge ( charge ) { this . chargesDataSource = this . chargesDataSource . concat ( [ charge . value ] ) ; charge . value = '' ; } deleteCharge ( charge ) { const deleteChargeDialogRef = this . dialog . open ( DeleteDialogComponent , { data : { deleteContext : `charge ${ charge . name }` } } ) ; deleteChargeDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . chargesDataSource . splice ( this . chargesDataSource . indexOf ( charge ) , 1 ) ; this . chargesDataSource = this . chargesDataSource . concat ( [ ] ) ; } } ) ; } get fixedDepositProductCharges ( ) { return { charges : this . chargesDataSource } ; } }