1
- import { Component , ViewChild , Injector , Output , EventEmitter , ElementRef , OnInit } from '@angular/core' ;
1
+ import { Component , ViewChild , Injector , Output , EventEmitter , ElementRef } from '@angular/core' ;
2
2
import { ModalDirective } from 'ngx-bootstrap' ;
3
- import { RoleServiceProxy , RoleDto , ListResultDtoOfPermissionDto } from '@shared/service-proxies/service-proxies' ;
3
+ import { RoleServiceProxy , GetRoleForEditOutput , RoleDto } from '@shared/service-proxies/service-proxies' ;
4
4
import { AppComponentBase } from '@shared/app-component-base' ;
5
5
import { finalize } from 'rxjs/operators' ;
6
6
7
7
@Component ( {
8
8
selector : 'edit-role-modal' ,
9
9
templateUrl : './edit-role.component.html'
10
10
} )
11
- export class EditRoleComponent extends AppComponentBase implements OnInit {
11
+ export class EditRoleComponent extends AppComponentBase {
12
12
@ViewChild ( 'editRoleModal' ) modal : ModalDirective ;
13
13
@ViewChild ( 'modalContent' ) modalContent : ElementRef ;
14
14
15
15
active : boolean = false ;
16
16
saving : boolean = false ;
17
17
18
- permissions : ListResultDtoOfPermissionDto = null ;
19
- role : RoleDto = null ;
18
+ model : GetRoleForEditOutput = null ;
20
19
21
20
@Output ( ) modalSave : EventEmitter < any > = new EventEmitter < any > ( ) ;
22
21
constructor (
@@ -26,21 +25,14 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
26
25
super ( injector ) ;
27
26
}
28
27
29
- ngOnInit ( ) : void {
30
- this . _roleService . getAllPermissions ( )
31
- . subscribe ( ( permissions : ListResultDtoOfPermissionDto ) => {
32
- this . permissions = permissions ;
33
- } ) ;
34
- }
35
-
36
28
show ( id : number ) : void {
37
- this . _roleService . get ( id )
29
+ this . _roleService . getRoleForEdit ( id )
38
30
. pipe ( finalize ( ( ) => {
39
31
this . active = true ;
40
32
this . modal . show ( ) ;
41
33
} ) )
42
- . subscribe ( ( result : RoleDto ) => {
43
- this . role = result ;
34
+ . subscribe ( ( result : GetRoleForEditOutput ) => {
35
+ this . model = result ;
44
36
} ) ;
45
37
}
46
38
@@ -49,7 +41,7 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
49
41
}
50
42
51
43
checkPermission ( permissionName : string ) : string {
52
- if ( this . role . permissions . indexOf ( permissionName ) != - 1 ) {
44
+ if ( this . model . grantedPermissionNames . indexOf ( permissionName ) != - 1 ) {
53
45
return "checked" ;
54
46
}
55
47
else {
@@ -58,6 +50,8 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
58
50
}
59
51
60
52
save ( ) : void {
53
+ const role = this . model . role ;
54
+
61
55
var permissions = [ ] ;
62
56
$ ( this . modalContent . nativeElement ) . find ( "[name=permission]" ) . each (
63
57
function ( index : number , elem : Element ) {
@@ -67,9 +61,18 @@ export class EditRoleComponent extends AppComponentBase implements OnInit {
67
61
}
68
62
)
69
63
70
- this . role . permissions = permissions ;
71
64
this . saving = true ;
72
- this . _roleService . update ( this . role )
65
+ var input = new RoleDto ( ) ;
66
+
67
+ input . name = role . name ;
68
+ input . displayName = role . displayName ;
69
+ input . description = role . description ;
70
+ input . id = role . id ;
71
+ input . isStatic = role . isStatic ;
72
+ input . permissions = permissions ;
73
+
74
+
75
+ this . _roleService . update ( input )
73
76
. pipe ( finalize ( ( ) => { this . saving = false ; } ) )
74
77
. subscribe ( ( ) => {
75
78
this . notify . info ( this . l ( 'SavedSuccessfully' ) ) ;
0 commit comments