diff --git a/src/app/groups/common-resolvers/group-actions.resolver.ts b/src/app/groups/common-resolvers/group-actions.resolver.ts index 7fd402d22..8e000d253 100644 --- a/src/app/groups/common-resolvers/group-actions.resolver.ts +++ b/src/app/groups/common-resolvers/group-actions.resolver.ts @@ -37,6 +37,9 @@ export class GroupActionsResolver implements Resolve { return this.groupsService.getGroupCommandTemplate('close'); case 'Attach Meeting': return this.groupsService.getGroupCalendarTemplate(groupId); + case 'Edit Meeting': + const calendarId = route.queryParamMap.get('calendarId'); + return this.groupsService.getGroupCalendarAndTemplate(groupId, calendarId); default: return undefined; } diff --git a/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.html b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.html new file mode 100644 index 000000000..b2dcf4fce --- /dev/null +++ b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.html @@ -0,0 +1,74 @@ +
+ + + +
+ + + +
+ + + 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 + + + + + Above Changes are Effective from + + + + + Changes Affection Date is required + + + Note: 'Repeats' and 'Repeats every' cannot not be modified if there are active accounts
+ (JLG Loans, Recurring Deposits etc) dependent on this meeting. +
+
+ +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.scss b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.spec.ts b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.spec.ts new file mode 100644 index 000000000..8bc2fdb0a --- /dev/null +++ b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { EditGroupMeetingComponent } from './edit-group-meeting.component'; + +describe('EditGroupMeetingComponent', () => { + let component: EditGroupMeetingComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditGroupMeetingComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditGroupMeetingComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.ts b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.ts new file mode 100644 index 000000000..4986c6be6 --- /dev/null +++ b/src/app/groups/groups-view/group-actions/edit-group-meeting/edit-group-meeting.component.ts @@ -0,0 +1,132 @@ +/** 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'; + +/** + * Edit Group Meetings Component + */ +@Component({ + selector: 'mifosx-edit-group-meeting', + templateUrl: './edit-group-meeting.component.html', + styleUrls: ['./edit-group-meeting.component.scss'] +}) +export class EditGroupMeetingComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Group Meeting form. */ + groupEditMeetingForm: FormGroup; + /** Calnedar Template Data */ + calendarTemplate: any; + /** Group Id */ + groupId: 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 {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.calendarId = this.route.snapshot.queryParams['calendarId']; + this.groupId = this.route.parent.snapshot.params['groupId']; + } + + ngOnInit() { + this.createEditGroupMeetingForm(); + this.buildDependencies(); + } + + /** + * Creates the Edit Group Meeting form. + */ + createEditGroupMeetingForm() { + this.groupEditMeetingForm = this.formBuilder.group({ + 'startDate': ['', Validators.required], + 'frequency': ['', Validators.required], + 'interval': ['', Validators.required] + }); + } + + /** + * Subscribes to value changes of controls. + */ + buildDependencies() { + this.groupEditMeetingForm.get('frequency').valueChanges.subscribe((frequency: any) => { + this.groupEditMeetingForm.removeControl('repeatsOnDay'); + switch (frequency) { + case 1: // Daily + this.repetitionIntervals = ['1', '2', '3']; + break; + case 2: // Weekly + this.repetitionIntervals = ['1', '2', '3']; + this.groupEditMeetingForm.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.groupEditMeetingForm.patchValue({ + 'startDate': this.calendarTemplate.startDate && new Date(this.calendarTemplate.startDate), + 'frequency': this.calendarTemplate.frequency.id, + 'interval': this.calendarTemplate.interval + }); + } + + /** + * 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 = `groups_${this.groupId}_CollectionMeeting`; + const typeId = '1'; + const prevStartDate: Date = this.groupEditMeetingForm.value.startDate; + this.groupEditMeetingForm.patchValue({ + startDate: this.datePipe.transform(prevStartDate, dateFormat), + }); + const data = { + ...this.groupEditMeetingForm.value, + repeating: true, + title, + typeId, + dateFormat, + locale + }; + this.groupsService.updateGroupMeeting(this.groupId, data, this.calendarId).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 047a46172..7bc4613ba 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 @@ -4,3 +4,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 b7a0c2f3f..6391dcf84 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 @@ -20,13 +20,15 @@ export class GroupActionsComponent { 'Attach Meeting': boolean 'Attendance': boolean 'Manage Members': boolean + 'Edit Meeting': boolean } = { 'Assign Staff': false, 'Close': false, 'Activate': false, 'Attach Meeting': false, 'Attendance': false, - 'Manage Members': false + 'Manage Members': false, + 'Edit 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 ba17eca56..17933d32d 100644 --- a/src/app/groups/groups-view/groups-view.component.html +++ b/src/app/groups/groups-view/groups-view.component.html @@ -33,8 +33,8 @@

- Next Meeting on: {{groupViewData.collectionMeetingCalendar?.recentEligibleMeetingDate | date}} -
+ Next Meeting on: {{groupViewData.collectionMeetingCalendar?.nextTenRecurringDates[0] | date}} +
Meeting Frequency: {{groupViewData.collectionMeetingCalendar?.frequency.value | lowercase}}

diff --git a/src/app/groups/groups-view/groups-view.component.ts b/src/app/groups/groups-view/groups-view.component.ts index f7af10aa0..ad03c8e09 100644 --- a/src/app/groups/groups-view/groups-view.component.ts +++ b/src/app/groups/groups-view/groups-view.component.ts @@ -53,6 +53,10 @@ export class GroupsViewComponent { case 'Manage Members': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; + case 'Edit Meeting': + const queryParams: any = { calendarId: this.groupViewData.collectionMeetingCalendar.id }; + this.router.navigate([`actions/${name}`], { relativeTo: this.route, queryParams: queryParams }); + break; case 'Edit': this.router.navigate(['edit'], { relativeTo: this.route }); break; @@ -65,6 +69,19 @@ export class GroupsViewComponent { } } + /** + * Checks if meeting is editable. + */ + get editMeeting() { + if (this.groupViewData.collectionMeetingCalendar) { + const entityType = this.groupViewData.collectionMeetingCalendar.entityType.value; + if (entityType === 'GROUPS' && this.groupViewData.hierarchy === '.' + this.groupViewData.id + '.' ) { + return true; + } + } + return false; + } + /** * Refetches data for the component * TODO: Replace by a custom reload component instead of hard-coded back-routing. diff --git a/src/app/groups/groups.module.ts b/src/app/groups/groups.module.ts index 6b524c5bd..70ce3c3be 100644 --- a/src/app/groups/groups.module.ts +++ b/src/app/groups/groups.module.ts @@ -29,6 +29,7 @@ import { EditGroupComponent } from './edit-group/edit-group.component'; import { AttachGroupMeetingComponent } from './groups-view/group-actions/attach-group-meeting/attach-group-meeting.component'; import { GroupAttendanceComponent } from './groups-view/group-actions/group-attendance/group-attendance.component'; import { ManageGroupMembersComponent } from './groups-view/group-actions/manage-group-members/manage-group-members.component'; +import { EditGroupMeetingComponent } from './groups-view/group-actions/edit-group-meeting/edit-group-meeting.component'; /** * Groups Module @@ -62,7 +63,8 @@ import { ManageGroupMembersComponent } from './groups-view/group-actions/manage- EditGroupComponent, AttachGroupMeetingComponent, GroupAttendanceComponent, - ManageGroupMembersComponent + ManageGroupMembersComponent, + EditGroupMeetingComponent ], entryComponents: [ UnassignRoleDialogComponent, diff --git a/src/app/groups/groups.service.ts b/src/app/groups/groups.service.ts index 563a46c5c..40a3c851a 100644 --- a/src/app/groups/groups.service.ts +++ b/src/app/groups/groups.service.ts @@ -222,7 +222,7 @@ export class GroupsService { * @returns {Observable} */ createGroup(group: any): Observable { - return this.http.post('/groups', group); + return this.http.post('/groups', group); } /** @@ -242,6 +242,15 @@ export class GroupsService { return this.http.get(`/groups/${groupId}/calendars/template`); } + /** + * @param {any} groupId Group Id + * @returns {Observable} + */ + getGroupCalendarAndTemplate(groupId: any, calendarId: any): Observable { + const httpParams = new HttpParams().set('template', 'true'); + return this.http.get(`/groups/${groupId}/calendars/${calendarId}`, { params: httpParams }); + } + /** * @param {any} groupId Group Id * @returns {Observable} @@ -250,6 +259,14 @@ export class GroupsService { return this.http.post(`/groups/${groupId}/calendars`, data); } + /** + * @param {any} groupId Group Id + * @returns {Observable} + */ + updateGroupMeeting(groupId: any, data: any, calendarId: any): Observable { + return this.http.put(`/groups/${groupId}/calendars/${calendarId}`, data); + } + /** * @param {any} groupId Group Id * @param {any} calendarId Calendar Id