/** Angular Imports */ import { Component , OnInit , ViewChild } from '@angular/core' ; import { ActivatedRoute } from '@angular/router' ; import { MatDialog } from '@angular/material/dialog' ; import { FormBuilder , Validators } from '@angular/forms' ; /** Custom Dialogs */ import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component' ; /** Custom Models */ import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base' ; import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base' ; /** Custom Services */ import { OrganizationService } from '../organization.service' ; /**
 * Manage Funds component.
 */ @ Component ( { selector : 'mifosx-manage-funds' , templateUrl : './manage-funds.component.html' , styleUrls : [ './manage-funds.component.scss' ] } ) export class ManageFundsComponent implements OnInit { /** Manage Funds data. */ fundsData : any ; /** New Fund form */ fundForm : any ; /** Funds form reference */ @ ViewChild ( 'formRef' ) formRef : any ; param { ActivatedRoute } route param { FormBuilder } formBuilder param { OrganizationService } organizationservice param { MatDialog } dialog constructor ( private route , private formBuilder , private organizationservice , public dialog ) { this . route . data . subscribe ( ( data ) => { this . fundsData = data . funds ; } ) ; } ngOnInit ( ) { this . createFundForm ( ) ; } /**
     * Creates the fund form.
     */ createFundForm ( ) { this . fundForm = this . formBuilder . group ( { 'name' : [ '' , Validators . required ] } ) ; } /**
     * Adds a new fund to the list.
     */ addFund ( ) { const newFund = this . fundForm . value ; this . organizationservice . createFund ( newFund ) . subscribe ( ( response ) => { this . fundsData . push ( { id : response . resourceId , name : newFund . name } ) ; this . formRef . resetForm ( ) ; } ) ; } param { string } fundId param { string } fundContent param { number } index editFund ( fundId , fundContent , index ) { const formfields = [ new InputBase ( { controlName : 'name' , label : 'Fund Content' , value : fundContent , type : 'text' , required : true } ) , ] ; const data = { title : 'Edit Fund' , layout : { addButtonText : 'Confirm' } , formfields : formfields } ; const editFundDialogRef = this . dialog . open ( FormDialogComponent , { data } ) ; editFundDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . data ) { this . organizationservice . editFund ( fundId , response . data . value ) . subscribe ( ( ) => { this . fundsData [ index ] . name = response . data . value . name ; } ) ; } } ) ; } }