2 Copyright 2020 TATA ELXSI
4 Licensed under the Apache License, Version 2.0 (the 'License');
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
19 * @file Users Action Component
21 import { isNullOrUndefined } from 'util';
22 import { Component, Injector } from '@angular/core';
23 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24 import { TranslateService } from '@ngx-translate/core';
25 import { AddEditUserComponent } from 'AddEditUserComponent';
26 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
27 import { DeleteComponent } from 'DeleteComponent';
28 import { ProjectRoleComponent } from 'ProjectRoleComponent';
29 import { SharedService } from 'SharedService';
30 import { UserData } from 'UserModel';
31 import { WarningComponent } from 'WarningComponent';
34 * @Component takes UsersActionComponent.html as template url
37 templateUrl: './UsersActionComponent.html',
38 styleUrls: ['./UsersActionComponent.scss']
40 /** Exporting a class @exports UsersActionComponent */
41 export class UsersActionComponent {
42 /** To inject services @public */
43 public injector: Injector;
45 /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */
46 public value: UserData;
48 /** handle translate @public */
49 public translateService: TranslateService;
51 /** Admin Visibility Check @public */
52 public isAdminShow: boolean;
54 /** User Visibility Check @public */
55 public isUserShow: boolean;
57 /** User Status Check @public */
58 public isUserStatus: string;
60 /** Instance of the modal service @private */
61 private modalService: NgbModal;
63 /** Contains all methods related to shared @private */
64 private sharedService: SharedService;
66 constructor(injector: Injector) {
67 this.injector = injector;
68 this.modalService = this.injector.get(NgbModal);
69 this.sharedService = this.injector.get(SharedService);
70 this.translateService = this.injector.get(TranslateService);
74 * Lifecyle Hooks the trigger before component is instantiate
76 public ngOnInit(): void {
77 this.isAdminShow = sessionStorage.getItem('admin_show') === 'true' ? true : false;
78 this.isUserShow = sessionStorage.getItem('user_show') === 'true' ? true : false;
79 if (!isNullOrUndefined(this.value.user_status)) {
80 this.isUserStatus = this.value.user_status;
84 /** Delete User Account @public */
85 public deleteUser(): void {
86 // eslint-disable-next-line security/detect-non-literal-fs-filename
87 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
88 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
90 this.sharedService.callData();
92 }).catch((): void => {
93 // Catch Navigation Error
97 /** Edit User Account @public */
98 public editUserModal(editType: string): void {
99 // eslint-disable-next-line security/detect-non-literal-fs-filename
100 const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
101 modalRef.componentInstance.userID = this.value.identifier;
102 if (editType === 'editPassword') {
103 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
105 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITUSERNAME');
107 modalRef.componentInstance.userType = editType;
108 modalRef.componentInstance.userName = this.value.username;
109 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
111 this.sharedService.callData();
113 }).catch((): void => {
114 // Catch Navigation Error
118 /** Edit User Account @public */
119 public projectRolesModal(): void {
120 // eslint-disable-next-line security/detect-non-literal-fs-filename
121 const modalRef: NgbModalRef = this.modalService.open(ProjectRoleComponent, { backdrop: 'static' });
122 modalRef.componentInstance.userID = this.value.identifier;
123 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITPROJECTROLEMAPPING');
124 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
126 this.sharedService.callData();
128 }).catch((): void => {
129 // Catch Navigation Error
133 /** To Unlock or Renew User @public */
134 public unlockRenewUser(editType: string): void {
135 // eslint-disable-next-line security/detect-non-literal-fs-filename
136 const modalRef: NgbModalRef = this.modalService.open(WarningComponent, { backdrop: 'static' });
137 sessionStorage.setItem('renew', 'true');
138 const id: string = sessionStorage.getItem('user_id');
139 if (editType === 'unlock') {
140 modalRef.componentInstance.heading = this.translateService.instant('Unlock User');
141 modalRef.componentInstance.confirmationMessage = this.translateService.instant('Are you sure want to unlock this user');
142 modalRef.componentInstance.submitMessage = this.translateService.instant('Unlock');
143 modalRef.componentInstance.action = Boolean(true);
144 modalRef.componentInstance.editType = editType;
145 modalRef.componentInstance.id = this.value.identifier;
147 modalRef.componentInstance.heading = this.translateService.instant('Renew User');
148 modalRef.componentInstance.confirmationMessage = this.translateService.instant('Are you sure want to renew this user');
149 modalRef.componentInstance.submitMessage = this.translateService.instant('Renew');
150 modalRef.componentInstance.action = Boolean(true);
151 modalRef.componentInstance.editType = editType;
152 modalRef.componentInstance.id = this.value.identifier;
154 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
156 this.sharedService.callData();
158 }).catch((): void => {
159 // Catch Navigation Error