@@ -0,0 +1,40 @@
|
|||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<mat-card>
|
||||||
|
|
||||||
|
<form [formGroup]="roleForm" (ngSubmit)="submit()">
|
||||||
|
|
||||||
|
<mat-card-content>
|
||||||
|
|
||||||
|
<div fxLayout="column">
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Name</mat-label>
|
||||||
|
<input matInput required formControlName="name">
|
||||||
|
<mat-error *ngIf="roleForm.controls.name.hasError('required')">
|
||||||
|
Role Name is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Description</mat-label>
|
||||||
|
<textarea matInput required formControlName="description"></textarea>
|
||||||
|
<mat-error *ngIf="roleForm.controls.description.hasError('required')">
|
||||||
|
Role 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">Submit</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,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 });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px" [routerLink]="['add']">
|
||||||
<button mat-raised-button color="primary">
|
<button mat-raised-button color="primary">
|
||||||
<fa-icon icon="plus"></fa-icon>
|
<fa-icon icon="plus"></fa-icon>
|
||||||
Add Role
|
Add Role
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { ExternalServicesComponent } from './external-services/external-services
|
|||||||
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
||||||
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
||||||
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
||||||
|
import { AddRoleComponent } from './roles-and-permissions/add-role/add-role.component';
|
||||||
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
|
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
|
||||||
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs/manage-scheduler-jobs.component';
|
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs/manage-scheduler-jobs.component';
|
||||||
import { GlobalConfigurationsComponent } from './global-configurations/global-configurations.component';
|
import { GlobalConfigurationsComponent } from './global-configurations/global-configurations.component';
|
||||||
@@ -221,11 +222,21 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'roles-and-permissions',
|
path: 'roles-and-permissions',
|
||||||
component: RolesAndPermissionsComponent,
|
|
||||||
resolve: {
|
|
||||||
roles: RolesAndPermissionsResolver
|
|
||||||
},
|
|
||||||
data: { title: extract('Roles and Permissions'), breadcrumb: 'Roles and Permissions' },
|
data: { title: extract('Roles and Permissions'), breadcrumb: 'Roles and Permissions' },
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: RolesAndPermissionsComponent,
|
||||||
|
resolve: {
|
||||||
|
roles: RolesAndPermissionsResolver
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'add',
|
||||||
|
component: AddRoleComponent,
|
||||||
|
data: { title: extract('Add Role'), breadcrumb: 'Add' }
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'surveys',
|
path: 'surveys',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { ExternalServicesComponent } from './external-services/external-services
|
|||||||
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
||||||
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
||||||
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
||||||
|
import { AddRoleComponent } from './roles-and-permissions/add-role/add-role.component';
|
||||||
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
|
import { ManageSurveysComponent } from './manage-surveys/manage-surveys.component';
|
||||||
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs/manage-scheduler-jobs.component';
|
import { ManageSchedulerJobsComponent } from './manage-scheduler-jobs/manage-scheduler-jobs.component';
|
||||||
import { GlobalConfigurationsComponent } from './global-configurations/global-configurations.component';
|
import { GlobalConfigurationsComponent } from './global-configurations/global-configurations.component';
|
||||||
@@ -74,7 +75,8 @@ import { ReportParameterDialogComponent } from './manage-reports/report-paramete
|
|||||||
ViewReportComponent,
|
ViewReportComponent,
|
||||||
CreateReportComponent,
|
CreateReportComponent,
|
||||||
EditReportComponent,
|
EditReportComponent,
|
||||||
ReportParameterDialogComponent
|
ReportParameterDialogComponent,
|
||||||
|
AddRoleComponent
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
ReportParameterDialogComponent
|
ReportParameterDialogComponent
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ export class SystemService {
|
|||||||
return this.http.get('/roles');
|
return this.http.get('/roles');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any} role Role to be created.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
createRole(role: any): Observable<any> {
|
||||||
|
return this.http.post('/roles', role);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Observable<any>} Fetches Codes.
|
* @returns {Observable<any>} Fetches Codes.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user