feat: add add-role component (#494)

Fixes: #487
This commit is contained in:
pwai
2019-12-03 23:12:00 +03:00
committed by Abhay Chawla
parent ba184db6e4
commit 091458765c
8 changed files with 156 additions and 6 deletions
@@ -0,0 +1,61 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */
import { SystemService } from '../../system.service';
/**
* Add Role Component.
*/
@Component({
selector: 'mifosx-add-role',
templateUrl: './add-role.component.html',
styleUrls: ['./add-role.component.scss']
})
export class AddRoleComponent implements OnInit {
/** Role form. */
roleForm: FormGroup;
/**
* @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) { }
/**
* Creates the role form.
*/
ngOnInit() {
this.createRoleForm();
}
/**
* Creates the create role form.
*/
createRoleForm() {
this.roleForm = this.formBuilder.group({
'name': ['', Validators.required],
'description': ['', Validators.required]
});
}
/**
* Submits the role form and creates a role,
* if successful redirects back to roles and permission.
*/
submit() {
this.systemService.createRole(this.roleForm.value)
.subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}