feat: add centers action (edit-meeting) (#1099)

Fixes: #1098
This commit is contained in:
Muskan Khedia
2020-07-15 00:06:07 +05:30
committed by GitHub
parent 7a249fb257
commit f55aaa0133
15 changed files with 463 additions and 4 deletions
@@ -3,3 +3,5 @@
<mifosx-close-center *ngIf="actions['Close']"></mifosx-close-center>
<mifosx-center-attendance *ngIf="actions['Attendance']" ></mifosx-center-attendance>
<mifosx-attach-center-meeting *ngIf="actions['Attach Meeting']"></mifosx-attach-center-meeting>
<mifosx-edit-center-meeting *ngIf="actions['Edit Meeting']"></mifosx-edit-center-meeting>
<mifosx-edit-center-meeting-schedule *ngIf="actions['Edit Meeting Schedule']"></mifosx-edit-center-meeting-schedule>
@@ -18,13 +18,17 @@ export class CenterActionsComponent {
'Assign Staff': boolean,
'Close': boolean,
'Attendance': boolean,
'Attach Meeting': boolean
'Attach Meeting': boolean,
'Edit Meeting': boolean,
'Edit Meeting Schedule': boolean
} = {
'Activate': false,
'Assign Staff': false,
'Close': false,
'Attendance': false,
'Attach Meeting': false
'Attach Meeting': false,
'Edit Meeting': false,
'Edit Meeting Schedule': false
};
/**
@@ -0,0 +1,46 @@
<div class="container">
<mat-card>
<form [formGroup]="centerEditMeetingScheduleForm">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Existing Meeting Date</mat-label>
<mat-select formControlName="presentMeetingDate">
<mat-option *ngFor="let date of nextMeetingDates" [value]="date">
{{ date | date }}
</mat-option>
</mat-select>
<mat-error *ngIf="centerEditMeetingScheduleForm.controls.presentMeetingDate.hasError('repeatsOnDay')">
Existing Meeting Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Revised Meeting Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="newMeetingDatePicker" required formControlName="newMeetingDate">
<mat-datepicker-toggle matSuffix [for]="newMeetingDatePicker"></mat-datepicker-toggle>
<mat-datepicker #newMeetingDatePicker></mat-datepicker>
<mat-error *ngIf="centerEditMeetingScheduleForm.controls.newMeetingDate.hasError('required')">
Revised Meeting Date is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!centerEditMeetingScheduleForm.valid" (click)="submit()">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditCenterMeetingScheduleComponent } from './edit-center-meeting-schedule.component';
describe('EditCenterMeetingScheduleComponent', () => {
let component: EditCenterMeetingScheduleComponent;
let fixture: ComponentFixture<EditCenterMeetingScheduleComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditCenterMeetingScheduleComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditCenterMeetingScheduleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,95 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
/**
* Edit Center Meetings Schedule Component
*/
@Component({
selector: 'mifosx-edit-center-meeting-schedule',
templateUrl: './edit-center-meeting-schedule.component.html',
styleUrls: ['./edit-center-meeting-schedule.component.scss']
})
export class EditCenterMeetingScheduleComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Center Meeting form. */
centerEditMeetingScheduleForm: FormGroup;
/** Calendar Template Data */
calendarTemplate: any;
/** Center Id */
centerId: any;
/** CalendarI ID */
calendarId: any;
/** Next meetings data */
nextMeetingDates: any;
/**
* Fetches Calendar Template from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centersActionData: any }) => {
this.calendarTemplate = data.centersActionData;
this.nextMeetingDates = this.calendarTemplate.nextTenRecurringDates;
});
this.calendarId = this.route.snapshot.queryParams['calendarId'];
this.centerId = this.route.parent.snapshot.params['centerId'];
}
ngOnInit() {
this.createEditMeetingScheduleForm();
}
/**
* Creates the Edit Center Meeting Schedule form.
*/
createEditMeetingScheduleForm() {
this.centerEditMeetingScheduleForm = this.formBuilder.group({
'presentMeetingDate': ['', Validators.required],
'newMeetingDate': ['', Validators.required]
});
}
/**
* Submits the form and updates the meeting.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const reschedulebasedOnMeetingDates = true;
const prevOldDate: Date = new Date(this.centerEditMeetingScheduleForm.value.presentMeetingDate);
const prevNewDate: Date = this.centerEditMeetingScheduleForm.value.newMeetingDate;
this.centerEditMeetingScheduleForm.patchValue({
'presentMeetingDate': this.datePipe.transform(prevOldDate, dateFormat),
'newMeetingDate': this.datePipe.transform(prevNewDate, dateFormat)
});
const data = {
...this.centerEditMeetingScheduleForm.value,
reschedulebasedOnMeetingDates,
dateFormat,
locale
};
this.centersService.updateCenterMeeting(this.centerId, data, this.calendarId).subscribe((response: any) => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -0,0 +1,81 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end">
<button mat-raised-button color="primary" (click)="editSchedule()">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit Schedule
</button>
</div>
<div class="container">
<mat-card>
<form [formGroup]="centerEditMeetingForm">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Repetition Frequency</mat-label>
<mat-select formControlName="frequency">
<mat-option *ngFor="let option of frequencyOptions" [value]="option.id">
{{ option.value }}
</mat-option>
</mat-select>
<mat-error *ngIf="centerEditMeetingForm.controls.frequency.hasError('repeatsOnDay')">
Repetition Frequency is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Repetition Interval</mat-label>
<mat-select formControlName="interval">
<mat-option *ngFor="let interval of repetitionIntervals" [value]="interval">
{{ interval }}
</mat-option>
</mat-select>
<mat-error *ngIf="centerEditMeetingForm.controls.interval.hasError('repeatsOnDay')">
Repeition Interval is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="centerEditMeetingForm.contains('repeatsOnDay')">
<mat-label>Repeats on Day</mat-label>
<mat-select formControlName="repeatsOnDay" required>
<mat-option *ngFor="let day of repeatsOnDays" [value]="day.id">
{{ day.value }}
</mat-option>
</mat-select>
<mat-error *ngIf="centerEditMeetingForm.controls.repeatsOnDay.hasError('repeatsOnDay')">
At least <strong>one</strong> day must be selected
</mat-error>
</mat-form-field>
<mat-form-field class="m-b-5">
<mat-label>Above Changes are Effective from</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="startDatePicker" required formControlName="startDate">
<mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
<mat-datepicker #startDatePicker></mat-datepicker>
<mat-error *ngIf="centerEditMeetingForm.controls.startDate.hasError('required')">
Changes Affection Date is <strong>required</strong>
</mat-error>
<mat-hint>
Note: 'Repeats' and 'Repeats every' cannot not be modified if there are active accounts <br>
(JLG Loans, Recurring Deposits etc) dependent on this meeting.
</mat-hint>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="!centerEditMeetingForm.valid" (click)="submit()">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditCenterMeetingComponent } from './edit-center-meeting.component';
describe('EditCenterMeetingComponent', () => {
let component: EditCenterMeetingComponent;
let fixture: ComponentFixture<EditCenterMeetingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditCenterMeetingComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditCenterMeetingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,141 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
/**
* Edit Center Meetings Component
*/
@Component({
selector: 'mifosx-edit-center-meeting',
templateUrl: './edit-center-meeting.component.html',
styleUrls: ['./edit-center-meeting.component.scss']
})
export class EditCenterMeetingComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Center Meeting form. */
centerEditMeetingForm: FormGroup;
/** Calendar Template Data */
calendarTemplate: any;
/** Center Id */
centerId: any;
/** Repetition Intervals */
repetitionIntervals: any[];
/** Frequency Options */
frequencyOptions: any;
/** Repetition Days Data */
repeatsOnDays: any;
/** CalendarI ID */
calendarId: any;
/**
* Fetches Calendar Template from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centersActionData: any }) => {
this.calendarTemplate = data.centersActionData;
this.frequencyOptions = this.calendarTemplate.frequencyOptions;
this.repeatsOnDays = this.calendarTemplate.repeatsOnDayOptions;
});
this.calendarId = this.route.snapshot.queryParams['calendarId'];
this.centerId = this.route.parent.snapshot.params['centerId'];
}
ngOnInit() {
this.createEditCenterMeetingForm();
this.buildDependencies();
}
/**
* Creates the Edit Center Meeting form.
*/
createEditCenterMeetingForm() {
this.centerEditMeetingForm = this.formBuilder.group({
'startDate': ['', Validators.required],
'frequency': ['', Validators.required],
'interval': ['', Validators.required]
});
}
/**
* Subscribes to value changes of controls.
*/
buildDependencies() {
this.centerEditMeetingForm.get('frequency').valueChanges.subscribe((frequency: any) => {
this.centerEditMeetingForm.removeControl('repeatsOnDay');
switch (frequency) {
case 1: // Daily
this.repetitionIntervals = ['1', '2', '3'];
break;
case 2: // Weekly
this.repetitionIntervals = ['1', '2', '3'];
this.centerEditMeetingForm.addControl('repeatsOnDay', new FormControl('', Validators.required));
this.centerEditMeetingForm.get('repeatsOnDay').patchValue(this.calendarTemplate.repeatsOnDay.id);
break;
case 3: // Monthly
this.repetitionIntervals = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'];
break;
case 4: // Yearly
this.repetitionIntervals = ['1', '2', '3', '4', '5'];
break;
}
});
this.centerEditMeetingForm.patchValue({
'startDate': this.calendarTemplate.startDate && new Date(this.calendarTemplate.startDate),
'frequency': this.calendarTemplate.frequency.id,
'interval': `${this.calendarTemplate.interval}`
});
}
/**
* Navigate to edit meeting schedule form.
*/
editSchedule() {
const queryParams: any = { calendarId: this.calendarId };
this.router.navigate([`../Edit Meeting Schedule`], { relativeTo: this.route, queryParams: queryParams });
}
/**
* Submits the form and updates the meeting.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const title = `centers_${this.centerId}_CollectionMeeting`;
const typeId = '1';
const prevStartDate: Date = this.centerEditMeetingForm.value.startDate;
this.centerEditMeetingForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
});
const data = {
...this.centerEditMeetingForm.value,
repeating: true,
title,
typeId,
dateFormat,
locale
};
this.centersService.updateCenterMeeting(this.centerId, data, this.calendarId).subscribe((response: any) => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -39,7 +39,7 @@
<div *ngIf="centerViewData.collectionMeetingCalendar; else unassigned">
<p>
Next Meeting on: {{centerViewData.collectionMeetingCalendar?.nextTenRecurringDates[0] | date}}
<i class="fa fa-edit"></i><br/>
<i class="fa fa-edit" *ngIf="editMeeting" (click)="doAction('Edit Meeting')"></i><br/>
Meeting Frequency: {{centerViewData.collectionMeetingCalendar?.frequency.value | lowercase}}
</p>
</div>
@@ -50,6 +50,19 @@ export class CentersViewComponent implements OnInit {
} 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;
}
/**
* Performs action button/option action.
* @param {string} name action name.
@@ -63,6 +76,10 @@ export class CentersViewComponent implements OnInit {
case 'Attach Meeting':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Edit Meeting':
const queryParams: any = { calendarId: this.centerViewData.collectionMeetingCalendar.id };
this.router.navigate([`actions/${name}`], { relativeTo: this.route, queryParams: queryParams });
break;
case 'Unassign Staff':
this.centersUnassignStaff();
break;
+5 -1
View File
@@ -22,6 +22,8 @@ import { CenterAssignStaffComponent } from './centers-view/center-actions/center
import { CloseCenterComponent } from './centers-view/center-actions/close-center/close-center.component';
import { CenterAttendanceComponent } from './centers-view/center-actions/center-attendance/center-attendance.component';
import { AttachCenterMeetingComponent } from './centers-view/center-actions/attach-center-meeting/attach-center-meeting.component';
import { EditCenterMeetingComponent } from './centers-view/center-actions/edit-center-meeting/edit-center-meeting.component';
import { EditCenterMeetingScheduleComponent } from './centers-view/center-actions/edit-center-meeting-schedule/edit-center-meeting-schedule.component';
/**
* Centers Module
@@ -49,7 +51,9 @@ import { AttachCenterMeetingComponent } from './centers-view/center-actions/atta
CenterAssignStaffComponent,
CloseCenterComponent,
CenterAttendanceComponent,
AttachCenterMeetingComponent
AttachCenterMeetingComponent,
EditCenterMeetingComponent,
EditCenterMeetingScheduleComponent
]
})
export class CentersModule { }
+9
View File
@@ -236,4 +236,13 @@ export class CentersService {
return this.http.post(`/centers/${centerId}/calendars`, data);
}
getCalendarAndTemplate(centerId: any, calendarId: any): Observable<any> {
const httpParams = new HttpParams().set('template', 'true');
return this.http.get(`/centers/${centerId}/calendars/${calendarId}`, { params: httpParams });
}
updateCenterMeeting(centerId: any, data: any, calendarId: any): Observable<any> {
return this.http.put(`/centers/${centerId}/calendars/${calendarId}`, data);
}
}
@@ -34,6 +34,10 @@ export class CenterActionsResolver implements Resolve<Object> {
return this.centersService.getCentersData(centerId);
case 'Attach Meeting':
return this.centersService.getCalendarTemplate(centerId);
case 'Edit Meeting':
case 'Edit Meeting Schedule':
const calendarId = route.queryParamMap.get('calendarId');
return this.centersService.getCalendarAndTemplate(centerId, calendarId);
default:
return undefined;
}