feat: add centers action (assign and unassign staff) (#1091)
Fixes: #1090
This commit is contained in:
@@ -25,6 +25,7 @@ import { CenterNotesResolver } from './common-resolvers/center-notes.resolver';
|
||||
import { CenterDatatableResolver } from './common-resolvers/center-datatable.resolver';
|
||||
import { CenterDatatablesResolver } from './common-resolvers/center-datatables.resolver';
|
||||
import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component';
|
||||
import { CenterActionsResolver } from './common-resolvers/center-actions.resolver';
|
||||
|
||||
const routes: Routes = [
|
||||
Route.withShell([
|
||||
@@ -91,7 +92,10 @@ const routes: Routes = [
|
||||
{
|
||||
path: 'actions/:name',
|
||||
data: { title: extract('Center Actions'), routeParamBreadcrumb: 'name' },
|
||||
component: CenterActionsComponent
|
||||
component: CenterActionsComponent,
|
||||
resolve: {
|
||||
centersActionData: CenterActionsResolver
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -111,7 +115,8 @@ const routes: Routes = [
|
||||
CenterSummaryResolver,
|
||||
CenterNotesResolver,
|
||||
CenterDatatableResolver,
|
||||
CenterDatatablesResolver
|
||||
CenterDatatablesResolver,
|
||||
CenterActionsResolver
|
||||
]
|
||||
})
|
||||
export class CentersRoutingModule { }
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
<mifosx-activate-center *ngIf="actions['Activate']"></mifosx-activate-center>
|
||||
<mifosx-center-assign-staff *ngIf="actions['Assign Staff']" ></mifosx-center-assign-staff>
|
||||
|
||||
@@ -14,9 +14,11 @@ export class CenterActionsComponent {
|
||||
|
||||
/** Flag object to store possible actions and render appropriate UI to the user */
|
||||
actions: {
|
||||
'Activate': boolean
|
||||
'Activate': boolean,
|
||||
'Assign Staff': boolean
|
||||
} = {
|
||||
'Activate': false,
|
||||
'Assign Staff': false
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="centerAssignStaffForm" (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="centerAssignStaffForm.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]="!centerAssignStaffForm.valid">Confirm</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
.container {
|
||||
max-width: 37rem;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CenterAssignStaffComponent } from './center-assign-staff.component';
|
||||
|
||||
describe('CenterAssignStaffComponent', () => {
|
||||
let component: CenterAssignStaffComponent;
|
||||
let fixture: ComponentFixture<CenterAssignStaffComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CenterAssignStaffComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CenterAssignStaffComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
+69
@@ -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 { CentersService } from 'app/centers/centers.service';
|
||||
|
||||
/**
|
||||
* Centers Assign Staff Component
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-center-assign-staff',
|
||||
templateUrl: './center-assign-staff.component.html',
|
||||
styleUrls: ['./center-assign-staff.component.scss']
|
||||
})
|
||||
export class CenterAssignStaffComponent implements OnInit {
|
||||
|
||||
/** Center Assign Staff form. */
|
||||
centerAssignStaffForm: FormGroup;
|
||||
/** Field Officer Data */
|
||||
staffData: any;
|
||||
/** Center Data */
|
||||
centerData: any;
|
||||
|
||||
/**
|
||||
* Fetches Center 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 centersService: CentersService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { centersActionData: any }) => {
|
||||
this.centerData = data.centersActionData;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the center assign staff form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.staffData = this.centerData.staffOptions;
|
||||
this.createCenterAssignStaffForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the center assign staff form.
|
||||
*/
|
||||
createCenterAssignStaffForm() {
|
||||
this.centerAssignStaffForm = this.formBuilder.group({
|
||||
'staffId': ['']
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the form and assigns staff for the center.
|
||||
*/
|
||||
submit() {
|
||||
this.centersService.executeGroupActionCommand(this.centerData.id, 'assignStaff', this.centerAssignStaffForm.value)
|
||||
.subscribe(() => {
|
||||
this.router.navigate(['../../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -65,10 +65,10 @@
|
||||
<button mat-menu-item *mifosxHasPermission="'SAVEORUPDATEATTENDANCE_MEETING'"> Attendance </button>
|
||||
</span>
|
||||
<span *ngIf="!(centerViewData.staffId)">
|
||||
<button mat-menu-item *mifosxHasPermission="'ASSIGNSTAFF_GROUP'" > Assign Staff </button>
|
||||
<button mat-menu-item *mifosxHasPermission="'ASSIGNSTAFF_GROUP'" (click)="doAction('Assign Staff')"> Assign Staff </button>
|
||||
</span>
|
||||
<span *ngIf="centerViewData.staffId">
|
||||
<button mat-menu-item *mifosxHasPermission="'UNASSIGNSTAFF_GROUP'" > Unassign Staff </button>
|
||||
<button mat-menu-item *mifosxHasPermission="'UNASSIGNSTAFF_GROUP'" (click)="doAction('Unassign Staff')"> Unassign Staff </button>
|
||||
</span>
|
||||
<span *ngIf="centerViewData.status.value==='Active'">
|
||||
<button mat-menu-item *mifosxHasPermission="'DELETE_CENTER'" > Delete </button>
|
||||
|
||||
@@ -3,6 +3,12 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
/** Dialog Imports */
|
||||
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
|
||||
|
||||
/** Custom Services */
|
||||
import { CentersService } from '../centers.service';
|
||||
|
||||
/**
|
||||
* Create Center View
|
||||
*/
|
||||
@@ -26,7 +32,8 @@ export class CentersViewComponent implements OnInit {
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
public dialog: MatDialog) {
|
||||
public dialog: MatDialog,
|
||||
public centersService: CentersService) {
|
||||
this.route.data.subscribe((data: {
|
||||
centerViewData: any,
|
||||
centerDatatables: any
|
||||
@@ -49,9 +56,40 @@ export class CentersViewComponent implements OnInit {
|
||||
doAction(name: string) {
|
||||
switch (name) {
|
||||
case 'Activate':
|
||||
case 'Assign Staff':
|
||||
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
|
||||
break;
|
||||
case 'Unassign Staff':
|
||||
this.centersUnassignStaff();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign's the centers's staff.
|
||||
*/
|
||||
private centersUnassignStaff() {
|
||||
const unAssignStaffDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
||||
data: { heading: 'Unassign Staff', dialogContext: 'Are you sure you want Unassign Staff ?' }
|
||||
});
|
||||
unAssignStaffDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
|
||||
if (response.confirm) {
|
||||
this.centersService.executeGroupActionCommand(this.centerViewData.id, 'unassignStaff', { staffId: this.centerViewData.staffId })
|
||||
.subscribe(() => {
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(`/centers`, {skipLocationChange: true})
|
||||
.then(() => this.router.navigate([url]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { MultiRowComponent } from './centers-view/datatable-tab/multi-row/multi-
|
||||
import { SingleRowComponent } from './centers-view/datatable-tab/single-row/single-row.component';
|
||||
import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component';
|
||||
import { ActivateCenterComponent } from './centers-view/center-actions/activate-center/activate-center.component';
|
||||
import { CenterAssignStaffComponent } from './centers-view/center-actions/center-assign-staff/center-assign-staff.component';
|
||||
|
||||
/**
|
||||
* Centers Module
|
||||
@@ -41,7 +42,8 @@ import { ActivateCenterComponent } from './centers-view/center-actions/activate-
|
||||
MultiRowComponent,
|
||||
SingleRowComponent,
|
||||
CenterActionsComponent,
|
||||
ActivateCenterComponent
|
||||
ActivateCenterComponent,
|
||||
CenterAssignStaffComponent
|
||||
]
|
||||
})
|
||||
export class CentersModule { }
|
||||
|
||||
@@ -187,4 +187,26 @@ export class CentersService {
|
||||
return this.http.post(`/centers/${centerId}`, data, { params: httpParams });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} centerId Center Id
|
||||
* @param {string} command Command
|
||||
* @param {any} data Data
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
executeGroupActionCommand(centerId: string, command: string, data: any): Observable<any> {
|
||||
const httpParams = new HttpParams().set('command', command);
|
||||
return this.http.post(`/groups/${centerId}`, data, { params: httpParams });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param centerId Center Id of center to get data for.
|
||||
* @returns {Observable<any>} Center data.
|
||||
*/
|
||||
getGroupStaffData(centerId: string): Observable<any> {
|
||||
const httpParams = new HttpParams().set('groupOrCenter', 'centers')
|
||||
.set('staffInSelectedOfficeOnly', 'true')
|
||||
.set('template', 'true');
|
||||
return this.http.get(`/groups/${centerId}`, { params: httpParams });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 { CentersService } from '../centers.service';
|
||||
|
||||
/**
|
||||
* Group Actions data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class CenterActionsResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {CentersService} centersService Savings service.
|
||||
*/
|
||||
constructor(private centersService: CentersService) { }
|
||||
|
||||
/**
|
||||
* Returns the Centers account actions data.
|
||||
* @param {ActivatedRouteSnapshot} route Route Snapshot
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const actionName = route.paramMap.get('name');
|
||||
const centerId = route.paramMap.get('centerId') || route.parent.parent.paramMap.get('centerId');
|
||||
switch (actionName) {
|
||||
case 'Assign Staff':
|
||||
return this.centersService.getGroupStaffData(centerId);
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<h1 mat-dialog-title>{{data.heading}}</h1>
|
||||
<div mat-dialog-content>
|
||||
<p>{{ data.dialogContext }} ?</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 { ConfirmationDialogComponent } from './confirmation-dialog.component';
|
||||
|
||||
describe('ConfirmationDialogComponent', () => {
|
||||
let component: ConfirmationDialogComponent;
|
||||
let fixture: ComponentFixture<ConfirmationDialogComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ConfirmationDialogComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ConfirmationDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, Inject } from '@angular/core';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||
|
||||
/**
|
||||
* Delete dialog component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-confirmation-dialog',
|
||||
templateUrl: './confirmation-dialog.component.html',
|
||||
styleUrls: ['./confirmation-dialog.component.scss']
|
||||
})
|
||||
export class ConfirmationDialogComponent implements OnInit {
|
||||
|
||||
/**
|
||||
* @param {MatDialogRef} dialogRef Component reference to dialog.
|
||||
* @param {any} data Provides a deleteContext.
|
||||
*/
|
||||
constructor(public dialogRef: MatDialogRef<ConfirmationDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
||||
|
||||
ngOnInit() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { ThemePickerComponent } from './theme-picker/theme-picker.component';
|
||||
import { ChangePasswordDialogComponent } from './change-password-dialog/change-password-dialog.component';
|
||||
import { EnableDialogComponent } from './enable-dialog/enable-dialog.component';
|
||||
import { DisableDialogComponent } from './disable-dialog/disable-dialog.component';
|
||||
import { ConfirmationDialogComponent } from './confirmation-dialog/confirmation-dialog.component';
|
||||
|
||||
/** Custom Modules */
|
||||
import { IconsModule } from './icons.module';
|
||||
@@ -41,7 +42,8 @@ import { MaterialModule } from './material.module';
|
||||
ThemePickerComponent,
|
||||
ChangePasswordDialogComponent,
|
||||
EnableDialogComponent,
|
||||
DisableDialogComponent
|
||||
DisableDialogComponent,
|
||||
ConfirmationDialogComponent
|
||||
],
|
||||
exports: [
|
||||
FileUploadComponent,
|
||||
@@ -59,7 +61,8 @@ import { MaterialModule } from './material.module';
|
||||
DeleteDialogComponent,
|
||||
ChangePasswordDialogComponent,
|
||||
EnableDialogComponent,
|
||||
DisableDialogComponent
|
||||
DisableDialogComponent,
|
||||
ConfirmationDialogComponent
|
||||
]
|
||||
})
|
||||
export class SharedModule { }
|
||||
|
||||
Reference in New Issue
Block a user