blob: fa932b87fd5fd4c3561960ff9150fe8f429e82a8 [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/**
20 * @file Header Component
21 */
SANDHYA.JS995c6722024-03-08 12:14:11 +053022import { isNullOrUndefined } from 'util';
kumaran.m3b4814a2020-05-01 19:48:54 +053023import { Component, Injector, OnInit } from '@angular/core';
SANDHYA.JS1b17c432023-04-26 17:54:57 +053024import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
25import { TranslateService } from '@ngx-translate/core';
26import { AddEditUserComponent } from 'AddEditUserComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053027import { AuthenticationService } from 'AuthenticationService';
SANDHYA.JS1b17c432023-04-26 17:54:57 +053028import { MODALCLOSERESPONSEDATA } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053029import { environment } from 'environment';
30import { ProjectService } from 'ProjectService';
31import { Observable } from 'rxjs';
32import { SharedService } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053033import { UserSettingsComponent } from 'UserSettingsComponent';
34
35/**
36 * Creating component
37 * @Component takes HeaderComponent.html as template url
38 */
39@Component({
40 selector: 'app-header',
41 templateUrl: './HeaderComponent.html',
42 styleUrls: ['./HeaderComponent.scss']
43})
44/** Exporting a class @exports HeaderComponent */
45export class HeaderComponent implements OnInit {
46 /** Invoke service injectors @public */
47 public injector: Injector;
48
49 /** Variables holds all the projects @public */
50 public projectList$: Observable<{}[]>;
51
52 /** Observable holds logined value @public */
53 public username$: Observable<string>;
54
55 /** Variables holds admin is logged or not @public */
56 public isAdmin: boolean;
57
58 /** Variables holds the selected project @public */
59 public selectedProject: Observable<string>;
60
61 /** project @public */
62 public getSelectedProject: string;
63
64 /** Version holds packages version @public */
65 public PACKAGEVERSION: string;
66
SANDHYA.JS1b17c432023-04-26 17:54:57 +053067 /** To check the role of the user is systemadmin or not @public */
68 public isSystemAdmin: boolean;
69
kumaran.m3b4814a2020-05-01 19:48:54 +053070 /** Contains all methods related to shared @public */
71 public sharedService: SharedService;
72
Barath Kumar R063a3f12020-12-29 16:35:09 +053073 /** Property contains to show new version tag shared @public */
74 public toShowNewTag: Boolean = false;
75
SANDHYA.JS1b17c432023-04-26 17:54:57 +053076 /** handle translate @public */
77 public translateService: TranslateService;
78
SANDHYA.JS995c6722024-03-08 12:14:11 +053079 /** Version holds version @public */
80 public getLocalStorageVersion: string;
81
kumaran.m3b4814a2020-05-01 19:48:54 +053082 /** Utilizes auth service for any auth operations @private */
83 private authService: AuthenticationService;
84
85 /** Holds all project details @private */
86 private projectService: ProjectService;
87
88 /** Utilizes modal service for any modal operations @private */
89 private modalService: NgbModal;
90
91 constructor(injector: Injector) {
92 this.injector = injector;
93 this.authService = this.injector.get(AuthenticationService);
94 this.modalService = this.injector.get(NgbModal);
95 this.projectService = this.injector.get(ProjectService);
96 this.sharedService = this.injector.get(SharedService);
SANDHYA.JS1b17c432023-04-26 17:54:57 +053097 this.translateService = this.injector.get(TranslateService);
kumaran.m3b4814a2020-05-01 19:48:54 +053098 }
99
100 /** Lifecyle Hooks the trigger before component is instantiate @public */
101 public ngOnInit(): void {
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530102 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
103 this.isSystemAdmin = sessionStorage.getItem('admin_show') === 'true' ? true : false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530104 this.selectedProject = this.authService.ProjectName;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530105 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530106 this.getSelectedProject = projectNameFinal;
107 });
SANDHYA.JS995c6722024-03-08 12:14:11 +0530108 this.sharedService.fetchOSMVersion();
kumaran.m3b4814a2020-05-01 19:48:54 +0530109 this.username$ = this.authService.username;
110 this.projectService.setHeaderProjects();
111 this.projectList$ = this.projectService.projectList;
112 this.PACKAGEVERSION = environment.packageVersion;
SANDHYA.JS995c6722024-03-08 12:14:11 +0530113 if (!isNullOrUndefined(sessionStorage.getItem('version'))) {
114 this.getLocalStorageVersion = sessionStorage.getItem('version');
115 } else if (!isNullOrUndefined(this.sharedService.osmVersion)) {
116 this.getLocalStorageVersion = this.sharedService.osmVersion;
117 }
118 if (this.getLocalStorageVersion === null) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530119 this.showNewVersion();
SANDHYA.JS995c6722024-03-08 12:14:11 +0530120 } else if (this.getLocalStorageVersion !== sessionStorage.getItem('osmVersion')) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530121 this.showNewVersion();
122 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530123 }
124
125 /** Logout function @public */
126 public logout(): void {
127 this.authService.logout();
128 }
129
Barath Kumar R063a3f12020-12-29 16:35:09 +0530130 /** Show Version function @public */
131 public showNewVersion(): void {
132 this.toShowNewTag = true;
133 }
134
135 /** Close Version and add in local storage @public */
136 public closeVersion(): void {
137 this.toShowNewTag = false;
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530138 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530139 }
140
kumaran.m3b4814a2020-05-01 19:48:54 +0530141 /** Implementation of model for UserSettings options.@public */
142 public userSettings(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530143 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530144 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
145 }
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530146
147 /** ChangePassword Function @public */
148 public changePassword(): void {
149 // eslint-disable-next-line security/detect-non-literal-fs-filename
150 const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530151 modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530152 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
153 modalRef.componentInstance.userType = 'changePassword';
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.m3b4814a2020-05-01 19:48:54 +0530162}