]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Component, Input, OnChanges, OnInit } from '@angular/core'; |
2 | ||
3 | import { I18n } from '@ngx-translate/i18n-polyfill'; | |
4 | import * as _ from 'lodash'; | |
5 | ||
6 | import { CellTemplate } from '../../../shared/enum/cell-template.enum'; | |
7 | import { CdTableColumn } from '../../../shared/models/cd-table-column'; | |
11fdf7f2 TL |
8 | |
9 | @Component({ | |
10 | selector: 'cd-role-details', | |
11 | templateUrl: './role-details.component.html', | |
12 | styleUrls: ['./role-details.component.scss'] | |
13 | }) | |
14 | export class RoleDetailsComponent implements OnChanges, OnInit { | |
15 | @Input() | |
e306af50 | 16 | selection: any; |
11fdf7f2 TL |
17 | @Input() |
18 | scopes: Array<string>; | |
19 | selectedItem: any; | |
20 | ||
21 | columns: CdTableColumn[]; | |
22 | scopes_permissions: Array<any> = []; | |
23 | ||
24 | constructor(private i18n: I18n) {} | |
25 | ||
26 | ngOnInit() { | |
27 | this.columns = [ | |
28 | { | |
29 | prop: 'scope', | |
30 | name: this.i18n('Scope'), | |
31 | flexGrow: 2 | |
32 | }, | |
33 | { | |
34 | prop: 'read', | |
35 | name: this.i18n('Read'), | |
36 | flexGrow: 1, | |
37 | cellClass: 'text-center', | |
38 | cellTransformation: CellTemplate.checkIcon | |
39 | }, | |
40 | { | |
41 | prop: 'create', | |
42 | name: this.i18n('Create'), | |
43 | flexGrow: 1, | |
44 | cellClass: 'text-center', | |
45 | cellTransformation: CellTemplate.checkIcon | |
46 | }, | |
47 | { | |
48 | prop: 'update', | |
49 | name: this.i18n('Update'), | |
50 | flexGrow: 1, | |
51 | cellClass: 'text-center', | |
52 | cellTransformation: CellTemplate.checkIcon | |
53 | }, | |
54 | { | |
55 | prop: 'delete', | |
56 | name: this.i18n('Delete'), | |
57 | flexGrow: 1, | |
58 | cellClass: 'text-center', | |
59 | cellTransformation: CellTemplate.checkIcon | |
60 | } | |
61 | ]; | |
62 | } | |
63 | ||
64 | ngOnChanges() { | |
e306af50 TL |
65 | if (this.selection) { |
66 | this.selectedItem = this.selection; | |
11fdf7f2 | 67 | // Build the scopes/permissions data used by the data table. |
9f95a23c | 68 | const scopes_permissions: any[] = []; |
11fdf7f2 | 69 | _.each(this.scopes, (scope) => { |
9f95a23c | 70 | const scope_permission: any = { read: false, create: false, update: false, delete: false }; |
11fdf7f2 TL |
71 | scope_permission['scope'] = scope; |
72 | if (scope in this.selectedItem['scopes_permissions']) { | |
73 | _.each(this.selectedItem['scopes_permissions'][scope], (permission) => { | |
74 | scope_permission[permission] = true; | |
75 | }); | |
76 | } | |
77 | scopes_permissions.push(scope_permission); | |
78 | }); | |
79 | this.scopes_permissions = scopes_permissions; | |
80 | } | |
81 | } | |
82 | } |