feat: groups add and unassign role (#1027)

Fixes #1026
This commit is contained in:
Karan Takalkar
2020-07-08 14:19:51 +05:30
committed by GitHub
parent 5e9e71f66f
commit 356cda70b8
14 changed files with 454 additions and 140 deletions
@@ -0,0 +1,48 @@
<div class="container">
<mat-card>
<form [formGroup]="groupsAddRoleForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Client</mat-label>
<mat-select formControlName="clientId">
<mat-option *ngFor="let client of clientMemberData" [value]="client.id">
{{ client.displayName }}
</mat-option>
</mat-select>
<mat-error *ngIf="groupsAddRoleForm.controls.clientId.hasError('required')">
Client Member is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Role</mat-label>
<mat-select formControlName="role">
<mat-option *ngFor="let role of roleData" [value]="role.id">
{{ role.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="groupsAddRoleForm.controls.role.hasError('required')">
Role 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]="!groupsAddRoleForm.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 { AddRoleComponent } from './add-role.component';
describe('AddRoleComponent', () => {
let component: AddRoleComponent;
let fixture: ComponentFixture<AddRoleComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AddRoleComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AddRoleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,68 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { GroupsService } from '../../groups.service';
/**
* Groups Add Role Component
*/
@Component({
selector: 'mifosx-add-role',
templateUrl: './add-role.component.html',
styleUrls: ['./add-role.component.scss']
})
export class AddRoleComponent implements OnInit {
/** Groups Add Role Form */
groupsAddRoleForm: FormGroup;
/** Client Menmber Data */
clientMemberData: any;
/** Role Data */
roleData: any;
/** Groups Account and Template Data */
groupAndTemplateData: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {GroupsService} groupsService Groups 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: { groupAndTemplateData: any }) => {
this.groupAndTemplateData = data.groupAndTemplateData;
});
}
ngOnInit() {
this.clientMemberData = this.groupAndTemplateData.activeClientMembers;
this.roleData = this.groupAndTemplateData.availableRoles;
this.createGroupsAddRoleForm();
}
/**
* Creates the add group role form.
*/
createGroupsAddRoleForm() {
this.groupsAddRoleForm = this.formBuilder.group({
'clientId': ['', Validators.required],
'role': ['', Validators.required]
});
}
/**
* Submits the form and assigns the group role.
*/
submit() {
this.groupsService.executeGroupCommand(this.groupAndTemplateData.id, 'assignRole', this.groupsAddRoleForm.value).subscribe(() => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}
@@ -6,15 +6,14 @@
</div>
<div class="action-button m-b-10" fxLayoutGap="25px" *ngIf="groupStatus !== 'Closed'">
<button mat-raised-button class="f-right" color="primary"
*mifosxHasPermission="'ASSIGNROLE_GROUP'">
*mifosxHasPermission="'ASSIGNROLE_GROUP'" [routerLink]="['add-role']">
<i class="fa fa-plus"></i>&nbsp; Add</button>
</div>
</div>
<div *ngIf="groupRolesData">
<table mat-table [dataSource]="groupRolesData"
class="mat-elevation-z1 m-b-25">
<table #rolesTable mat-table [dataSource]="groupRolesData" class="mat-elevation-z1 m-b-25">
<ng-container matColumnDef="Name">
<th mat-header-cell *matHeaderCellDef> Name </th>
@@ -35,8 +34,8 @@
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let element">
<span *ngIf="groupStatus !== 'Closed'">
<button class="account-action-button" mat-raised-button color="primary"
*mifosxHasPermission="'UNASSIGNROLE_GROUP'">
<button class="account-action-button" mat-raised-button color="warn"
*mifosxHasPermission="'UNASSIGNROLE_GROUP'" (click)="unassignRole(element.clientId, element.id)">
<i class="fa fa-ban" matTooltip="Unassign"></i>
</button>
</span>
@@ -1,6 +1,13 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatDialog, MatTable } from '@angular/material';
/** Custom Dialogs */
import { UnassignRoleDialogComponent } from '../custom-dialogs/unassign-role-dialog/unassign-role-dialog.component';
/** Custom Services */
import { GroupsService } from 'app/groups/groups.service';
/**
* Groups Committee Tab Component
@@ -15,18 +22,46 @@ export class CommitteeTabComponent {
/** Group Status */
groupStatus: any;
/** Group Roles Data */
groupRolesData: any;
groupRolesData: any[];
/** Groups View Data */
groupViewData: any;
/** Columns to be Displayed for client members table */
groupRolesColumns: string[] = ['Name', 'Role', 'Client Id', 'Actions'];
/** Roles Table */
@ViewChild('rolesTable') rolesTableRef: MatTable<Element>;
/**
* Fetches groups data from parent's `resolve`.
* @param {ActivatedRoute} route Activated Route.
* @param {ActivatedRoute} route Activated Route
* @param {GroupsService} groupsService Groups Service
* @param {MatDialog} dialog Mat Dialog
*/
constructor(private route: ActivatedRoute) {
constructor(private route: ActivatedRoute,
private groupsService: GroupsService,
public dialog: MatDialog) {
this.route.parent.data.subscribe((data: { groupViewData: any }) => {
this.groupRolesData = data.groupViewData.groupRoles;
this.groupStatus = data.groupViewData.status.value;
this.groupViewData = data.groupViewData;
this.groupRolesData = this.groupViewData.groupRoles;
this.groupStatus = this.groupViewData.status.value;
});
}
/**
* Unassigns a client's role.
* @param {any} clientId Client Id
* @param {any} roleId Role Id
*/
unassignRole(clientId: any, roleId: any) {
const unAssignRoleDialogRef = this.dialog.open(UnassignRoleDialogComponent, {
data: { id: clientId }
});
unAssignRoleDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
if (response.confirm) {
const clientIndex = this.groupRolesData.findIndex((client: any) => client.clientId === clientId);
this.groupRolesData.splice(clientIndex, 1);
this.rolesTableRef.renderRows();
this.groupsService.unAssignRoleCommand(this.groupViewData.id, roleId).subscribe(() => {});
}
});
}
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>Unassign Role</h1>
<div mat-dialog-content>
<p>Are you sure you want to unassign role for client member with id: {{ data.id }} ?</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 { UnassignRoleDialogComponent } from './unassign-role-dialog.component';
describe('UnassignRoleDialogComponent', () => {
let component: UnassignRoleDialogComponent;
let fixture: ComponentFixture<UnassignRoleDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UnassignRoleDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UnassignRoleDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,22 @@
/** Angular Imports */
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
/**
* Unassign role dialog component.
*/
@Component({
selector: 'mifosx-unassign-role-dialog',
templateUrl: './unassign-role-dialog.component.html',
styleUrls: ['./unassign-role-dialog.component.scss']
})
export class UnassignRoleDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data.
*/
constructor(public dialogRef: MatDialogRef<UnassignRoleDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
}