feat: add centers action (attach meeting) (#1097)

Fixes: #1096
This commit is contained in:
Muskan Khedia
2020-07-14 22:39:40 +05:30
committed by GitHub
parent 33a0045b10
commit 7a249fb257
12 changed files with 289 additions and 18 deletions
@@ -0,0 +1,74 @@
<div class="container">
<mat-card>
<form [formGroup]="centerMeetingForm">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Meeting Start Date</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="centerMeetingForm.controls.startDate.hasError('required')">
Start Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-checkbox class="m-t-10 m-b-10" labelPosition="before" formControlName="repeating">
Repeats?
</mat-checkbox>
<mat-form-field *ngIf="centerMeetingForm.contains('frequency')">
<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="centerMeetingForm.controls.frequency.hasError('repeatsOnDay')">
Repetition Frequency is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="centerMeetingForm.contains('interval')">
<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="centerMeetingForm.controls.interval.hasError('repeatsOnDay')">
Repeition Interval is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="centerMeetingForm.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="centerMeetingForm.controls.repeatsOnDay.hasError('repeatsOnDay')">
At least <strong>one</strong> day must be selected
</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]="!centerMeetingForm.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 { AttachCenterMeetingComponent } from './attach-center-meeting.component';
describe('AttachCenterMeetingComponent', () => {
let component: AttachCenterMeetingComponent;
let fixture: ComponentFixture<AttachCenterMeetingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AttachCenterMeetingComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AttachCenterMeetingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,135 @@
/** 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';
/**
* Center Meetings Component
*/
@Component({
selector: 'mifosx-attach-center-meeting',
templateUrl: './attach-center-meeting.component.html',
styleUrls: ['./attach-center-meeting.component.scss']
})
export class AttachCenterMeetingComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Center Meeting form. */
centerMeetingForm: FormGroup;
/** Calnedar Template Data */
calendarTemplate: any;
/** Center Id */
centerId: any;
/** Repetition Intervals */
repetitionIntervals: any[];
/** Frequency Options */
frequencyOptions: any;
/** Repetition Days Data */
repeatsOnDays: 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.centerId = this.route.parent.snapshot.params['centerId'];
}
ngOnInit() {
this.createCenterMeetingForm();
this.buildDependencies();
}
/**
* Creates the Center Meeting form.
*/
createCenterMeetingForm() {
this.centerMeetingForm = this.formBuilder.group({
'startDate': ['', Validators.required],
'repeating': [false]
});
}
/**
* Subscribes to value changes of controls.
*/
buildDependencies() {
this.centerMeetingForm.get('repeating').valueChanges.subscribe((value: boolean) => {
if (value) {
this.centerMeetingForm.addControl('frequency', new FormControl());
this.centerMeetingForm.addControl('interval', new FormControl());
this.centerMeetingForm.get('frequency').valueChanges.subscribe((frequency: any) => {
this.centerMeetingForm.removeControl('repeatsOnDay');
switch (frequency) {
case 1: // Daily
this.repetitionIntervals = ['1', '2', '3'];
break;
case 2: // Weekly
this.repetitionIntervals = ['1', '2', '3'];
this.centerMeetingForm.addControl('repeatsOnDay', new FormControl('', Validators.required));
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.centerMeetingForm.patchValue({
'frequency': 1,
'interval': '1'
});
} else {
this.centerMeetingForm.removeControl('frequency');
this.centerMeetingForm.removeControl('interval');
}
});
}
/**
* Submits the form and attatches 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.centerMeetingForm.value.startDate;
this.centerMeetingForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
});
const data = {
...this.centerMeetingForm.value,
title,
typeId,
dateFormat,
locale
};
this.centersService.createCenterMeeting(this.centerId, data).subscribe((response: any) => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -2,3 +2,4 @@
<mifosx-center-assign-staff *ngIf="actions['Assign Staff']" ></mifosx-center-assign-staff>
<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>
@@ -17,12 +17,14 @@ export class CenterActionsComponent {
'Activate': boolean,
'Assign Staff': boolean,
'Close': boolean,
'Attendance': boolean
'Attendance': boolean,
'Attach Meeting': boolean
} = {
'Activate': false,
'Assign Staff': false,
'Close': false,
'Attendance': false
'Attendance': false,
'Attach Meeting': false
};
/**
@@ -31,23 +31,29 @@
{{(centerViewData.activationDate)?(centerViewData.activationDate|date) :'Not Activated'}}<br />
</p>
</div>
<div fxFlex="50%">
<p class="meetingDetails">
Next Meeting On:
<span *ngIf="meetingData">
{{centerViewData.collectionMeetingCalendar.nextTenRecurringDates[0]|date}}
<span *ngIf="centerViewData.collectionMeetingCalendar">
<a href="#" *mifosxHasPermission="'UPDATE_MEETING'"> <i class="fa fa-edit" style="color:#ffffff; padding: 5px;"></i> </a>
</span> <br/>
<span *ngIf="centerViewData.collectionMeetingCalendar.humanReadable"> Meeting Frequency: {{centerViewData.collectionMeetingCalendar.humanReadable}} </span>
</span>
<span *ngIf="!(meetingData)"> Unassigned </span><br/>
<span *ngIf="centerViewData.status.value === 'Closed'"> Closed Date: {{centerViewData.timeline.closedOnDate|date}}</span>
</p>
</div>
</div>
</mat-card-subtitle>
</div>
<div class="center-meeting" fxLayoutAlign="start start">
<div *ngIf="centerViewData.collectionMeetingCalendar; else unassigned">
<p>
Next Meeting on: {{centerViewData.collectionMeetingCalendar?.nextTenRecurringDates[0] | date}}
<i class="fa fa-edit"></i><br/>
Meeting Frequency: {{centerViewData.collectionMeetingCalendar?.frequency.value | lowercase}}
</p>
</div>
<ng-template #unassigned>
<div>
<p>
Next Meeting on: Unassigned
<i class="fa fa-calendar"></i><br/>
Meeting Frequency: N/A
</p>
</div>
</ng-template>
</div>
</mat-card-title-group>
<mat-card-actions class="center-actions" *ngIf="!(centerViewData.status.value==='Closed')">
<span *ngIf="!(centerViewData.status.value=='Active')">
@@ -75,7 +81,7 @@
</span>
<button mat-menu-item *mifosxHasPermission="'CLOSE_CENTER'" (click)="doAction('Close')"> Close </button>
<span *ngIf="centerViewData.status.value==='Active' && !(centerViewData.collectionMeetingCalendar)">
<button mat-menu-item *mifosxHasPermission="'CREATE_MEETING'"> Attach Meeting </button>
<button mat-menu-item *mifosxHasPermission="'CREATE_MEETING'" (click)="doAction('Attach Meeting')"> Attach Meeting </button>
</span>
<button mat-menu-item *mifosxHasPermission="'READ_Staff Assignment History'" > Staff Assignment History </button>
</mat-menu>
@@ -21,6 +21,18 @@
border-radius: 20px;
}
}
.center-meeting {
align-self: flex-end;
width: 300px;
height: 140px;
div, ng-template > div {
background-color: #0a6aac;
p {
color: white;
padding: 0 10px;
}
}
}
.center-actions {
align-self: flex-end;
margin: 0 1%;
@@ -60,6 +60,7 @@ export class CentersViewComponent implements OnInit {
case 'Assign Staff':
case 'Close':
case 'Attendance':
case 'Attach Meeting':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+3 -1
View File
@@ -21,6 +21,7 @@ import { ActivateCenterComponent } from './centers-view/center-actions/activate-
import { CenterAssignStaffComponent } from './centers-view/center-actions/center-assign-staff/center-assign-staff.component';
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';
/**
* Centers Module
@@ -47,7 +48,8 @@ import { CenterAttendanceComponent } from './centers-view/center-actions/center-
ActivateCenterComponent,
CenterAssignStaffComponent,
CloseCenterComponent,
CenterAttendanceComponent
CenterAttendanceComponent,
AttachCenterMeetingComponent
]
})
export class CentersModule { }
+8
View File
@@ -228,4 +228,12 @@ export class CentersService {
return this.http.post(`/centers/${centerId}/meetings`, data, {params: httpParams});
}
getCalendarTemplate(centerId: any): Observable<any> {
return this.http.get(`/centers/${centerId}/calendars/template`);
}
createCenterMeeting(centerId: any, data: any): Observable<any> {
return this.http.post(`/centers/${centerId}/calendars`, data);
}
}
@@ -32,6 +32,8 @@ export class CenterActionsResolver implements Resolve<Object> {
return this.centersService.getGroupStaffData(centerId);
case 'Attendance':
return this.centersService.getCentersData(centerId);
case 'Attach Meeting':
return this.centersService.getCalendarTemplate(centerId);
default:
return undefined;
}