feat: add centers action (assign and unassign staff) (#1091)
Fixes: #1090
This commit is contained in:
@@ -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]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user