blob: a7b4c2480ad9178833fa81ae742ebe29d886e443 [file] [log] [blame]
kumaran.m3b4814a2020-05-01 19:48:54 +05301/*
2 Copyright 2020 TATA ELXSI
3
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
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
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.
15
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
17*/
18/**
19 * @file Users Action Component
20 */
21import { Component, Injector } from '@angular/core';
22import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
23import { TranslateService } from '@ngx-translate/core';
24import { AddEditUserComponent } from 'AddEditUserComponent';
25import { MODALCLOSERESPONSEDATA } from 'CommonModel';
26import { DeleteComponent } from 'DeleteComponent';
27import { ProjectRoleComponent } from 'ProjectRoleComponent';
SANDHYA.JSc84f1122024-06-04 21:50:03 +053028import { SharedService, isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053029import { UserData } from 'UserModel';
SANDHYA.JS1b17c432023-04-26 17:54:57 +053030import { WarningComponent } from 'WarningComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053031/**
32 * Creating component
33 * @Component takes UsersActionComponent.html as template url
34 */
35@Component({
36 templateUrl: './UsersActionComponent.html',
37 styleUrls: ['./UsersActionComponent.scss']
38})
39/** Exporting a class @exports UsersActionComponent */
40export class UsersActionComponent {
41 /** To inject services @public */
42 public injector: Injector;
43
44 /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */
45 public value: UserData;
46
47 /** handle translate @public */
48 public translateService: TranslateService;
49
SANDHYA.JS1b17c432023-04-26 17:54:57 +053050 /** Admin Visibility Check @public */
51 public isAdminShow: boolean;
52
53 /** User Visibility Check @public */
54 public isUserShow: boolean;
55
56 /** User Status Check @public */
57 public isUserStatus: string;
58
kumaran.m3b4814a2020-05-01 19:48:54 +053059 /** Instance of the modal service @private */
60 private modalService: NgbModal;
61
62 /** Contains all methods related to shared @private */
63 private sharedService: SharedService;
64
65 constructor(injector: Injector) {
66 this.injector = injector;
67 this.modalService = this.injector.get(NgbModal);
68 this.sharedService = this.injector.get(SharedService);
69 this.translateService = this.injector.get(TranslateService);
70 }
71
SANDHYA.JS1b17c432023-04-26 17:54:57 +053072 /**
73 * Lifecyle Hooks the trigger before component is instantiate
74 */
75 public ngOnInit(): void {
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +053076 this.isAdminShow = sessionStorage.getItem('admin_show') === 'true' ? true : false;
77 this.isUserShow = sessionStorage.getItem('user_show') === 'true' ? true : false;
SANDHYA.JS1b17c432023-04-26 17:54:57 +053078 if (!isNullOrUndefined(this.value.user_status)) {
79 this.isUserStatus = this.value.user_status;
80 }
81 }
82
kumaran.m3b4814a2020-05-01 19:48:54 +053083 /** Delete User Account @public */
84 public deleteUser(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053085 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +053086 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
87 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
88 if (result) {
89 this.sharedService.callData();
90 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053091 }).catch((): void => {
92 // Catch Navigation Error
93 });
kumaran.m3b4814a2020-05-01 19:48:54 +053094 }
95
96 /** Edit User Account @public */
97 public editUserModal(editType: string): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053098 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +053099 const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
100 modalRef.componentInstance.userID = this.value.identifier;
101 if (editType === 'editPassword') {
102 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
103 } else {
104 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITUSERNAME');
105 }
106 modalRef.componentInstance.userType = editType;
107 modalRef.componentInstance.userName = this.value.username;
108 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
109 if (result) {
110 this.sharedService.callData();
111 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530112 }).catch((): void => {
113 // Catch Navigation Error
114 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530115 }
116
117 /** Edit User Account @public */
118 public projectRolesModal(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530119 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530120 const modalRef: NgbModalRef = this.modalService.open(ProjectRoleComponent, { backdrop: 'static' });
121 modalRef.componentInstance.userID = this.value.identifier;
122 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITPROJECTROLEMAPPING');
123 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
124 if (result) {
125 this.sharedService.callData();
126 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530127 }).catch((): void => {
128 // Catch Navigation Error
129 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530130 }
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530131
132 /** To Unlock or Renew User @public */
133 public unlockRenewUser(editType: string): void {
134 // eslint-disable-next-line security/detect-non-literal-fs-filename
135 const modalRef: NgbModalRef = this.modalService.open(WarningComponent, { backdrop: 'static' });
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530136 sessionStorage.setItem('renew', 'true');
137 const id: string = sessionStorage.getItem('user_id');
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530138 if (editType === 'unlock') {
139 modalRef.componentInstance.heading = this.translateService.instant('Unlock User');
140 modalRef.componentInstance.confirmationMessage = this.translateService.instant('Are you sure want to unlock this user');
141 modalRef.componentInstance.submitMessage = this.translateService.instant('Unlock');
142 modalRef.componentInstance.action = Boolean(true);
143 modalRef.componentInstance.editType = editType;
144 modalRef.componentInstance.id = this.value.identifier;
145 } else {
146 modalRef.componentInstance.heading = this.translateService.instant('Renew User');
147 modalRef.componentInstance.confirmationMessage = this.translateService.instant('Are you sure want to renew this user');
148 modalRef.componentInstance.submitMessage = this.translateService.instant('Renew');
149 modalRef.componentInstance.action = Boolean(true);
150 modalRef.componentInstance.editType = editType;
151 modalRef.componentInstance.id = this.value.identifier;
152 }
153 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
154 if (result) {
155 this.sharedService.callData();
156 }
157 }).catch((): void => {
158 // Catch Navigation Error
159 });
160 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530161}