1
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
2
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
3
|
import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog';
|
4
|
import { Role } from 'src/app/shared/models/role.interface';
|
5
|
import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service';
|
6
|
import { RolesService } from 'src/app/shared/services/roles-users-management/role.service';
|
7
|
|
8
|
@Component({
|
9
|
selector: 'app-create-role',
|
10
|
templateUrl: './create-role.component.html',
|
11
|
styleUrls: ['./create-role.component.scss']
|
12
|
})
|
13
|
export class CreateRoleComponent implements OnInit {
|
14
|
|
15
|
createRoleForm: FormGroup;
|
16
|
role: Role;
|
17
|
@Input() displayDialog: boolean;
|
18
|
@Output() valueChange = new EventEmitter();
|
19
|
|
20
|
constructor(private fb: FormBuilder, public ref: DynamicDialogRef, private roleservice: RolesService,public config: DynamicDialogConfig, private notifications: NotificationsHandlingService) { }
|
21
|
|
22
|
ngOnInit(): void {
|
23
|
this.createRoleForm = this.fb.group({
|
24
|
name: this.fb.control(null, [Validators.required]),
|
25
|
description: this.fb.control(null, [Validators.required]),
|
26
|
mradio: this.fb.control(null,[Validators.required])
|
27
|
});
|
28
|
}
|
29
|
|
30
|
createRole(): void{
|
31
|
const role = <Role> {
|
32
|
id: null,
|
33
|
name: this.createRoleForm.get('name').value,
|
34
|
description: this.createRoleForm.get('description').value,
|
35
|
isGlobal: this.createRoleForm.get('mradio').value,
|
36
|
readOnly: false,
|
37
|
status:true,
|
38
|
rightsList: []
|
39
|
}
|
40
|
this.roleservice.create(role).subscribe(
|
41
|
result => {
|
42
|
this.ref.close(result);
|
43
|
this.notifications.showCreateRoleSuccess();
|
44
|
console.log("Successful creation of new role")
|
45
|
},
|
46
|
error => {
|
47
|
console.log("Error at creation of new role")
|
48
|
});
|
49
|
|
50
|
|
51
|
}
|
52
|
|
53
|
|
54
|
}
|