feat: group actions (attach-meeting) (#1045)

Fixes: #1044
This commit is contained in:
Karan Takalkar
2020-07-09 13:30:05 +05:30
committed by GitHub
parent 2a129bc02a
commit 5d4f4ed14c
11 changed files with 264 additions and 3 deletions
@@ -32,6 +32,8 @@ export class GroupActionsResolver implements Resolve<Object> {
return this.groupsService.getGroupData(groupId, 'true');
case 'Close':
return this.groupsService.getGroupCommandTemplate('close');
case 'Attach Meeting':
return this.groupsService.getGroupCalendarTemplate(groupId);
default:
return undefined;
}
@@ -0,0 +1,74 @@
<div class="container">
<mat-card>
<form [formGroup]="groupMeetingForm">
<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="groupMeetingForm.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="groupMeetingForm.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="groupMeetingForm.controls.frequency.hasError('repeatsOnDay')">
Repetition Frequency is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="groupMeetingForm.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="groupMeetingForm.controls.interval.hasError('repeatsOnDay')">
Repeition Interval is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field *ngIf="groupMeetingForm.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="groupMeetingForm.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]="!groupMeetingForm.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 { AttachGroupMeetingComponent } from './attach-group-meeting.component';
describe('AttachGroupMeetingComponent', () => {
let component: AttachGroupMeetingComponent;
let fixture: ComponentFixture<AttachGroupMeetingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AttachGroupMeetingComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AttachGroupMeetingComponent);
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 { GroupsService } from 'app/groups/groups.service';
/**
* Group Meetings Component
*/
@Component({
selector: 'mifosx-attach-group-meeting',
templateUrl: './attach-group-meeting.component.html',
styleUrls: ['./attach-group-meeting.component.scss']
})
export class AttachGroupMeetingComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Group Meeting form. */
groupMeetingForm: FormGroup;
/** Calnedar Template Data */
calendarTemplate: any;
/** Group Id */
groupId: 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 {GroupsService} groupsService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.calendarTemplate = data.groupActionData;
this.frequencyOptions = this.calendarTemplate.frequencyOptions;
this.repeatsOnDays = this.calendarTemplate.repeatsOnDayOptions;
});
this.groupId = this.route.parent.snapshot.params['groupId'];
}
ngOnInit() {
this.createGroupMeetingForm();
this.buildDependencies();
}
/**
* Creates the Group Meeting form.
*/
createGroupMeetingForm() {
this.groupMeetingForm = this.formBuilder.group({
'startDate': ['', Validators.required],
'repeating': [false]
});
}
/**
* Subscribes to value changes of controls.
*/
buildDependencies() {
this.groupMeetingForm.get('repeating').valueChanges.subscribe((value: boolean) => {
if (value) {
this.groupMeetingForm.addControl('frequency', new FormControl());
this.groupMeetingForm.addControl('interval', new FormControl());
this.groupMeetingForm.get('frequency').valueChanges.subscribe((frequency: any) => {
this.groupMeetingForm.removeControl('repeatsOnDay');
switch (frequency) {
case 1: // Daily
this.repetitionIntervals = ['1', '2', '3'];
break;
case 2: // Weekly
this.repetitionIntervals = ['1', '2', '3'];
this.groupMeetingForm.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.groupMeetingForm.patchValue({
'frequency': 1,
'interval': '1'
});
} else {
this.groupMeetingForm.removeControl('frequency');
this.groupMeetingForm.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 = `groups_${this.groupId}_CollectionMeeting`;
const typeId = '1';
const prevStartDate: Date = this.groupMeetingForm.value.startDate;
this.groupMeetingForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
});
const data = {
...this.groupMeetingForm.value,
title,
typeId,
dateFormat,
locale
};
this.groupsService.createGroupMeeting(this.groupId, data).subscribe((response: any) => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -1,3 +1,4 @@
<mifosx-group-assign-staff *ngIf="actions['Assign Staff']"></mifosx-group-assign-staff>
<mifosx-close-group *ngIf="actions['Close']"></mifosx-close-group>
<mifosx-activate-group *ngIf="actions['Activate']"></mifosx-activate-group>
<mifosx-attach-group-meeting *ngIf="actions['Attach Meeting']"></mifosx-attach-group-meeting>
@@ -17,10 +17,12 @@ export class GroupActionsComponent {
'Assign Staff': boolean
'Close': boolean
'Activate': boolean
'Attach Meeting': boolean
} = {
'Assign Staff': false,
'Close': false,
'Activate': false
'Activate': false,
'Attach Meeting': false,
};
/**
@@ -84,7 +84,7 @@
<span *ngIf="groupViewData.staffId">
<button mat-menu-item *mifosxHasPermission="'UNASSIGNSTAFF_GROUP'" (click)="doAction('Unassign Staff')">Unassign Staff</button></span>
<span *ngIf="!(groupViewData.centerId || groupViewData.collectionMeetingCalendar) && groupViewData.status.value==='Active'">
<button mat-menu-item *mifosxHasPermission="'CREATE_MEETING'">Attatch Meeting</button></span>
<button mat-menu-item *mifosxHasPermission="'CREATE_MEETING'" (click)="doAction('Attach Meeting')">Attatch Meeting</button></span>
<button mat-menu-item *mifosxHasPermission="'CLOSE_GROUP'" (click)="doAction('Close')">Close</button>
<button mat-menu-item *mifosxHasPermission="'DELETE_GROUP'" (click)="doAction('Delete')">Delete</button>
</mat-menu>
@@ -48,6 +48,7 @@ export class GroupsViewComponent {
case 'Assign Staff':
case 'Close':
case 'Activate':
case 'Attach Meeting':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Edit':
+3 -1
View File
@@ -26,6 +26,7 @@ import { UnassignStaffDialogComponent } from './groups-view/custom-dialogs/unass
import { CloseGroupComponent } from './groups-view/group-actions/close-group/close-group.component';
import { ActivateGroupComponent } from './groups-view/group-actions/activate-group/activate-group.component';
import { EditGroupComponent } from './edit-group/edit-group.component';
import { AttachGroupMeetingComponent } from './groups-view/group-actions/attach-group-meeting/attach-group-meeting.component';
/**
* Groups Module
@@ -56,7 +57,8 @@ import { EditGroupComponent } from './edit-group/edit-group.component';
UnassignStaffDialogComponent,
CloseGroupComponent,
ActivateGroupComponent,
EditGroupComponent
EditGroupComponent,
AttachGroupMeetingComponent
],
entryComponents: [
UnassignRoleDialogComponent,
+16
View File
@@ -233,4 +233,20 @@ export class GroupsService {
return this.http.put(`/groups/${groupId}`, group);
}
/**
* @param {any} groupId Group Id
* @returns {Observable<any>}
*/
getGroupCalendarTemplate(groupId: any): Observable<any> {
return this.http.get(`/groups/${groupId}/calendars/template`);
}
/**
* @param {any} groupId Group Id
* @returns {Observable<any>}
*/
createGroupMeeting(groupId: any, data: any): Observable<any> {
return this.http.post(`/groups/${groupId}/calendars`, data);
}
}