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