1 import { Component, Input, OnChanges, OnInit } from '@angular/core';
3 import { I18n } from '@ngx-translate/i18n-polyfill';
4 import * as _ from 'lodash';
6 import { CellTemplate } from '../../../shared/enum/cell-template.enum';
7 import { CdTableColumn } from '../../../shared/models/cd-table-column';
8 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
11 selector: 'cd-role-details',
12 templateUrl: './role-details.component.html',
13 styleUrls: ['./role-details.component.scss']
15 export class RoleDetailsComponent implements OnChanges, OnInit {
17 selection: CdTableSelection;
19 scopes: Array<string>;
22 columns: CdTableColumn[];
23 scopes_permissions: Array<any> = [];
25 constructor(private i18n: I18n) {}
31 name: this.i18n('Scope'),
36 name: this.i18n('Read'),
38 cellClass: 'text-center',
39 cellTransformation: CellTemplate.checkIcon
43 name: this.i18n('Create'),
45 cellClass: 'text-center',
46 cellTransformation: CellTemplate.checkIcon
50 name: this.i18n('Update'),
52 cellClass: 'text-center',
53 cellTransformation: CellTemplate.checkIcon
57 name: this.i18n('Delete'),
59 cellClass: 'text-center',
60 cellTransformation: CellTemplate.checkIcon
66 if (this.selection.hasSelection) {
67 this.selectedItem = this.selection.first();
68 // Build the scopes/permissions data used by the data table.
69 const scopes_permissions: any[] = [];
70 _.each(this.scopes, (scope) => {
71 const scope_permission: any = { read: false, create: false, update: false, delete: false };
72 scope_permission['scope'] = scope;
73 if (scope in this.selectedItem['scopes_permissions']) {
74 _.each(this.selectedItem['scopes_permissions'][scope], (permission) => {
75 scope_permission[permission] = true;
78 scopes_permissions.push(scope_permission);
80 this.scopes_permissions = scopes_permissions;