/** Angular Imports */ import { Component } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; import { MatDialog } from '@angular/material/dialog' ; /** Custom Dialogs */ import { UnassignStaffDialogComponent } from './custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component' ; import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component' ; /** Custom Services */ import { GroupsService } from '../groups.service' ; /**
 * Groups View Component.
 */ @ Component ( { selector : 'mifosx-groups-view' , templateUrl : './groups-view.component.html' , styleUrls : [ './groups-view.component.scss' ] } ) export class GroupsViewComponent { /** Group view data */ groupViewData : any ; /** Group datatables data */ groupDatatables : any ; param { ActivatedRoute } route param { GroupsService } groupsService param { Router } router param { MatDialog } dialog constructor ( private route , private groupsService , private router , public dialog ) { this . route . data . subscribe ( ( data ) => { this . groupViewData = data . groupViewData ; this . groupDatatables = data . groupDatatables ; } ) ; } param { string } name doAction ( name ) { switch ( name ) { case 'Assign Staff' : case 'Close' : case 'Activate' : case 'Attach Meeting' : case 'Attendance' : case 'Manage Members' : case 'Transfer Clients' : this . router . navigate ( [ `actions/${ name }` ] , { relativeTo : this . route } ) ; break ; case 'Edit Meeting' : const queryParams = { calendarId : this . groupViewData . collectionMeetingCalendar . id } ; this . router . navigate ( [ `actions/${ name }` ] , { relativeTo : this . route , queryParams : queryParams } ) ; break ; case 'Edit' : this . router . navigate ( [ 'edit' ] , { relativeTo : this . route } ) ; break ; case 'Unassign Staff' : this . unassignStaff ( ) ; break ; case 'Delete' : this . deleteGroup ( ) ; break ; } } /**
     * Checks if meeting is editable.
     */ get editMeeting ( ) { if ( this . groupViewData . collectionMeetingCalendar ) { const entityType = this . groupViewData . collectionMeetingCalendar . entityType . value ; if ( entityType === 'GROUPS' && this . groupViewData . hierarchy === '.' + this . groupViewData . id + '.' ) { return true ; } } return false ; } /**
     * 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 ( `/groups` , { skipLocationChange : true } ) . then ( ( ) => this . router . navigate ( [ url ] ) ) ; } /**
     * Unassign's the group's staff.
     */ private unassignStaff ( ) { const unAssignStaffDialogRef = this . dialog . open ( UnassignStaffDialogComponent ) ; unAssignStaffDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . confirm ) { this . groupsService . executeGroupCommand ( this . groupViewData . id , 'unassignStaff' , { staffId : this . groupViewData . staffId } ) . subscribe ( ( ) => { this . reload ( ) ; } ) ; } } ) ; } /**
     * Deletes the group
     */ private deleteGroup ( ) { const deleteGroupDialogRef = this . dialog . open ( DeleteDialogComponent , { data : { deleteContext : `group with id: ${ this . groupViewData . id }` } } ) ; deleteGroupDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . delete ) { this . groupsService . deleteGroup ( this . groupViewData . id ) . subscribe ( ( ) => { this . router . navigate ( [ '/groups' ] , { relativeTo : this . route } ) ; } ) ; } } ) ; } }