File
Implements
Metadata
selector |
tcla-live-apps-settings-access-control |
styleUrls |
./live-apps-settings-access-control.component.css |
templateUrl |
./live-apps-settings-access-control.component.html |
Methods
isGroup
|
isGroup(index, item)
|
|
Parameters :
Name |
Optional |
index |
No
|
item |
No
|
|
runSaveFunction
|
runSaveFunction()
|
|
|
dataSource
|
Type : []
|
Default value : []
|
|
displayedColumns
|
Type : string[]
|
Default value : []
|
|
Private
generateTables
|
Default value : () => {...}
|
|
Public
isSelected
|
Default value : () => {...}
|
|
Public
toggle
|
Default value : () => {...}
|
|
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { RouteAccessControlConfig, RouteAccessControlConfigurationElement, Roles } from '../../models/tc-groups-data';
import { TcAccessControlService } from '../../services/tc-access-control.service';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'tcla-live-apps-settings-access-control',
templateUrl: './live-apps-settings-access-control.component.html',
styleUrls: ['./live-apps-settings-access-control.component.css']
})
export class LiveAppsSettingsAccessControlComponent implements OnInit {
displayedColumns: string[] = [];
dataSource = [];
private accessControlConfiguration: RouteAccessControlConfig;
allRoles: Roles;
isGroup(index, item): boolean {
return item.isGroupBy;
}
constructor(
private route: ActivatedRoute,
private accessControlService: TcAccessControlService,
private snackBar: MatSnackBar
) { }
ngOnInit() {
this.accessControlConfiguration = this.route.snapshot.data.accessControlConfigHolder;
this.allRoles = this.route.snapshot.data.allRoles;
this.generateTables();
}
runSaveFunction() {
this.accessControlConfiguration.configuration = [];
for (const role of this.allRoles.roles){
let userConfiguration = this.dataSource.filter(entry => entry[role.id]);
let routes = userConfiguration.filter(row => row.type === 'route').map(element => element.name);
let buttonIds = userConfiguration.filter(row => row.type === 'button').map(element => element.name);
this.accessControlConfiguration.configuration.push(
new RouteAccessControlConfigurationElement().deserialize({'roleId': role.id, routes: routes, buttonIds: buttonIds})
)
}
this.accessControlService.updateAccessControlConfig(Number(this.route.snapshot.data.claims.primaryProductionSandbox.id).valueOf(), this.accessControlConfiguration.uiAppId, this.accessControlConfiguration, this.accessControlConfiguration.id).subscribe(
result => {
this.snackBar.open('Access Control configuration saved', 'OK', {
duration: 3000
});
},
error => {
this.snackBar.open('Error saving Access Control configuration saved', 'OK', {
duration: 3000
});
}
);
}
private generateTables = (): void => {
this.displayedColumns = ['name'];
this.allRoles.roles.forEach(role => {
this.displayedColumns.push(role.id);
});
// Create in dataSource all rows with the appropriate order
this.dataSource.push({ initial: 'Routes', isGroupBy: true });
this.accessControlConfiguration.allowedRoutes.forEach(route => this.dataSource.push({name: route, type: 'route'}));
this.dataSource.push({ initial: 'Buttons', isGroupBy: true });
this.accessControlConfiguration.allowedButtonIds.forEach(buttonId => this.dataSource.push({ name: buttonId, type: 'button' }));
// Update the dataSource with the previous configuration
this.accessControlConfiguration.configuration.forEach(configElement => {
// Routes
configElement.routes.forEach(configRoute => {
let row = this.dataSource.filter(entry => entry.name === configRoute)[0];
row[configElement.roleId] = true;
})
// ButtonsIds
configElement.buttonIds.forEach(configRoute => {
let row = this.dataSource.filter(entry => entry.name === configRoute)[0];
row[configElement.roleId] = true;
})
});
}
public isSelected = (row, role): boolean => {
return row[role];
}
public toggle = (row, role: string) => {
let dsRow = this.dataSource.filter(entry => entry.name === row.name)[0];
if (dsRow[role]) {
delete dsRow[role];
} else {
dsRow[role] = true;
}
}
}
<div fxLayout="column" fxFill>
<tc-tibco-cloud-widget-header style="height: 40px;" [icon]="'tcs-capabilities'"
[headerText]="'Access Control Configuration'">
</tc-tibco-cloud-widget-header>
<div fxFlex style="padding: 20px; overflow: hidden" fxLayout="column">
<div style="overflow: auto;" fxFlex fxLayout="column">
<div fxLayout="column">
<p>You can configure roles by here:</p>
<br>
<table fxFlex mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<ng-container *ngFor="let role of allRoles.roles" matColumnDef="{{role.id}}">
<th mat-header-cell *matHeaderCellDef [ngClass]="'centered-cell'">{{role.id}}</th>
<td mat-cell [ngClass]="'centered-cell'" *matCellDef="let row">
<!-- (click)="$event.stopPropagation()" (change)="$event ? selection.toggle(row) : null" [checked]="selection.isSelected(row)" -->
<mat-checkbox [disabled]="(row.type === 'button' && row.name === 'configure') || (row.type === 'route' && row.name === '/starterApp/configuration') "
(click)="$event.stopPropagation()" [checked]="isSelected(row, role.id)"
(change)="$event ? toggle(row, role.id) : null"
></mat-checkbox>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<!-- Group header -->
<ng-container matColumnDef="groupHeader">
<td colspan="999" mat-cell *matCellDef="let groupBy"><strong>{{groupBy.initial}}</strong></td>
</ng-container>
<tr mat-row *matRowDef="let row; columns: ['groupHeader']; when: isGroup"></tr>
</table>
</div>
<div fxFlex class="tcs-filler-panel"></div>
<div fxLayout="row" fxLayoutAlign="end end" fxLayoutGap="10px" style="min-height: 50px">
<button mat-raised-button color="primary" (click)="runSaveFunction()">Save</button>
</div>
</div>
</div>
</div>
.centered-cell {
text-align: center;
}
Legend
Html element with directive