2 Copyright 2020 TATA ELXSI
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
16 Author: KUMARAN M (kumaran.m@tataelxsi.co.in), RAJESH S (rajesh.s@tataelxsi.co.in), BARATH KUMAR R (barath.r@tataelxsi.co.in)
20 * @file Header Component
22 import { Component, Injector, OnInit } 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 { AuthenticationService } from 'AuthenticationService';
27 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
28 import { environment } from 'environment';
29 import { ProjectService } from 'ProjectService';
30 import { Observable } from 'rxjs';
31 import { SharedService, isNullOrUndefined } from 'SharedService';
32 import { UserSettingsComponent } from 'UserSettingsComponent';
36 * @Component takes HeaderComponent.html as template url
39 selector: 'app-header',
40 templateUrl: './HeaderComponent.html',
41 styleUrls: ['./HeaderComponent.scss']
43 /** Exporting a class @exports HeaderComponent */
44 export class HeaderComponent implements OnInit {
45 /** Invoke service injectors @public */
46 public injector: Injector;
48 /** Variables holds all the projects @public */
49 public projectList$: Observable<{}[]>;
51 /** Observable holds logined value @public */
52 public username$: Observable<string>;
54 /** Variables holds admin is logged or not @public */
55 public isAdmin: boolean;
57 /** Variables holds the selected project @public */
58 public selectedProject: Observable<string>;
60 /** project @public */
61 public getSelectedProject: string;
63 /** Version holds packages version @public */
64 public PACKAGEVERSION: string;
66 /** To check the role of the user is systemadmin or not @public */
67 public isSystemAdmin: boolean;
69 /** Contains all methods related to shared @public */
70 public sharedService: SharedService;
72 /** Property contains to show new version tag shared @public */
73 public toShowNewTag: Boolean = false;
75 /** handle translate @public */
76 public translateService: TranslateService;
78 /** Version holds version @public */
79 public getLocalStorageVersion: string;
81 /** Utilizes auth service for any auth operations @private */
82 private authService: AuthenticationService;
84 /** Holds all project details @private */
85 private projectService: ProjectService;
87 /** Utilizes modal service for any modal operations @private */
88 private modalService: NgbModal;
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);
96 this.translateService = this.injector.get(TranslateService);
99 /** Lifecyle Hooks the trigger before component is instantiate @public */
100 public ngOnInit(): void {
101 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
102 this.isSystemAdmin = sessionStorage.getItem('admin_show') === 'true' ? true : false;
103 this.selectedProject = this.authService.ProjectName;
104 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
105 this.getSelectedProject = projectNameFinal;
107 this.sharedService.fetchOSMVersion();
108 this.username$ = this.authService.username;
109 this.projectService.setHeaderProjects();
110 this.projectList$ = this.projectService.projectList;
111 this.PACKAGEVERSION = environment.packageVersion;
112 if (!isNullOrUndefined(sessionStorage.getItem('version'))) {
113 this.getLocalStorageVersion = sessionStorage.getItem('version');
114 } else if (!isNullOrUndefined(this.sharedService.osmVersion)) {
115 this.getLocalStorageVersion = this.sharedService.osmVersion;
117 if (this.getLocalStorageVersion === null) {
118 this.showNewVersion();
119 } else if (this.getLocalStorageVersion !== sessionStorage.getItem('osmVersion')) {
120 this.showNewVersion();
124 /** Logout function @public */
125 public logout(): void {
126 this.authService.logout();
129 /** Show Version function @public */
130 public showNewVersion(): void {
131 this.toShowNewTag = true;
134 /** Close Version and add in local storage @public */
135 public closeVersion(): void {
136 this.toShowNewTag = false;
137 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
140 /** Implementation of model for UserSettings options.@public */
141 public userSettings(): void {
142 // eslint-disable-next-line security/detect-non-literal-fs-filename
143 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
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' });
150 modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
151 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
152 modalRef.componentInstance.userType = 'changePassword';
153 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
155 this.sharedService.callData();
157 }).catch((): void => {
158 // Catch Navigation Error