@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user