blob: 13e2129a209d2a14f84809e8c8bf85e209a03a90 [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';
31import { SharedService } 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
kumaran.m3b4814a2020-05-01 19:48:54 +053078 /** Utilizes auth service for any auth operations @private */
79 private authService: AuthenticationService;
80
81 /** Holds all project details @private */
82 private projectService: ProjectService;
83
84 /** Utilizes modal service for any modal operations @private */
85 private modalService: NgbModal;
86
87 constructor(injector: Injector) {
88 this.injector = injector;
89 this.authService = this.injector.get(AuthenticationService);
90 this.modalService = this.injector.get(NgbModal);
91 this.projectService = this.injector.get(ProjectService);
92 this.sharedService = this.injector.get(SharedService);
SANDHYA.JS1b17c432023-04-26 17:54:57 +053093 this.translateService = this.injector.get(TranslateService);
kumaran.m3b4814a2020-05-01 19:48:54 +053094 }
95
96 /** Lifecyle Hooks the trigger before component is instantiate @public */
97 public ngOnInit(): void {
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +053098 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
99 this.isSystemAdmin = sessionStorage.getItem('admin_show') === 'true' ? true : false;
kumaran.m3b4814a2020-05-01 19:48:54 +0530100 this.selectedProject = this.authService.ProjectName;
Barath Kumar R063a3f12020-12-29 16:35:09 +0530101 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +0530102 this.getSelectedProject = projectNameFinal;
103 });
104 this.username$ = this.authService.username;
105 this.projectService.setHeaderProjects();
106 this.projectList$ = this.projectService.projectList;
107 this.PACKAGEVERSION = environment.packageVersion;
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530108 const getLocalStorageVersion: string = sessionStorage.getItem('osmVersion');
Barath Kumar R063a3f12020-12-29 16:35:09 +0530109 if (getLocalStorageVersion === null) {
110 this.showNewVersion();
111 } else if (getLocalStorageVersion !== this.sharedService.osmVersion) {
112 this.showNewVersion();
113 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530114 }
115
116 /** Logout function @public */
117 public logout(): void {
118 this.authService.logout();
119 }
120
Barath Kumar R063a3f12020-12-29 16:35:09 +0530121 /** Show Version function @public */
122 public showNewVersion(): void {
123 this.toShowNewTag = true;
124 }
125
126 /** Close Version and add in local storage @public */
127 public closeVersion(): void {
128 this.toShowNewTag = false;
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530129 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530130 }
131
kumaran.m3b4814a2020-05-01 19:48:54 +0530132 /** Implementation of model for UserSettings options.@public */
133 public userSettings(): void {
SANDHYA.JS0a34dfa2023-04-25 23:59:41 +0530134 // eslint-disable-next-line security/detect-non-literal-fs-filename
kumaran.m3b4814a2020-05-01 19:48:54 +0530135 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
136 }
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530137
138 /** ChangePassword Function @public */
139 public changePassword(): void {
140 // eslint-disable-next-line security/detect-non-literal-fs-filename
141 const modalRef: NgbModalRef = this.modalService.open(AddEditUserComponent, { backdrop: 'static' });
SANDHYA.JS5b35bcd2023-04-27 15:11:06 +0530142 modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
SANDHYA.JS1b17c432023-04-26 17:54:57 +0530143 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
144 modalRef.componentInstance.userType = 'changePassword';
145 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
146 if (result) {
147 this.sharedService.callData();
148 }
149 }).catch((): void => {
150 // Catch Navigation Error
151 });
152 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530153}