Initial Commit - NG UI
* Roboto and font-awesome fonts are added in package.json
* Replace Nginx alpine varient to stable
* Devops files are added
* Docker file aligned as per community reviews
* Enhancement - NS primitive, Azure inclusion and domain name
* RWD changes
Change-Id: If543efbf127964cbd8f4be4c5a67260c91407fd9
Signed-off-by: kumaran.m <kumaran.m@tataelxsi.co.in>
diff --git a/src/app/roles/RolesComponent.html b/src/app/roles/RolesComponent.html
new file mode 100644
index 0000000..da59906
--- /dev/null
+++ b/src/app/roles/RolesComponent.html
@@ -0,0 +1,18 @@
+<!--
+Copyright 2020 TATA ELXSI
+
+Licensed under the Apache License, Version 2.0 (the 'License');
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+-->
+<router-outlet></router-outlet>
\ No newline at end of file
diff --git a/src/app/roles/RolesComponent.scss b/src/app/roles/RolesComponent.scss
new file mode 100644
index 0000000..f6cb0fe
--- /dev/null
+++ b/src/app/roles/RolesComponent.scss
@@ -0,0 +1,18 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+ */
+
diff --git a/src/app/roles/RolesComponent.ts b/src/app/roles/RolesComponent.ts
new file mode 100644
index 0000000..82f20b4
--- /dev/null
+++ b/src/app/roles/RolesComponent.ts
@@ -0,0 +1,58 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+*/
+/**
+ * @file Roles component.
+ */
+import { Component, Injector } from '@angular/core';
+import { Router, RouterEvent } from '@angular/router';
+
+/**
+ * Creating component
+ * @Component takes RolesComponent.html as template url
+ */
+@Component({
+ selector: 'app-roles',
+ templateUrl: './RolesComponent.html',
+ styleUrls: ['./RolesComponent.scss']
+})
+
+/** Exporting a class @exports RolesComponent */
+export class RolesComponent {
+ /** Invoke service injectors @public */
+ public injector: Injector;
+
+ /** Holds teh instance of router service @private */
+ private router: Router;
+
+ // creates role datails component
+ constructor(injector: Injector) {
+ this.injector = injector;
+ this.router = this.injector.get(Router);
+ this.router.events.subscribe((event: RouterEvent) => {
+ this.redirectToList(event.url);
+ });
+ }
+
+ /** Return to role datails list */
+ public redirectToList(getURL: string): void {
+ if (getURL === '/roles') {
+ this.router.navigate(['/roles/details']).catch();
+ }
+ }
+
+}
diff --git a/src/app/roles/RolesModule.ts b/src/app/roles/RolesModule.ts
new file mode 100644
index 0000000..88e1225
--- /dev/null
+++ b/src/app/roles/RolesModule.ts
@@ -0,0 +1,87 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+*/
+
+/**
+ * @file Roles Module
+ */
+import { CommonModule } from '@angular/common';
+import { HttpClientModule } from '@angular/common/http';
+import { NgModule } from '@angular/core';
+import { FormsModule } from '@angular/forms';
+import { ReactiveFormsModule } from '@angular/forms';
+import { RouterModule, Routes } from '@angular/router';
+import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
+import { TranslateModule } from '@ngx-translate/core';
+import { LoaderModule } from 'LoaderModule';
+import { Ng2SmartTableModule } from 'ng2-smart-table';
+import { PagePerRowModule } from 'PagePerRowModule';
+import { PageReloadModule } from 'PageReloadModule';
+import { RolesComponent } from 'Roles';
+import { RolesActionComponent } from 'RolesAction';
+import { RolesCreateEditComponent } from 'RolesCreateEdit';
+import { RolesDetailsComponent } from 'RolesDetails';
+
+/** const values for Roles Routes */
+const routes: Routes = [
+ {
+ path: '',
+ component: RolesComponent,
+ children: [
+ {
+ path: 'details',
+ data: {
+ breadcrumb: [{ title: 'PAGE.DASHBOARD.DASHBOARD', url: '/' }, { title: 'ROLES', url: null }]
+ },
+ component: RolesDetailsComponent
+ },
+ {
+ path: 'create',
+ data: {
+ breadcrumb: [{ title: 'PAGE.DASHBOARD.DASHBOARD', url: '/' }, { title: 'ROLES', url: '/roles/details' },
+ { title: 'PAGE.ROLES.CREATEROLE', url: null }]
+ },
+ component: RolesCreateEditComponent
+ },
+ {
+ path: 'edit/:id',
+ data: {
+ breadcrumb: [{ title: 'PAGE.DASHBOARD.DASHBOARD', url: '/' }, { title: 'ROLES', url: '/roles/details' },
+ { title: '{id}', url: null }]
+ },
+ component: RolesCreateEditComponent
+ }
+ ]
+ }
+];
+/**
+ * An NgModule is a class adorned with the @NgModule decorator function.
+ * @NgModule takes a metadata object that tells Angular how to compile and run module code.
+ */
+@NgModule({
+ imports: [FormsModule, ReactiveFormsModule, CommonModule, HttpClientModule, TranslateModule,
+ RouterModule.forChild(routes), NgbModule, PagePerRowModule, Ng2SmartTableModule, LoaderModule, PageReloadModule],
+ declarations: [RolesComponent, RolesDetailsComponent, RolesActionComponent, RolesCreateEditComponent],
+ entryComponents: [RolesActionComponent]
+})
+/**
+ * AppModule is the Root module for application
+ */
+export class RolesModule {
+ /** Variables declared to avoid state-less class */
+ private rolesModule: string;
+}
diff --git a/src/app/roles/roles-create-edit/RolesCreateEditComponent.html b/src/app/roles/roles-create-edit/RolesCreateEditComponent.html
new file mode 100644
index 0000000..7bb2a1f
--- /dev/null
+++ b/src/app/roles/roles-create-edit/RolesCreateEditComponent.html
@@ -0,0 +1,92 @@
+<!--
+Copyright 2020 TATA ELXSI
+
+Licensed under the Apache License, Version 2.0 (the 'License');
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+-->
+<div class="row d-flex flex-row justify-content-between">
+ <div class="d-flex align-items-center header-style">
+ {{ (getRoleType == 'Add' ? 'PAGE.ROLES.CREATEROLE' : 'PAGE.ROLES.EDITROLE') | translate}}</div>
+ <span class="button">
+ <button class="btn btn-primary" type="button" (click)="viewSelection()" placement="top" container="body"
+ ngbTooltip="{{ (viewMode == 'text' ? 'PAGE.ROLES.PREVIEW' : 'PAGE.ROLES.TEXTVIEW') | translate}}"> <i
+ [ngClass]="{ 'fa': 'true', 'fa-comment': viewMode == 'text', 'fa-edit': viewMode == 'preview' }"></i> {{ (viewMode == 'text' ? 'PAGE.ROLES.PREVIEW' : 'PAGE.ROLES.TEXTVIEW') | translate}}
+ </button>
+ </span>
+</div>
+<form [formGroup]="roleForm" (ngSubmit)="roleCheck()" autocomplete="off">
+ <div class="form-group row">
+ <label class="col-sm-12 col-form-label mandatory-label"
+ [ngClass]="{'text-danger': roleForm.invalid === true && submitted === true}">{{'MANDATORYCHECK' | translate}}</label>
+ <label class="col-sm-2 col-form-label">{{'NAME' | translate}}*</label>
+ <div class="col-sm-5">
+ <input placeholder="{{'NAME' | translate}}" type="text" class="form-control" maxlength="30"
+ formControlName="roleName" [ngClass]="{ 'is-invalid': submitted && f.roleName.errors }" required>
+ </div>
+ </div>
+ <div class="form-group row" *ngIf="viewMode == 'text'">
+ <label class="col-sm-2 col-form-label">{{'PAGE.ROLES.PERMISSIONS' | translate}}</label>
+ <div class="col-sm-5">
+ <textarea placeholder="{{'PAGE.ROLES.YAMLPERMISSIONS' | translate}}" rows="10" cols="50" type="text"
+ class="form-control" formControlName="permissions"></textarea>
+ </div>
+ </div>
+ <div class="form-group row" [ngClass]="{ 'justify-content-end': viewMode == 'text' }">
+ <div class="col-sm-6">
+ <button type="button" class="btn btn-danger" routerLink="/roles/details">{{'CANCEL' | translate}}</button>
+ <button class="btn btn-primary ml-3"
+ type="submit">{{ (getRoleType == 'Add' ? 'CREATE' : 'APPLY') | translate}}</button>
+ </div>
+ </div>
+</form>
+<ngb-accordion class="roles-section" [closeOthers]="true" type="secondary" *ngIf="rolePermissions && viewMode == 'preview'">
+ <ngb-panel *ngFor="let permissionGroup of rolePermissions; let i = index">
+ <ng-template ngbPanelHeader let-opened="opened">
+ <div class="d-flex align-items-center justify-content-between">
+ <button ngbPanelToggle class="btn text-dark container-fluid text-left pl-0"><i
+ [ngClass]="{ 'fas': true, 'fa-angle-down': opened, 'fa-angle-right': !opened }"></i> {{permissionGroup.title}}</button>
+ </div>
+ </ng-template>
+ <ng-template ngbPanelContent>
+ <div class="row">
+ <div class="col-lg-4 col-md-6 col-sm-12" *ngFor="let permission of permissionGroup.permissions">
+ <div class="row">
+ <div class="col-md-6 col-sm-6 p-2">{{permission.operation}}</div>
+ <div class="btn-group btn-group-toggle custom-button col-md-6 col-sm-6" ngbRadioGroup name="permission"
+ [(ngModel)]="permission.value">
+ <label ngbButtonLabel ngbTooltip="true">
+ <input ngbButton type="radio" [value]="true">
+ <span class="bg-success"><img src="assets/images/TICK.svg" alt="Checked Icon" /></span>
+ </label>
+ <label ngbButtonLabel ngbTooltip="NA">
+ <input ngbButton type="radio" value="NA">
+ <span class="bg-warning"><img src="assets/images/TICK.svg" alt="Checked Icon" /></span>
+ </label>
+ <label ngbButtonLabel ngbTooltip="false">
+ <input ngbButton type="radio" [value]="false">
+ <span class="bg-danger"><img src="assets/images/TICK.svg" alt="Checked Icon" /></span>
+ </label>
+ </div>
+ </div>
+ </div>
+ </div>
+ </ng-template>
+ </ngb-panel>
+</ngb-accordion>
+<div class="float-right" *ngIf="viewMode == 'preview'">
+ <button type="button" class="btn btn-danger" routerLink="/roles/details">{{'CANCEL' | translate}}</button>
+ <button class="btn btn-primary ml-3"
+ (click)="roleCheck()">{{ (getRoleType == 'Add' ? 'CREATE' : 'APPLY') | translate}}</button>
+</div>
+<app-loader [waitingMessage]="message" *ngIf="isLoadingResults"></app-loader>
\ No newline at end of file
diff --git a/src/app/roles/roles-create-edit/RolesCreateEditComponent.scss b/src/app/roles/roles-create-edit/RolesCreateEditComponent.scss
new file mode 100644
index 0000000..362973a
--- /dev/null
+++ b/src/app/roles/roles-create-edit/RolesCreateEditComponent.scss
@@ -0,0 +1,51 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+*/
+@import '../../../assets/scss/mixins/mixin';
+@import '../../../assets/scss/variable';
+ .custom-button{
+ label {
+ @include padding-value(2,2,2,2);
+ &.active {
+ @include background(null, $white, null, null, null);
+ span{
+ img {
+ opacity: 1;
+ }
+ }
+ }
+ input[type="radio"] {
+ display: none;
+ }
+ span {
+ display: inline-block;
+ @include wh-value(30px,30px);
+ cursor: pointer;
+ border-radius: 50%;
+ @include border(all,2,solid, $white);
+ @include box-shadow(0px, 1px, 3px, 0px, $dark);
+ @include background(null, null, null, no-repeat, center);
+ text-align: center;
+ @include line-height(25px);
+ img {
+ width:50%;
+ opacity: 0;
+ @include transition(all, 0.3, null, ease);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/app/roles/roles-create-edit/RolesCreateEditComponent.ts b/src/app/roles/roles-create-edit/RolesCreateEditComponent.ts
new file mode 100644
index 0000000..0419c5f
--- /dev/null
+++ b/src/app/roles/roles-create-edit/RolesCreateEditComponent.ts
@@ -0,0 +1,335 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+*/
+/**
+ * @file Roles Create and Edit Component
+ */
+import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { Component, Injector, Input, OnInit } from '@angular/core';
+import { FormBuilder, FormGroup, Validators } from '@angular/forms';
+import { ActivatedRoute, Router } from '@angular/router';
+import { TranslateService } from '@ngx-translate/core';
+import { NotifierService } from 'angular-notifier';
+import { APIURLHEADER, ERRORDATA } from 'CommonModel';
+import { environment } from 'environment';
+import * as jsonpath from 'jsonpath';
+import { RestService } from 'RestService';
+import { Permission, PermissionGroup, RoleConfig, RoleData } from 'RolesModel';
+import { SharedService } from 'SharedService';
+import { isNullOrUndefined } from 'util';
+
+/**
+ * Creating component
+ * @Component takes RolesCreateEditComponent.html as template url
+ */
+@Component({
+ selector: 'app-roles-create-edit',
+ templateUrl: './RolesCreateEditComponent.html',
+ styleUrls: ['./RolesCreateEditComponent.scss']
+})
+/** Exporting a class @exports RolesCreateEditComponent */
+export class RolesCreateEditComponent implements OnInit {
+ /** To inject services @public */
+ public injector: Injector;
+
+ /** contains role permissions from config file @public */
+ public rolePermissions: {}[];
+
+ /** contains role form group information @public */
+ public roleForm: FormGroup;
+
+ /** Instance of the rest service @public */
+ public restService: RestService;
+
+ /** Check the loading results for loader status @public */
+ public isLoadingResults: boolean = false;
+
+ /** Give the message for the loading @public */
+ public message: string = 'PLEASEWAIT';
+
+ /** Instance to check role form submitted status @public */
+ public submitted: boolean = false;
+
+ /** Contains role create or edit value @public */
+ public getRoleType: string;
+
+ /** Contains view selection value either text or preview @public */
+ public viewMode: string = 'text';
+
+ /** Contains role id value @private */
+ private roleRef: string;
+
+ /** Notifier service to popup notification @private */
+ private notifierService: NotifierService;
+
+ /** Contains tranlsate instance @private */
+ private translateService: TranslateService;
+
+ /** contians form builder module @private */
+ private formBuilder: FormBuilder;
+
+ /** Contains all methods related to shared @private */
+ private sharedService: SharedService;
+
+ /** Controls the header form @private */
+ private headers: HttpHeaders;
+
+ /** Varaibles to hold http client @private */
+ private httpClient: HttpClient;
+
+ /** Holds the instance of activatedRoute of router service @private */
+ private activatedRoute: ActivatedRoute;
+
+ /** Holds the instance of roter service @private */
+ private router: Router;
+
+ constructor(injector: Injector) {
+ this.injector = injector;
+ this.restService = this.injector.get(RestService);
+ this.notifierService = this.injector.get(NotifierService);
+ this.translateService = this.injector.get(TranslateService);
+ this.formBuilder = this.injector.get(FormBuilder);
+ this.sharedService = this.injector.get(SharedService);
+ this.httpClient = this.injector.get(HttpClient);
+ this.activatedRoute = this.injector.get(ActivatedRoute);
+ this.router = this.injector.get(Router);
+ }
+
+ /** Lifecyle Hooks the trigger before component is instantiate @public */
+ public ngOnInit(): void {
+ this.headers = new HttpHeaders({
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
+ 'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0'
+ });
+ this.roleForm = this.formBuilder.group({
+ roleName: ['', [Validators.required]],
+ permissions: ['']
+ });
+ this.getRolePermissions();
+ }
+
+ /** Get role permission information based on action @public */
+ public getRolePermissions(): void {
+ this.isLoadingResults = true;
+ this.loadPermissions().then((response: RoleConfig) => {
+ this.rolePermissions = response.rolePermissions;
+ if (this.activatedRoute.snapshot.url[0].path === 'create') {
+ this.getRoleType = 'Add';
+ this.isLoadingResults = false;
+ } else {
+ this.getRoleType = 'Edit';
+ this.getRoleData();
+ }
+ }).catch(() => {
+ // Empty Block
+ });
+ }
+
+ /** Check Role Create or Edit and proceed action @public */
+ public roleCheck(): void {
+ this.submitted = true;
+ if (!this.roleForm.valid) {
+ const errorIp: Element = document.querySelector('.ng-invalid[formControlName]');
+ if (errorIp) {
+ errorIp.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ } else {
+ if (this.getRoleType === 'Add') {
+ this.createRole();
+ } else {
+ this.editRole();
+ }
+ }
+ }
+
+ /** Convenience getter for easy access to form fields */
+ get f(): FormGroup['controls'] { return this.roleForm.controls; }
+
+ /** Create role @private */
+ public createRole(): void {
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.ROLES_URL,
+ httpOptions: { headers: this.headers }
+ };
+ let permissionData: Object = {};
+ this.sharedService.cleanForm(this.roleForm);
+ if (!this.roleForm.invalid) {
+ if (this.viewMode === 'preview') {
+ this.isLoadingResults = true;
+ permissionData = this.generatePermissions();
+ this.roleCreateAPI(apiURLHeader, permissionData);
+ } else {
+ if (this.checkPermission()) {
+ this.isLoadingResults = true;
+ permissionData = this.roleForm.value.permissions !== '' ? JSON.parse(this.roleForm.value.permissions) : {};
+ this.roleCreateAPI(apiURLHeader, permissionData);
+ }
+ }
+ }
+ }
+
+ /** Method to handle role create API call @public */
+ public roleCreateAPI(apiURLHeader: APIURLHEADER, permissionData: {}): void {
+ const postData: {} = {
+ name: this.roleForm.value.roleName,
+ permissions: !isNullOrUndefined(permissionData) ? permissionData : {}
+ };
+ this.restService.postResource(apiURLHeader, postData).subscribe(() => {
+ this.notifierService.notify('success', this.translateService.instant('PAGE.ROLES.CREATEDSUCCESSFULLY'));
+ this.router.navigate(['/roles/details']).catch();
+ }, (error: ERRORDATA) => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'post');
+ });
+ }
+
+ /** Edit role @private */
+ public editRole(): void {
+ const apiURLHeader: APIURLHEADER = {
+ url: environment.ROLES_URL + '/' + this.roleRef,
+ httpOptions: { headers: this.headers }
+ };
+ let permissionData: Object = {};
+ this.sharedService.cleanForm(this.roleForm);
+ if (!this.roleForm.invalid) {
+ if (this.viewMode === 'preview') {
+ this.isLoadingResults = true;
+ permissionData = this.generatePermissions();
+ this.roleEditAPI(apiURLHeader, permissionData);
+ } else {
+ if (this.checkPermission()) {
+ this.isLoadingResults = true;
+ permissionData = this.roleForm.value.permissions !== '' ? JSON.parse(this.roleForm.value.permissions) : {};
+ this.roleEditAPI(apiURLHeader, permissionData);
+ }
+ }
+ }
+ }
+
+ /** Method to handle role edit API call */
+ public roleEditAPI(apiURLHeader: APIURLHEADER, permissionData: {}): void {
+ const postData: {} = {
+ name: this.roleForm.value.roleName,
+ permissions: !isNullOrUndefined(permissionData) ? permissionData : {}
+ };
+ this.restService.patchResource(apiURLHeader, postData).subscribe(() => {
+ this.notifierService.notify('success', this.translateService.instant('PAGE.ROLES.UPDATEDSUCCESSFULLY'));
+ this.router.navigate(['/roles/details']).catch();
+ }, (error: ERRORDATA) => {
+ this.isLoadingResults = false;
+ this.restService.handleError(error, 'patch');
+ });
+ }
+
+ /** Method to handle toggle role view selection @public */
+ public viewSelection(): void {
+ if (this.viewMode === 'text' && this.checkPermission()) {
+ this.loadPermissions().then((response: RoleConfig) => {
+ this.rolePermissions = response.rolePermissions;
+ const permissions: {} = this.roleForm.value.permissions !== '' ? JSON.parse(this.roleForm.value.permissions) : {};
+ this.filterRoleData(permissions);
+ this.viewMode = 'preview';
+ }).catch(() => {
+ // Empty Block
+ });
+ } else {
+ const rolePermission: {} = this.generatePermissions();
+ if (Object.keys(rolePermission).length !== 0) {
+ this.roleForm.patchValue({ permissions: JSON.stringify(rolePermission, null, '\t') });
+ }
+ this.viewMode = 'text';
+ }
+
+ }
+
+ /** Generate role permission post data @private */
+ private generatePermissions(): Object {
+ const permissions: Object = {};
+ this.rolePermissions.forEach((permissionGroup: PermissionGroup) => {
+ if (!isNullOrUndefined(permissionGroup)) {
+ permissionGroup.permissions.forEach((permission: Permission) => {
+ if (!isNullOrUndefined(permission.value) && permission.value !== 'NA') {
+ permissions[permission.operation] = permission.value;
+ }
+ });
+ }
+ });
+ return permissions;
+ }
+
+ /** Validation method for check permission json string @private */
+ private checkPermission(): boolean {
+ if (this.roleForm.value.permissions) {
+ if (!this.sharedService.checkJson(this.roleForm.value.permissions)) {
+ this.notifierService.notify('error', this.translateService.instant('PAGE.ROLES.ROLEJSONERROR'));
+ return false;
+ } else {
+ this.roleForm.value.permissions = this.roleForm.value.permissions.replace(/'/g, '"');
+ const rolePermission: {} = JSON.parse(this.roleForm.value.permissions);
+ for (const key of Object.keys(rolePermission)) {
+ if (typeof rolePermission[key] !== 'boolean') {
+ this.notifierService.notify('error', this.translateService.instant('PAGE.ROLES.ROLEKEYERROR', { roleKey: key }));
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ /** Get role data from NBI based on ID and apply filter @private */
+ private getRoleData(): void {
+ // tslint:disable-next-line: no-backbone-get-set-outside-model
+ this.roleRef = this.activatedRoute.snapshot.paramMap.get('id');
+ if (!isNullOrUndefined(this.roleRef)) {
+ this.restService.getResource(environment.ROLES_URL + '/' + this.roleRef).subscribe((data: RoleData) => {
+ this.roleForm.setValue({ roleName: data.name, permissions: JSON.stringify(data.permissions, null, '\t') });
+ this.filterRoleData(data.permissions);
+ this.isLoadingResults = false;
+ }, (error: ERRORDATA) => {
+ this.router.navigate(['/roles/details']).catch();
+ this.restService.handleError(error, 'get');
+ });
+ }
+ }
+
+ /** Method to filter role data @private */
+ private filterRoleData(permissions: {}): void {
+ Object.keys(permissions).forEach((permission: string) => {
+ jsonpath.apply(this.rolePermissions, '$..permissions[?(@.operation == "' + permission + '")]', (response: Permission) => {
+ if (response.operation === permission) {
+ response.value = permissions[permission];
+ }
+ return response;
+ });
+ });
+ }
+
+ /** Method to load the role permission Json file @private */
+ private async loadPermissions(): Promise<Object> {
+ const jsonFile: string = environment.PERMISSIONS_CONFIG_FILE + '?cb=' + new Date().getTime();
+ return new Promise<Object>((resolve: Function, reject: Function): void => {
+ this.httpClient.get(jsonFile).subscribe((response: Response) => {
+ resolve(response);
+ }, (error: {}) => {
+ reject();
+ });
+ });
+ }
+
+}
diff --git a/src/app/roles/roles-details/RolesDetailsComponent.html b/src/app/roles/roles-details/RolesDetailsComponent.html
new file mode 100644
index 0000000..28a3fe7
--- /dev/null
+++ b/src/app/roles/roles-details/RolesDetailsComponent.html
@@ -0,0 +1,36 @@
+<!--
+Copyright 2020 TATA ELXSI
+
+Licensed under the Apache License, Version 2.0 (the 'License');
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+-->
+<div class="row d-flex flex-row justify-content-between">
+ <div class="d-flex align-items-center header-style">{{'ROLES' | translate}}</div>
+ <span class="button">
+ <button class="btn btn-primary" type="button" (click)="createRole()" placement="top"
+ container="body" ngbTooltip="{{'PAGE.ROLES.CREATEROLE' | translate}}">
+ <i class="fas fa-plus-circle" aria-hidden="true"></i>
+ {{'PAGE.ROLES.CREATEROLE' | translate}}
+ </button>
+ </span>
+</div>
+<div class="row mt-2 mb-0 form-group justify-content-end list-utilites-actions">
+ <page-per-row class="mr-2" (pagePerRow)="onChange($event)"></page-per-row>
+ <page-reload></page-reload>
+</div>
+<div class="smarttable-style bg-white mt-1">
+ <ng2-smart-table [settings]="settings" [source]="dataSource" (userRowSelect)="onUserRowSelect($event)">
+ </ng2-smart-table>
+</div>
+<app-loader [waitingMessage]="message" *ngIf="isLoadingResults"></app-loader>
\ No newline at end of file
diff --git a/src/app/roles/roles-details/RolesDetailsComponent.scss b/src/app/roles/roles-details/RolesDetailsComponent.scss
new file mode 100644
index 0000000..021d205
--- /dev/null
+++ b/src/app/roles/roles-details/RolesDetailsComponent.scss
@@ -0,0 +1,17 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+*/
\ No newline at end of file
diff --git a/src/app/roles/roles-details/RolesDetailsComponent.ts b/src/app/roles/roles-details/RolesDetailsComponent.ts
new file mode 100644
index 0000000..2568f5a
--- /dev/null
+++ b/src/app/roles/roles-details/RolesDetailsComponent.ts
@@ -0,0 +1,191 @@
+/*
+ Copyright 2020 TATA ELXSI
+
+ Licensed under the Apache License, Version 2.0 (the 'License');
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
+*/
+/**
+ * @file Roles Deatils component.
+ */
+import { Component, Injector, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
+import { TranslateService } from '@ngx-translate/core';
+import { ERRORDATA } from 'CommonModel';
+import { DataService } from 'DataService';
+import { environment } from 'environment';
+import { LocalDataSource } from 'ng2-smart-table';
+import { RestService } from 'RestService';
+import { RolesActionComponent } from 'RolesAction';
+import { RoleData, RoleDetails } from 'RolesModel';
+import { Subscription } from 'rxjs';
+import { SharedService } from 'SharedService';
+
+/**
+ * Creating component
+ * @Component takes RolesComponent.html as template url
+ */
+@Component({
+ selector: 'app-roles-details',
+ templateUrl: './RolesDetailsComponent.html',
+ styleUrls: ['./RolesDetailsComponent.scss']
+})
+export class RolesDetailsComponent implements OnInit {
+ /** To inject services @public */
+ public injector: Injector;
+
+ /** Formation of appropriate Data for LocalDatasource @public */
+ public dataSource: LocalDataSource = new LocalDataSource();
+
+ /** handle translate @public */
+ public translateService: TranslateService;
+
+ /** Columns list of the smart table @public */
+ public columnLists: object = {};
+
+ /** Settings for smarttable to populate the table with columns @public */
+ public settings: object = {};
+
+ /** Check the loading results @public */
+ public isLoadingResults: boolean = true;
+
+ /** Give the message for the loading @public */
+ public message: string = 'PLEASEWAIT';
+
+ /** Instance of the rest service @private */
+ private restService: RestService;
+
+ /** dataService to pass the data from one component to another @private */
+ private dataService: DataService;
+
+ /** Contains role details data @private */
+ private roleData: RoleData[] = [];
+
+ /** Contains all methods related to shared @private */
+ private sharedService: SharedService;
+
+ /** Instance of subscriptions @private */
+ private generateDataSub: Subscription;
+
+ /** Holds the instance of roter service @private */
+ private router: Router;
+
+ constructor(injector: Injector) {
+ this.injector = injector;
+ this.restService = this.injector.get(RestService);
+ this.dataService = this.injector.get(DataService);
+ this.sharedService = this.injector.get(SharedService);
+ this.translateService = this.injector.get(TranslateService);
+ this.router = this.injector.get(Router);
+ }
+ /** Lifecyle Hooks the trigger before component is instantiate @public */
+ public ngOnInit(): void {
+ this.generateColumns();
+ this.generateSettings();
+ this.generateData();
+ this.generateDataSub = this.sharedService.dataEvent.subscribe(() => { this.generateData(); });
+ }
+ /** smart table Header Colums @public */
+ public generateColumns(): void {
+ this.columnLists = {
+ name: { title: this.translateService.instant('NAME'), width: '30%', sortDirection: 'asc' },
+ identifier: { title: this.translateService.instant('IDENTIFIER'), width: '35%' },
+ modified: { title: this.translateService.instant('MODIFIED'), width: '15%' },
+ created: { title: this.translateService.instant('CREATED'), width: '15%' },
+ Actions: {
+ name: 'Actions', width: '5%', filter: false, sort: false, type: 'custom',
+ title: this.translateService.instant('ACTIONS'),
+ valuePrepareFunction: (cell: RoleData, row: RoleData): RoleData => row,
+ renderComponent: RolesActionComponent
+ }
+ };
+ }
+
+ /** smart table Data Settings @public */
+ public generateSettings(): void {
+ this.settings = {
+ edit: {
+ editButtonContent: '<i class="fa fa-edit" title="Edit"></i>',
+ confirmSave: true
+ },
+ delete: {
+ deleteButtonContent: '<i class="far fa-trash-alt" title="delete"></i>',
+ confirmDelete: true
+ },
+ columns: this.columnLists,
+ actions: {
+ add: false,
+ edit: false,
+ delete: false,
+ topology: false,
+ position: 'right'
+ },
+ attr: this.sharedService.tableClassConfig(),
+ pager: this.sharedService.paginationPagerConfig(),
+ noDataMessage: this.translateService.instant('NODATAMSG')
+ };
+ }
+
+ /** smart table listing manipulation @public */
+ public onChange(perPageValue: number): void {
+ this.dataSource.setPaging(1, perPageValue, true);
+ }
+
+ /** convert UserRowSelect Function @private */
+ public onUserRowSelect(event: MessageEvent): void {
+ Object.assign(event.data, { page: 'roles' });
+ this.dataService.changeMessage(event.data);
+ }
+
+ /** Fetching the role data from API and Load it in the smarttable @public */
+ public generateData(): void {
+ this.isLoadingResults = true;
+ this.roleData = [];
+ this.restService.getResource(environment.ROLES_URL).subscribe((roleList: RoleDetails[]) => {
+ roleList.forEach((role: RoleDetails) => {
+ const roleDataObj: RoleData = this.generateRoleData(role);
+ this.roleData.push(roleDataObj);
+ });
+ this.dataSource.load(this.roleData).then((data: boolean) => {
+ this.isLoadingResults = false;
+ }).catch();
+ }, (error: ERRORDATA) => {
+ this.restService.handleError(error, 'get');
+ this.isLoadingResults = false;
+ });
+ }
+
+ /** Generate role data object and return for the datasource @public */
+ public generateRoleData(roleData: RoleDetails): RoleData {
+ return {
+ name: roleData.name,
+ identifier: roleData._id,
+ modified: this.sharedService.convertEpochTime(Number(roleData._admin.modified)),
+ created: this.sharedService.convertEpochTime(Number(roleData._admin.created)),
+ permissions: roleData.permissions
+ };
+ }
+
+ /** Create role click handler @public */
+ public createRole(): void {
+ this.router.navigate(['/roles/create']).catch(() => {
+ // Catch Navigation Error
+ });
+ }
+
+ /** Lifecyle hook which get trigger on component destruction @private */
+ public ngOnDestroy(): void {
+ this.generateDataSub.unsubscribe();
+ }
+
+}