/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; import { DomSanitizer } from '@angular/platform-browser' ; import { MatDialog } from '@angular/material/dialog' ; /** Custom Dialogs */ import { UnassignStaffDialogComponent } from './custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component' ; import { UploadSignatureDialogComponent } from './custom-dialogs/upload-signature-dialog/upload-signature-dialog.component' ; import { ViewSignatureDialogComponent } from './custom-dialogs/view-signature-dialog/view-signature-dialog.component' ; import { DeleteSignatureDialogComponent } from './custom-dialogs/delete-signature-dialog/delete-signature-dialog.component' ; import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component' ; import { UploadImageDialogComponent } from './custom-dialogs/upload-image-dialog/upload-image-dialog.component' ; import { CaptureImageDialogComponent } from './custom-dialogs/capture-image-dialog/capture-image-dialog.component' ; /** Custom Services */ import { ClientsService } from '../clients.service' ; @ Component ( { selector : 'mifosx-clients-view' , templateUrl : './clients-view.component.html' , styleUrls : [ './clients-view.component.scss' ] } ) export class ClientsViewComponent implements OnInit { clientViewData : any ; clientDatatables : any ; clientImage : any ; clientTemplateData : any ; constructor ( private route , private router , private clientsService , private _sanitizer , public dialog ) { this . route . data . subscribe ( ( data ) => { this . clientViewData = data . clientViewData ; this . clientDatatables = data . clientDatatables ; this . clientTemplateData = data . clientTemplateData ; } ) ; } ngOnInit ( ) { this . clientsService . getClientProfileImage ( this . clientViewData . id ) . subscribe ( ( base64Image ) => { this . clientImage = this . _sanitizer . bypassSecurityTrustResourceUrl ( base64Image ) ; } , ( error ) => { } ) ; } param { string } name doAction ( name ) { switch ( name ) { case 'Assign Staff' : case 'Close' : case 'Survey' : case 'Reject' : case 'Activate' : case 'Withdraw' : case 'Update Default Savings' : case 'Transfer Client' : case 'Undo Transfer' : case 'Accept Transfer' : case 'Reject Transfer' : case 'Reactivate' : case 'Undo Rejection' : case 'Add Charge' : case 'Create Self Service User' : case 'Client Screen Reports' : this . router . navigate ( [ `actions/${ name }` ] , { relativeTo : this . route } ) ; break ; case 'Unassign Staff' : this . unassignStaff ( ) ; break ; case 'Delete' : this . deleteClient ( ) ; break ; case 'View Signature' : this . viewSignature ( ) ; break ; case 'Upload Signature' : this . uploadSignature ( ) ; break ; case 'Delete Signature' : this . deleteSignature ( ) ; break ; case 'Capture Image' : this . captureProfileImage ( ) ; break ; case 'Upload Image' : this . uploadProfileImage ( ) ; break ; case 'Delete Image' : this . deleteProfileImage ( ) ; break ; case 'Create Standing Instructions' : const createStandingInstructionsQueryParams = { officeId : this . clientViewData . officeId , accountType : 'fromsavings' } ; this . router . navigate ( [ 'standing-instructions/create-standing-instructions' ] , { relativeTo : this . route , queryParams : createStandingInstructionsQueryParams } ) ; break ; case 'View Standing Instructions' : const viewStandingInstructionsQueryParams = { officeId : this . clientViewData . officeId , accountType : 'fromsavings' } ; this . router . navigate ( [ 'standing-instructions/list-standing-instructions' ] , { relativeTo : this . route , queryParams : viewStandingInstructionsQueryParams } ) ; break ; } } /**
     * Refetches data for the component
     * TODO: Replace by a custom reload component instead of hard-coded back-routing.
     */ reload ( ) { const url = this . router . url ; this . router . navigateByUrl ( `/clients` , { skipLocationChange : true } ) . then ( ( ) => this . router . navigate ( [ url ] ) ) ; } /**
     * Deletes the client
     */ private deleteClient ( ) { const deleteClientDialogRef = this . dialog . open ( DeleteDialogComponent , { data : { deleteContext : `client with id: ${ this . clientViewData . id }` } } ) ; deleteClientDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . clientsService . deleteClient ( this . clientViewData . id ) . subscribe ( ( ) => { this . router . navigate ( [ '/clients' ] , { relativeTo : this . route } ) ; } ) ; } } ) ; } /**
     * Unassign's the client's staff.
     */ private unassignStaff ( ) { const unAssignStaffDialogRef = this . dialog . open ( UnassignStaffDialogComponent ) ; unAssignStaffDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . confirm ) { this . clientsService . executeClientCommand ( this . clientViewData . id , 'unassignStaff' , { staffId : this . clientViewData . staffId } ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } /**
     * Shows client signature in a dialog
     */ private viewSignature ( ) { this . clientsService . getClientDocuments ( this . clientViewData . id ) . subscribe ( ( documents ) => { const viewSignatureDialogRef = this . dialog . open ( ViewSignatureDialogComponent , { data : { documents : documents , id : this . clientViewData . id } } ) ; viewSignatureDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . upload ) { this . uploadSignature ( ) ; } else if ( response . delete ) { this . deleteSignature ( ) ; } } ) ; } ) ; } /**
     * Uploads client signature
     */ private uploadSignature ( ) { const uploadSignatureDialogRef = this . dialog . open ( UploadSignatureDialogComponent ) ; uploadSignatureDialogRef . afterClosed ( ) . subscribe ( ( signature ) => { if ( signature ) { this . clientsService . uploadClientSignatureImage ( this . clientViewData . id , signature ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } /**
     * Deletes client signature
     */ private deleteSignature ( ) { this . clientsService . getClientDocuments ( this . clientViewData . id ) . subscribe ( ( documents ) => { const deleteSignatureDialogRef = this . dialog . open ( DeleteSignatureDialogComponent , { data : documents } ) ; deleteSignatureDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . clientsService . deleteClientDocument ( this . clientViewData . id , response . id ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } else if ( response . upload ) { this . uploadSignature ( ) ; } } ) ; } ) ; } /**
     * Captures clients profile image.
     */ private captureProfileImage ( ) { const captureImageDialogRef = this . dialog . open ( CaptureImageDialogComponent ) ; captureImageDialogRef . afterClosed ( ) . subscribe ( ( imageURL ) => { if ( imageURL ) { this . clientsService . uploadCapturedClientProfileImage ( this . clientViewData . id , imageURL ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } /**
     * Uploads the clients image.
     */ private uploadProfileImage ( ) { const uploadImageDialogRef = this . dialog . open ( UploadImageDialogComponent ) ; uploadImageDialogRef . afterClosed ( ) . subscribe ( ( image ) => { if ( image ) { this . clientsService . uploadClientProfileImage ( this . clientViewData . id , image ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } /**
     * Deletes the client image.
     */ private deleteProfileImage ( ) { const deleteClientImageDialogRef = this . dialog . open ( DeleteDialogComponent , { data : { deleteContext : `the profile image of ${ this . clientViewData . displayName }` } } ) ; deleteClientImageDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . clientsService . deleteClientProfileImage ( this . clientViewData . id ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } }