blob: 45807f948dda2d69565275e6a29f4896b4ff88ec [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 */
22import { Component, Injector, OnInit } from '@angular/core';
SANDHYA.JS1b17c432023-04-26 17:54:57 +053023import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
24import { TranslateService } from '@ngx-translate/core';
25import { AddEditUserComponent } from 'AddEditUserComponent';
kumaran.m3b4814a2020-05-01 19:48:54 +053026import { AuthenticationService } from 'AuthenticationService';
SANDHYA.JS1b17c432023-04-26 17:54:57 +053027import { MODALCLOSERESPONSEDATA } from 'CommonModel';
kumaran.m3b4814a2020-05-01 19:48:54 +053028import { environment } from 'environment';
29import { ProjectService } from 'ProjectService';
30import { Observable } from 'rxjs';
SANDHYA.JSc84f1122024-06-04 21:50:03 +053031import { SharedService, isNullOrUndefined } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053032import { UserSettingsComponent } from 'UserSettingsComponent';
33
34/**
35 * Creating component
36 * @Component takes HeaderComponent.html as template url
37 */
38@Component({
39 selector: 'app-header',
40 templateUrl: './HeaderComponent.html',
41 styleUrls: ['./HeaderComponent.scss']
42})
43/** Exporting a class @exports HeaderComponent */
44export class HeaderComponent implements OnInit {
45 /** Invoke service injectors @public */
46 public injector: Injector;
47
48 /** Variables holds all the projects @public */
49 public projectList$: Observable<{}[]>;
50
51 /** Observable holds logined value @public */
52 public username$: Observable<string>;
53
54 /** Variables holds admin is logged or not @public */
55 public isAdmin: boolean;
56
57 /** Variables holds the selected project @public */
58 public selectedProject: Observable<string>;
59
60 /** project @public */
61 public getSelectedProject: string;
62
63 /** Version holds packages version @public */
64 public PACKAGEVERSION: string;
65
SANDHYA.JS1b17c432023-04-26 17:54:57 +053066 /** To check the role of the user is systemadmin or not @public */
67 public isSystemAdmin: boolean;
68
kumaran.m3b4814a2020-05-01 19:48:54 +053069 /** Contains all methods related to shared @public */
70 public sharedService: SharedService;
71
Barath Kumar R063a3f12020-12-29 16:35:09 +053072 /** Property contains to show new version tag shared @public */
73 public toShowNewTag: Boolean = false;
74
SANDHYA.JS1b17c432023-04-26 17:54:57 +053075 /** handle translate @public */
76 public translateService: TranslateService;
77
SANDHYA.JS995c6722024-03-08 12:14:11 +053078 /** Version holds version @public */
79 public getLocalStorageVersion: string;
80
kumaran.m3b4814a2020-05-01 19:48:54 +053081 /** Utilizes auth service for any auth operations @private */
82 private authService: AuthenticationService;
83
84 /** Holds all project details @private */
85 private projectService: ProjectService;
86
87 /** Utilizes modal service for any modal operations @private */
88 private modalService: NgbModal;
89
90 constructor(injector: Injector) {
91 this.injector = injector;
92 this.authService = this.injector.get(AuthenticationService);
93 this.modalService = this.injector.get(NgbModal);
94 this.projectService = this.injector.get(ProjectService);
95 this.sharedService = this.injector.get(SharedService);
SANDHYA.JS1b17c432023-04-26 17:54:57 +053096 this.translateService = this.injector.get(TranslateService);
kumaran.m3b4814a2020-05-01 19:48:54 +053097 }
98
99 /** Lifecyle Hooks the trigger before component is instantiate @public */
100 public ngOnInit(): void {
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530101 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
102 this.isSystemAdmin = sessionStorage.getItem('admin_show') === 'true' ? true : false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530103 this.selectedProject = this.authService.ProjectName;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530104 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530105 this.getSelectedProject = projectNameFinal;
106 });
SANDHYA.JS995c6722024-03-08 12:14:11 +0530107 this.sharedService.fetchOSMVersion();
kumaran.m3b4814a2020-05-01 19:48:54 +0530108 this.username$ = this.authService.username;
109 this.projectService.setHeaderProjects();
110 this.projectList$ = this.projectService.projectList;
111 this.PACKAGEVERSION = environment.packageVersion;
SANDHYA.JS995c6722024-03-08 12:14:11 +0530112 if (!isNullOrUndefined(sessionStorage.getItem('version'))) {
113 this.getLocalStorageVersion = sessionStorage.getItem('version');
114 } else if (!isNullOrUndefined(this.sharedService.osmVersion)) {
115 this.getLocalStorageVersion = this.sharedService.osmVersion;
116 }
117 if (this.getLocalStorageVersion === null) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530118 this.showNewVersion();
SANDHYA.JS995c6722024-03-08 12:14:11 +0530119 } else if (this.getLocalStorageVersion !== sessionStorage.getItem('osmVersion')) {
Barath Kumar R063a3f12020-12-29 16:35:09 +0530120 this.showNewVersion();
121 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530122 }
123
124 /** Logout function @public */
125 public logout(): void {
126 this.authService.logout();
127 }
128
Barath Kumar R063a3f12020-12-29 16:35:09 +0530129 /** Show Version function @public */
130 public showNewVersion(): void {
131 this.toShowNewTag = true;
132 }
133
134 /** Close Version and add in local storage @public */
135 public closeVersion(): void {
136 this.toShowNewTag = false;
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530137 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530138 }
139
kumaran.m3b4814a2020-05-01 19:48:54 +0530140 /** Implementation of model for UserSettings options.@public */
141 public userSettings(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530142 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530143 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
144 }
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530145
146 /** ChangePassword Function @public */
147 public changePassword(): void {
148 // eslint-disable-next-line security/detect-non-literal-fs-filename
149 const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530150 modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530151 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
152 modalRef.componentInstance.userType = 'changePassword';
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}