feat: group actions (assign/unassign staff) (#1029)

Fixes #1028
This commit is contained in:
Karan Takalkar
2020-07-08 15:37:38 +05:30
committed by GitHub
parent 356cda70b8
commit b3abac32f5
17 changed files with 356 additions and 8 deletions
@@ -0,0 +1,38 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { GroupsService } from '../groups.service';
/**
* Group Actions data resolver.
*/
@Injectable()
export class GroupActionsResolver implements Resolve<Object> {
/**
* @param {GroupsService} groupsService Savings service.
*/
constructor(private groupsService: GroupsService) { }
/**
* Returns the Savings account actions data.
* @param {ActivatedRouteSnapshot} route Route Snapshot
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const actionName = route.paramMap.get('name');
const groupId = route.paramMap.get('groupId') || route.parent.parent.paramMap.get('groupId');
switch (actionName) {
case 'Assign Staff':
return this.groupsService.getGroupData(groupId, 'true');
default:
return undefined;
}
}
}
+12 -1
View File
@@ -17,6 +17,7 @@ import { CommitteeTabComponent } from './groups-view/committee-tab/committee-tab
import { CreateGroupComponent } from './create-group/create-group.component';
import { DatatableTabsComponent } from './groups-view/datatable-tabs/datatable-tabs.component';
import { AddRoleComponent } from './groups-view/add-role/add-role.component';
import { GroupActionsComponent } from './groups-view/group-actions/group-actions.component';
/** Custom Resolvers */
import { GroupViewResolver } from './common-resolvers/group-view.resolver';
@@ -27,6 +28,7 @@ import { OfficesResolver } from 'app/accounting/common-resolvers/offices.resolve
import { GroupDatatablesResolver } from './common-resolvers/group-datatables.resolver';
import { GroupDatatableResolver } from './common-resolvers/group-datatable.resolver';
import { GroupDataAndTemplateResolver } from './common-resolvers/group-data-and-template.resolver';
import { GroupActionsResolver } from './common-resolvers/group-actions.resolver';
/** Groups Routes */
const routes: Routes = [
@@ -113,6 +115,14 @@ const routes: Routes = [
},
]
},
{
path: 'actions/:name',
data: { title: extract('Group Actions'), routeParamBreadcrumb: 'name' },
component: GroupActionsComponent,
resolve: {
groupActionData: GroupActionsResolver
}
},
{
path: 'savingsaccounts',
loadChildren: '../savings/savings.module#SavingsModule'
@@ -138,6 +148,7 @@ const routes: Routes = [
GroupNotesResolver,
GroupDatatablesResolver,
GroupDatatableResolver,
GroupDataAndTemplateResolver]
GroupDataAndTemplateResolver,
GroupActionsResolver]
})
export class GroupsRoutingModule { }
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>Unassign Staff</h1>
<div mat-dialog-content>
<p>Are you sure you want to unassign staff for this group ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="warn" [mat-dialog-close]="{ confirm: true }">Confirm</button>
</mat-dialog-actions>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UnassignStaffDialogComponent } from './unassign-staff-dialog.component';
describe('UnassignStaffDialogComponent', () => {
let component: UnassignStaffDialogComponent;
let fixture: ComponentFixture<UnassignStaffDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UnassignStaffDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UnassignStaffDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,20 @@
/** Angular Imports */
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
/**
* Unassign staff dialog component.
*/
@Component({
selector: 'mifosx-unassign-staff-dialog',
templateUrl: './unassign-staff-dialog.component.html',
styleUrls: ['./unassign-staff-dialog.component.scss']
})
export class UnassignStaffDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
*/
constructor(public dialogRef: MatDialogRef<UnassignStaffDialogComponent>) { }
}
@@ -0,0 +1 @@
<mifosx-group-assign-staff *ngIf="actions['Assign Staff']"></mifosx-group-assign-staff>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupActionsComponent } from './group-actions.component';
describe('GroupActionsComponent', () => {
let component: GroupActionsComponent;
let fixture: ComponentFixture<GroupActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GroupActionsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GroupActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
/**
* Group actions component.
*/
@Component({
selector: 'mifosx-group-actions',
templateUrl: './group-actions.component.html',
styleUrls: ['./group-actions.component.scss']
})
export class GroupActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Assign Staff': boolean
} = {
'Assign Staff': false
};
/**
* @param {ActivatedRoute} route Activated Route
*/
constructor(private route: ActivatedRoute) {
const name = this.route.snapshot.params['name'];
this.actions[name] = true;
}
}
@@ -0,0 +1,36 @@
<div class="container">
<mat-card>
<form [formGroup]="groupAssignStaffForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field fxFlex="48%">
<mat-label>Staff</mat-label>
<mat-select formControlName="staffId">
<mat-option *ngFor="let staff of staffData" [value]="staff.id">
{{ staff.displayName }}
</mat-option>
</mat-select>
<mat-error *ngIf="groupAssignStaffForm.controls.staffId.hasError('required')">
Staff is <strong>required</strong>
</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]="!groupAssignStaffForm.valid">Confirm</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 { GroupAssignStaffComponent } from './group-assign-staff.component';
describe('GroupAssignStaffComponent', () => {
let component: GroupAssignStaffComponent;
let fixture: ComponentFixture<GroupAssignStaffComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GroupAssignStaffComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GroupAssignStaffComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,69 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
/**
* Groups Assign Staff Component
*/
@Component({
selector: 'mifosx-group-assign-staff',
templateUrl: './group-assign-staff.component.html',
styleUrls: ['./group-assign-staff.component.scss']
})
export class GroupAssignStaffComponent implements OnInit {
/** Group Assign Staff form. */
groupAssignStaffForm: FormGroup;
/** Field Officer Data */
staffData: any;
/** Group Data */
groupData: any;
/**
* Fetches Group Action Data from `resolve`
* @param {FormBuilder} formBuilder Form Builder
* @param {SavingsService} savingsService Savings Service
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { groupActionData: any }) => {
this.groupData = data.groupActionData;
});
}
/**
* Creates the group assign staff form.
*/
ngOnInit() {
this.staffData = this.groupData.staffOptions;
this.createGroupAssignStaffForm();
}
/**
* Creates the group assign staff form.
*/
createGroupAssignStaffForm() {
this.groupAssignStaffForm = this.formBuilder.group({
'staffId': ['']
});
}
/**
* Submits the form and assigns staff for the group.
*/
submit() {
this.groupsService.executeGroupCommand(this.groupData.id, 'assignStaff', this.groupAssignStaffForm.value)
.subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -20,7 +20,7 @@
</mat-card-title>
<mat-card-subtitle>
<p>
Group #: {{groupViewData.id}} | Center Name: {{groupViewData.centerName}} | Staff: {{groupViewData.staffName}}<br/>
Group #: {{groupViewData.id}} | Center Name: {{groupViewData.centerName}} | Staff: {{groupViewData.staffName || 'Unassigned'}}<br/>
Office Name: {{groupViewData.officeName}}<br/>
Activation Date : {{(groupViewData.activationDate)?(groupViewData.activationDate|date) :'Not Activated'}}<br/>
<span *ngIf="!groupViewData.active">
@@ -80,9 +80,9 @@
<span *ngIf="groupViewData.collectionMeetingCalendar">
<button mat-menu-item *mifosxHasPermission="'SAVEORUPDATEATTENDANCE_MEETING'">Attendance</button></span>
<span *ngIf="!groupViewData.staffId">
<button mat-menu-item *mifosxHasPermission="'ASSIGNSTAFF_GROUP'">Assign Staff</button></span>
<button mat-menu-item *mifosxHasPermission="'ASSIGNSTAFF_GROUP'" (click)="doAction('Assign Staff')">Assign Staff</button></span>
<span *ngIf="groupViewData.staffId">
<button mat-menu-item *mifosxHasPermission="'UNASSIGNSTAFF_GROUP'">Unassign Staff</button></span>
<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="'CLOSE_GROUP'">Close</button>
@@ -1,6 +1,13 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
/** Custom Dialogs */
import { UnassignStaffDialogComponent } from './custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component';
/** Custom Services */
import { GroupsService } from '../groups.service';
/**
* Groups View Component.
@@ -21,11 +28,54 @@ export class GroupsViewComponent {
* Fetches group data from `resolve`
* @param {ActivatedRoute} route Activated Route
*/
constructor(private route: ActivatedRoute) {
constructor(private route: ActivatedRoute,
private groupsService: GroupsService,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: { groupViewData: any, groupDatatables: any }) => {
this.groupViewData = data.groupViewData;
this.groupDatatables = data.groupDatatables;
});
}
/**
* Performs action button/option action.
* @param {string} name action name.
*/
doAction(name: string) {
switch (name) {
case 'Assign Staff':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
this.unassignStaff();
break;
}
}
/**
* Refetches data for the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
*/
reload() {
const url: string = this.router.url;
this.router.navigateByUrl(`/groups`, {skipLocationChange: true})
.then(() => this.router.navigate([url]));
}
/**
* Unassign's the group's staff.
*/
private unassignStaff() {
const unAssignStaffDialogRef = this.dialog.open(UnassignStaffDialogComponent);
unAssignStaffDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
if (response.confirm) {
this.groupsService.executeGroupCommand(this.groupViewData.id, 'unassignStaff', { staffId: this.groupViewData.staffId })
.subscribe(() => {
this.reload();
});
}
});
}
}
+9 -2
View File
@@ -20,6 +20,9 @@ import { SingleRowComponent } from './groups-view/datatable-tabs/single-row/sing
import { MultiRowComponent } from './groups-view/datatable-tabs/multi-row/multi-row.component';
import { AddRoleComponent } from './groups-view/add-role/add-role.component';
import { UnassignRoleDialogComponent } from './groups-view/custom-dialogs/unassign-role-dialog/unassign-role-dialog.component';
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';
/**
* Groups Module
@@ -44,10 +47,14 @@ import { UnassignRoleDialogComponent } from './groups-view/custom-dialogs/unassi
SingleRowComponent,
MultiRowComponent,
AddRoleComponent,
UnassignRoleDialogComponent
UnassignRoleDialogComponent,
GroupActionsComponent,
GroupAssignStaffComponent,
UnassignStaffDialogComponent
],
entryComponents: [
UnassignRoleDialogComponent
UnassignRoleDialogComponent,
UnassignStaffDialogComponent
],
providers: [DatePipe]
})