/** Angular Imports */ import { Component , OnInit } from '@angular/core' ; import { MatDialog } from '@angular/material/dialog' ; import { DatePipe } from '@angular/common' ; import { ActivatedRoute , Router } from '@angular/router' ; import { FormControl } from '@angular/forms' ; /** Custom Services */ import { GroupsService } from 'app/groups/groups.service' ; import { SettingsService } from 'app/settings/settings.service' ; /** 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 { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base' ; /**
 * Group Attendance component.
 */ @ Component ( { selector : 'mifosx-group-attendance' , templateUrl : './group-attendance.component.html' , styleUrls : [ './group-attendance.component.scss' ] } ) export class GroupAttendanceComponent implements OnInit { /** Members data. */ membersData : any ; /** Group Data */ groupData : any ; /** Attendance Type Options */ attendanceTypeOptions : any ; /** Columns to be displayed in member's attendance table. */ displayedColumns : string [ ] = [ 'name' , 'attendance' ] ; /** Start Date Form Control */ meetingDate = new FormControl ( ) ; /** Meeting Dates Data */ meetingDates : any [ ] ; /** Data source for client members table. */ dataSource : { } [ ] ; param { ActivatedRoute } route param { DatePipe } datePipe param { Router } router param { GroupsService } groupsService param { MatDialog } dialog param { SettingsService } settingsService constructor ( private route , private datePipe , private router , private groupsService , public dialog , private settingsService ) { this . route . data . subscribe ( ( data ) => { this . groupData = data . groupActionData ; this . membersData = data . groupActionData . clientMembers ; } ) ; } /**
     * Sets the members table.
     */ ngOnInit ( ) { this . dataSource = this . membersData . map ( ( member ) => ( { clientId : member . id , attendanceType : 1 } ) ) ; this . meetingDates = this . groupData . collectionMeetingCalendar . recurringDates . filter ( ( date ) => new Date ( date ) . getTime ( ) < new Date ( ) . getTime ( ) ) ; this . getAttendanceOptions ( ) ; } /**
     * Gets attendance type options based on calendar id.
     */ getAttendanceOptions ( ) { this . groupsService . getMeetingsTemplate ( this . groupData . id , this . groupData . collectionMeetingCalendar . id ) . subscribe ( ( response ) => { this . attendanceTypeOptions = response . attendanceTypeOptions ; } ) ; } param { any } member editAttendance ( member ) { const formfields = [ new SelectBase ( { controlName : 'attendanceType' , label : 'Attendance' , value : member . attendanceType , options : { label : 'value' , value : 'id' , data : this . attendanceTypeOptions } , required : false } ) , ] ; const data = { title : 'Assign Member Attendance' , layout : { addButtonText : 'Confirm' } , formfields : formfields } ; const memberAttendanceDialogRef = this . dialog . open ( FormDialogComponent , { data } ) ; memberAttendanceDialogRef . afterClosed ( ) . subscribe ( ( response ) => { if ( response . data ) { const updatedMemeber = { ... member , ... response . data . value } ; this . dataSource . splice ( this . dataSource . indexOf ( member ) , 1 , updatedMemeber ) ; this . dataSource = this . dataSource . concat ( [ ] ) ; } } ) ; } /**
     * Assigns Client Members Attendance
     */ submit ( ) { const locale = this . settingsService . language . code ; const dateFormat = this . settingsService . dateFormat ; const prevMeetingDate = new Date ( this . meetingDate . value ) ; this . meetingDate . patchValue ( this . datePipe . transform ( prevMeetingDate , dateFormat ) ) ; const data = { meetingDate : this . meetingDate . value , calendarId : this . groupData . collectionMeetingCalendar . id , clientsAttendance : this . dataSource , dateFormat , locale } ; this . groupsService . assignGroupAttendance ( this . groupData . id , this . groupData . collectionMeetingCalendar . id , data ) . subscribe ( ( ) => { this . router . navigate ( [ '../../' ] , { relativeTo : this . route } ) ; } ) ; } }