blob: cb0b462add025ba3367ea06aa27873af99ed098c [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';
28import { SharedService } from 'SharedService';
29import { UserData } from 'UserModel';
30/**
31 * Creating component
32 * @Component takes UsersActionComponent.html as template url
33 */
34@Component({
35 templateUrl: './UsersActionComponent.html',
36 styleUrls: ['./UsersActionComponent.scss']
37})
38/** Exporting a class @exports UsersActionComponent */
39export class UsersActionComponent {
40 /** To inject services @public */
41 public injector: Injector;
42
43 /** To get the value from the Users action via valuePrepareFunction default Property of ng-smarttable @public */
44 public value: UserData;
45
46 /** handle translate @public */
47 public translateService: TranslateService;
48
49 /** Instance of the modal service @private */
50 private modalService: NgbModal;
51
52 /** Contains all methods related to shared @private */
53 private sharedService: SharedService;
54
55 constructor(injector: Injector) {
56 this.injector = injector;
57 this.modalService = this.injector.get(NgbModal);
58 this.sharedService = this.injector.get(SharedService);
59 this.translateService = this.injector.get(TranslateService);
60 }
61
62 /** Delete User Account @public */
63 public deleteUser(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053064 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +053065 const modalRef: NgbModalRef = this.modalService.open(DeleteComponent, { backdrop: 'static' });
66 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
67 if (result) {
68 this.sharedService.callData();
69 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053070 }).catch((): void => {
71 // Catch Navigation Error
72 });
kumaran.m3b4814a2020-05-01 19:48:54 +053073 }
74
75 /** Edit User Account @public */
76 public editUserModal(editType: string): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +053077 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +053078 const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
79 modalRef.componentInstance.userID = this.value.identifier;
80 if (editType === 'editPassword') {
81 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
82 } else {
83 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITUSERNAME');
84 }
85 modalRef.componentInstance.userType = editType;
86 modalRef.componentInstance.userName = this.value.username;
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 projectRolesModal(): 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(ProjectRoleComponent, { backdrop: 'static' });
100 modalRef.componentInstance.userID = this.value.identifier;
101 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITPROJECTROLEMAPPING');
102 modalRef.result.then((result: MODALCLOSERESPONSEDATA) => {
103 if (result) {
104 this.sharedService.callData();
105 }
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530106 }).catch((): void => {
107 // Catch Navigation Error
108 });
kumaran.m3b4814a2020-05-01 19:48:54 +0530109 }
110}