/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; import { MatDialog } from '@angular/material/dialog' ; /** Dialog Imports */ import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component' ; /** Custom Services */ import { CentersService } from '../centers.service' ; import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component' ; /**
 * Create Center View
 */ @ Component ( { selector : 'mifosx-centers-view' , templateUrl : './centers-view.component.html' , styleUrls : [ './centers-view.component.scss' ] } ) export class CentersViewComponent implements OnInit { /** Stores Center View Data */ centerViewData : any ; /** Center datatable */ centerDatatables : any ; /** Meeting data */ meetingData : boolean ; param route constructor ( private route , private router , public dialog , public centersService ) { this . route . data . subscribe ( ( data ) => { this . centerViewData = data . centerViewData ; this . centerDatatables = data . centerDatatables ; } ) ; } ngOnInit ( ) { if ( this . centerViewData . collectionMeetingCalendar ) { this . meetingData = true ; } else { this . meetingData = false ; } } /**
     * Checks if meeting is editable.
     */ get editMeeting ( ) { if ( this . centerViewData . collectionMeetingCalendar ) { const entityType = this . centerViewData . collectionMeetingCalendar . entityType . value ; if ( entityType === 'CENTERS' && this . centerViewData . hierarchy === '.' + this . centerViewData . id + '.' ) { return true ; } } return false ; } param { string } name doAction ( name ) { switch ( name ) { case 'Activate' : case 'Assign Staff' : case 'Close' : case 'Attendance' : case 'Attach Meeting' : case 'Manage Groups' : case 'Staff Assignment History' : this . router . navigate ( [ `actions/${ name }` ] , { relativeTo : this . route } ) ; break ; case 'Edit Meeting' : const queryParams = { calendarId : this . centerViewData . collectionMeetingCalendar . id } ; this . router . navigate ( [ `actions/${ name }` ] , { relativeTo : this . route , queryParams : queryParams } ) ; break ; case 'Unassign Staff' : this . centersUnassignStaff ( ) ; break ; case 'Delete' : this . deleteCenter ( ) ; break ; case 'Edit' : this . router . navigate ( [ 'edit' ] , { relativeTo : this . route } ) ; } } /**
     * Unassign's the centers's staff.
     */ private centersUnassignStaff ( ) { const unAssignStaffDialogRef = this . dialog . open ( ConfirmationDialogComponent , { data : { heading : 'Unassign Staff' , dialogContext : 'Are you sure you want Unassign Staff' } } ) ; unAssignStaffDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . confirm ) { this . centersService . executeGroupActionCommand ( this . centerViewData . id , 'unassignStaff' , { staffId : this . centerViewData . staffId } ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } /**
     * Deletes the center
     */ private deleteCenter ( ) { const deleteGroupDialogRef = this . dialog . open ( DeleteDialogComponent , { data : { deleteContext : `center with id: ${ this . centerViewData . id }` } } ) ; deleteGroupDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . centersService . deleteCenter ( this . centerViewData . id ) . subscribe ( ( ) => { this . router . navigate ( [ '/centers' ] , { relativeTo : this . route } ) ; } ) ; } } ) ; } /**
     * 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 ( `/centers` , { skipLocationChange : true } ) . then ( ( ) => this . router . navigate ( [ url ] ) ) ; } }