| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 21 | import { isNullOrUndefined } from 'util'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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'; |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 31 | import { WarningComponent } from 'WarningComponent'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 32 | /** |
| 33 | * Creating component |
| 34 | * @Component takes UsersActionComponent.html as template url |
| 35 | */ |
| 36 | @Component({ |
| 37 | templateUrl: './UsersActionComponent.html', |
| 38 | styleUrls: ['./UsersActionComponent.scss'] |
| 39 | }) |
| 40 | /** Exporting a class @exports UsersActionComponent */ |
| 41 | export class UsersActionComponent { |
| 42 | /** To inject services @public */ |
| 43 | public injector: Injector; |
| 44 | |
| 45 | /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */ |
| 46 | public value: UserData; |
| 47 | |
| 48 | /** handle translate @public */ |
| 49 | public translateService: TranslateService; |
| 50 | |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 51 | /** Admin Visibility Check @public */ |
| 52 | public isAdminShow: boolean; |
| 53 | |
| 54 | /** User Visibility Check @public */ |
| 55 | public isUserShow: boolean; |
| 56 | |
| 57 | /** User Status Check @public */ |
| 58 | public isUserStatus: string; |
| 59 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 60 | /** Instance of the modal service @private */ |
| 61 | private modalService: NgbModal; |
| 62 | |
| 63 | /** Contains all methods related to shared @private */ |
| 64 | private sharedService: SharedService; |
| 65 | |
| 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); |
| 71 | } |
| 72 | |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 73 | /** |
| 74 | * Lifecyle Hooks the trigger before component is instantiate |
| 75 | */ |
| 76 | public ngOnInit(): void { |
| SANDHYA.JS | 5b35bcd | 2023-04-27 15:11:06 +0530 | [diff] [blame^] | 77 | this.isAdminShow = sessionStorage.getItem('admin_show') === 'true' ? true : false; |
| 78 | this.isUserShow = sessionStorage.getItem('user_show') === 'true' ? true : false; |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 79 | if (!isNullOrUndefined(this.value.user_status)) { |
| 80 | this.isUserStatus = this.value.user_status; |
| 81 | } |
| 82 | } |
| 83 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 84 | /** Delete User Account @public */ |
| 85 | public deleteUser(): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 86 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 87 | const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' }); |
| 88 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 89 | if (result) { |
| 90 | this.sharedService.callData(); |
| 91 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 92 | }).catch((): void => { |
| 93 | // Catch Navigation Error |
| 94 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** Edit User Account @public */ |
| 98 | public editUserModal(editType: string): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 99 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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'); |
| 104 | } else { |
| 105 | modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITUSERNAME'); |
| 106 | } |
| 107 | modalRef.componentInstance.userType = editType; |
| 108 | modalRef.componentInstance.userName = this.value.username; |
| 109 | modalRef.result.then((result: MODALCLOSERESPONSEDATA) => { |
| 110 | if (result) { |
| 111 | this.sharedService.callData(); |
| 112 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 113 | }).catch((): void => { |
| 114 | // Catch Navigation Error |
| 115 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** Edit User Account @public */ |
| 119 | public projectRolesModal(): void { |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 120 | // eslint-disable-next-line security/detect-non-literal-fs-filename |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 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) => { |
| 125 | if (result) { |
| 126 | this.sharedService.callData(); |
| 127 | } |
| SANDHYA.JS | 0a34dfa | 2023-04-25 23:59:41 +0530 | [diff] [blame] | 128 | }).catch((): void => { |
| 129 | // Catch Navigation Error |
| 130 | }); |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 131 | } |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 132 | |
| 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' }); |
| SANDHYA.JS | 5b35bcd | 2023-04-27 15:11:06 +0530 | [diff] [blame^] | 137 | sessionStorage.setItem('renew', 'true'); |
| 138 | const id: string = sessionStorage.getItem('user_id'); |
| SANDHYA.JS | 1b17c43 | 2023-04-26 17:54:57 +0530 | [diff] [blame] | 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; |
| 146 | } else { |
| 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; |
| 153 | } |
| 154 | modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => { |
| 155 | if (result) { |
| 156 | this.sharedService.callData(); |
| 157 | } |
| 158 | }).catch((): void => { |
| 159 | // Catch Navigation Error |
| 160 | }); |
| 161 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 162 | } |