diff --git a/src/app/groups/common-resolvers/group-actions.resolver.ts b/src/app/groups/common-resolvers/group-actions.resolver.ts index 357d65b4b..2d5461227 100644 --- a/src/app/groups/common-resolvers/group-actions.resolver.ts +++ b/src/app/groups/common-resolvers/group-actions.resolver.ts @@ -32,6 +32,8 @@ export class GroupActionsResolver implements Resolve { return this.groupsService.getGroupData(groupId, 'true'); case 'Close': return this.groupsService.getGroupCommandTemplate('close'); + case 'Attach Meeting': + return this.groupsService.getGroupCalendarTemplate(groupId); default: return undefined; } diff --git a/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.html b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.html new file mode 100644 index 000000000..efbbee406 --- /dev/null +++ b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.html @@ -0,0 +1,74 @@ +
+ + + +
+ + + +
+ + + Meeting Start Date + + + + + Start Date is required + + + + + Repeats? + + + + Repetition Frequency + + + {{ option.value }} + + + + Repetition Frequency is required + + + + + Repetition Interval + + + {{ interval }} + + + + Repeition Interval is required + + + + + Repeats on Day + + + {{ day.value }} + + + + At least one day must be selected + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.scss b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.spec.ts b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.spec.ts new file mode 100644 index 000000000..78ea9ef05 --- /dev/null +++ b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AttachGroupMeetingComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AttachGroupMeetingComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.ts b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.ts new file mode 100644 index 000000000..fd12fe3b4 --- /dev/null +++ b/src/app/groups/groups-view/group-actions/attach-group-meeting/attach-group-meeting.component.ts @@ -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 }); + }); + } + +} diff --git a/src/app/groups/groups-view/group-actions/group-actions.component.html b/src/app/groups/groups-view/group-actions/group-actions.component.html index a88f23d75..8cca9392b 100644 --- a/src/app/groups/groups-view/group-actions/group-actions.component.html +++ b/src/app/groups/groups-view/group-actions/group-actions.component.html @@ -1,3 +1,4 @@ + diff --git a/src/app/groups/groups-view/group-actions/group-actions.component.ts b/src/app/groups/groups-view/group-actions/group-actions.component.ts index b73a5dc0b..f10016121 100644 --- a/src/app/groups/groups-view/group-actions/group-actions.component.ts +++ b/src/app/groups/groups-view/group-actions/group-actions.component.ts @@ -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, }; /** diff --git a/src/app/groups/groups-view/groups-view.component.html b/src/app/groups/groups-view/groups-view.component.html index b5ee58ea3..6aec9d8ac 100644 --- a/src/app/groups/groups-view/groups-view.component.html +++ b/src/app/groups/groups-view/groups-view.component.html @@ -84,7 +84,7 @@ - + diff --git a/src/app/groups/groups-view/groups-view.component.ts b/src/app/groups/groups-view/groups-view.component.ts index f70137944..4cb2d8baa 100644 --- a/src/app/groups/groups-view/groups-view.component.ts +++ b/src/app/groups/groups-view/groups-view.component.ts @@ -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': diff --git a/src/app/groups/groups.module.ts b/src/app/groups/groups.module.ts index 1e870023c..03e40e75f 100644 --- a/src/app/groups/groups.module.ts +++ b/src/app/groups/groups.module.ts @@ -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, diff --git a/src/app/groups/groups.service.ts b/src/app/groups/groups.service.ts index b00825f19..4113842ca 100644 --- a/src/app/groups/groups.service.ts +++ b/src/app/groups/groups.service.ts @@ -233,4 +233,20 @@ export class GroupsService { return this.http.put(`/groups/${groupId}`, group); } + /** + * @param {any} groupId Group Id + * @returns {Observable} + */ + getGroupCalendarTemplate(groupId: any): Observable { + return this.http.get(`/groups/${groupId}/calendars/template`); + } + + /** + * @param {any} groupId Group Id + * @returns {Observable} + */ + createGroupMeeting(groupId: any, data: any): Observable { + return this.http.post(`/groups/${groupId}/calendars`, data); + } + }