feat: add view, edit roles and permission component (#632)

- Add view roles and permission
- Edit roles and permission
- Edit role description

Fixes: #176
This commit is contained in:
Muskan Khedia
2020-05-31 13:05:52 +05:30
committed by GitHub
parent ab3bef463d
commit 28b3f730f0
23 changed files with 864 additions and 8 deletions
@@ -0,0 +1,37 @@
<div class="container">
<mat-card>
<form [formGroup]="roleForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Role Name</mat-label>
<input matInput disabled formControlName="name">
</mat-form-field>
<mat-form-field>
<mat-label>Role Description</mat-label>
<input matInput required formControlName="description">
<mat-error *ngIf="roleForm.controls.description.hasError('required')">
Description 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]="!roleForm.valid || roleForm.pristine">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,11 @@
.container {
max-width: 37rem;
}
span {
font-size: 1rem;
}
.roleName {
line-height: 3rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditRoleComponent } from './edit-role.component';
describe('EditRoleComponent', () => {
let component: EditRoleComponent;
let fixture: ComponentFixture<EditRoleComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditRoleComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditRoleComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,67 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { SystemService } from '../../system.service';
/**
* Edit Role Description Component.
*/
@Component({
selector: 'mifosx-edit-role',
templateUrl: './edit-role.component.html',
styleUrls: ['./edit-role.component.scss'],
})
export class EditRoleComponent implements OnInit {
/** Role Form */
roleForm: FormGroup;
/** Role Data */
roleData: any;
/**
* Retrieves the code data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {SystemService} systemService System Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(
private formBuilder: FormBuilder,
private systemService: SystemService,
private route: ActivatedRoute,
private router: Router
) {
this.route.data.subscribe((data: { role: any }) => {
this.roleData = data.role;
});
}
/**
* Creates and sets the role form.
*/
ngOnInit() {
this.createRoleForm();
}
/**
* Creates and sets role form.
*/
createRoleForm() {
this.roleForm = this.formBuilder.group({
name: [{ value: this.roleData.name, disabled: true }, Validators.required],
description: [this.roleData.description, Validators.required],
});
}
/**
* Submits the role form and updates role description,
* if successful redirects to view updated roles and permissions.
*/
submit() {
this.systemService.updateRole(this.roleForm.value, this.roleData.id).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}