From 0e69e8ea1e1c4438c21bb11fbe0561a1c6aea577 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Wed, 8 Jul 2020 16:25:29 +0530 Subject: [PATCH] feat: group actions (close) (#1031) Fixes: #1030 --- .../group-actions.resolver.ts | 2 + .../close-group/close-group.component.html | 46 ++++++++++ .../close-group/close-group.component.scss | 3 + .../close-group/close-group.component.spec.ts | 25 ++++++ .../close-group/close-group.component.ts | 84 +++++++++++++++++++ .../group-actions.component.html | 1 + .../group-actions/group-actions.component.ts | 4 +- .../groups-view/groups-view.component.html | 2 +- .../groups-view/groups-view.component.ts | 1 + src/app/groups/groups.module.ts | 4 +- src/app/groups/groups.service.ts | 9 ++ 11 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 src/app/groups/groups-view/group-actions/close-group/close-group.component.html create mode 100644 src/app/groups/groups-view/group-actions/close-group/close-group.component.scss create mode 100644 src/app/groups/groups-view/group-actions/close-group/close-group.component.spec.ts create mode 100644 src/app/groups/groups-view/group-actions/close-group/close-group.component.ts diff --git a/src/app/groups/common-resolvers/group-actions.resolver.ts b/src/app/groups/common-resolvers/group-actions.resolver.ts index 500c2bd53..357d65b4b 100644 --- a/src/app/groups/common-resolvers/group-actions.resolver.ts +++ b/src/app/groups/common-resolvers/group-actions.resolver.ts @@ -30,6 +30,8 @@ export class GroupActionsResolver implements Resolve { switch (actionName) { case 'Assign Staff': return this.groupsService.getGroupData(groupId, 'true'); + case 'Close': + return this.groupsService.getGroupCommandTemplate('close'); default: return undefined; } diff --git a/src/app/groups/groups-view/group-actions/close-group/close-group.component.html b/src/app/groups/groups-view/group-actions/close-group/close-group.component.html new file mode 100644 index 000000000..d82412fea --- /dev/null +++ b/src/app/groups/groups-view/group-actions/close-group/close-group.component.html @@ -0,0 +1,46 @@ +
+ + + +
+ + + +
+ + + Closed On Date + + + + + Closed On Date is required + + + + + Closure Reason + + + {{ reason.name }} + + + + CLosure Reason is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/groups/groups-view/group-actions/close-group/close-group.component.scss b/src/app/groups/groups-view/group-actions/close-group/close-group.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/groups/groups-view/group-actions/close-group/close-group.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/groups/groups-view/group-actions/close-group/close-group.component.spec.ts b/src/app/groups/groups-view/group-actions/close-group/close-group.component.spec.ts new file mode 100644 index 000000000..dccb1e93d --- /dev/null +++ b/src/app/groups/groups-view/group-actions/close-group/close-group.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CloseGroupComponent } from './close-group.component'; + +describe('CloseGroupComponent', () => { + let component: CloseGroupComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CloseGroupComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CloseGroupComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/groups/groups-view/group-actions/close-group/close-group.component.ts b/src/app/groups/groups-view/group-actions/close-group/close-group.component.ts new file mode 100644 index 000000000..164544711 --- /dev/null +++ b/src/app/groups/groups-view/group-actions/close-group/close-group.component.ts @@ -0,0 +1,84 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { DatePipe } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { GroupsService } from 'app/groups/groups.service'; + +/** + * Close Group Component + */ +@Component({ + selector: 'mifosx-close-group', + templateUrl: './close-group.component.html', + styleUrls: ['./close-group.component.scss'] +}) +export class CloseGroupComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Close Share Account form. */ + closeGroupForm: FormGroup; + /** Group Data */ + closureData: any; + /** Group Id */ + groupId: any; + + /** + * @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.closureData = data.groupActionData.closureReasons; + }); + this.groupId = this.route.parent.snapshot.params['groupId']; + } + + ngOnInit() { + this.createCloseGroupForm(); + } + + /** + * Creates the close group form. + */ + createCloseGroupForm() { + this.closeGroupForm = this.formBuilder.group({ + 'closureDate': ['', Validators.required], + 'closureReasonId': ['', Validators.required] + }); + } + + /** + * Submits the form and closes the group. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevClosedDate: Date = this.closeGroupForm.value.closureDate; + this.closeGroupForm.patchValue({ + closureDate: this.datePipe.transform(prevClosedDate, dateFormat), + }); + const data = { + ...this.closeGroupForm.value, + dateFormat, + locale + }; + this.groupsService.executeGroupCommand(this.groupId, 'close', data).subscribe(() => { + 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 6d3f292e7..24b6f096a 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 +1,2 @@ + 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 7435a27d8..02d0c8e4d 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 @@ -15,8 +15,10 @@ export class GroupActionsComponent { /** Flag object to store possible actions and render appropriate UI to the user */ actions: { 'Assign Staff': boolean + 'Close': boolean } = { - 'Assign Staff': false + 'Assign Staff': false, + 'Close': false }; /** diff --git a/src/app/groups/groups-view/groups-view.component.html b/src/app/groups/groups-view/groups-view.component.html index a2fb6fd52..eaeddf3a2 100644 --- a/src/app/groups/groups-view/groups-view.component.html +++ b/src/app/groups/groups-view/groups-view.component.html @@ -85,7 +85,7 @@ - + diff --git a/src/app/groups/groups-view/groups-view.component.ts b/src/app/groups/groups-view/groups-view.component.ts index e7a90fb40..9a9a1afa1 100644 --- a/src/app/groups/groups-view/groups-view.component.ts +++ b/src/app/groups/groups-view/groups-view.component.ts @@ -45,6 +45,7 @@ export class GroupsViewComponent { doAction(name: string) { switch (name) { case 'Assign Staff': + case 'Close': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; case 'Unassign Staff': diff --git a/src/app/groups/groups.module.ts b/src/app/groups/groups.module.ts index c44ecd6ca..90c789b52 100644 --- a/src/app/groups/groups.module.ts +++ b/src/app/groups/groups.module.ts @@ -23,6 +23,7 @@ import { UnassignRoleDialogComponent } from './groups-view/custom-dialogs/unassi import { GroupActionsComponent } from './groups-view/group-actions/group-actions.component'; import { GroupAssignStaffComponent } from './groups-view/group-actions/group-assign-staff/group-assign-staff.component'; import { UnassignStaffDialogComponent } from './groups-view/custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component'; +import { CloseGroupComponent } from './groups-view/group-actions/close-group/close-group.component'; /** * Groups Module @@ -50,7 +51,8 @@ import { UnassignStaffDialogComponent } from './groups-view/custom-dialogs/unass UnassignRoleDialogComponent, GroupActionsComponent, GroupAssignStaffComponent, - UnassignStaffDialogComponent + UnassignStaffDialogComponent, + CloseGroupComponent ], entryComponents: [ UnassignRoleDialogComponent, diff --git a/src/app/groups/groups.service.ts b/src/app/groups/groups.service.ts index 9149911ca..e1ca115f8 100644 --- a/src/app/groups/groups.service.ts +++ b/src/app/groups/groups.service.ts @@ -72,6 +72,15 @@ export class GroupsService { return this.http.get(`/runreports/GroupSummaryCounts`, { params: httpParams }); } + /** + * @param {any} command Command + * @returns {Observable} + */ + getGroupCommandTemplate(command: string): Observable { + const httpParams = new HttpParams().set('command', command); + return this.http.get(`/groups/template`, { params: httpParams }); + } + /** * @param {string} groupId Group Id * @param {string} command Command