feat: add centers action (assign and unassign staff) (#1091)

Fixes: #1090
This commit is contained in:
Muskan Khedia
2020-07-14 11:33:27 +05:30
committed by GitHub
parent 3e50f79016
commit 96f881e909
17 changed files with 311 additions and 9 deletions
@@ -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
};
/**
@@ -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>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -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();
});
});
@@ -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 });
});
}
}