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 @@
<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 });
});
}
}