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 { isNullOrUndefined } from 'util';
23 import { Component, Injector, OnInit } from '@angular/core';
24 import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
25 import { TranslateService } from '@ngx-translate/core';
26 import { AddEditUserComponent } from 'AddEditUserComponent';
27 import { AuthenticationService } from 'AuthenticationService';
28 import { MODALCLOSERESPONSEDATA } from 'CommonModel';
29 import { environment } from 'environment';
30 import { ProjectService } from 'ProjectService';
31 import { Observable } from 'rxjs';
32 import { SharedService } from 'SharedService';
33 import { UserSettingsComponent } from 'UserSettingsComponent';
37 * @Component takes HeaderComponent.html as template url
40 selector: 'app-header',
41 templateUrl: './HeaderComponent.html',
42 styleUrls: ['./HeaderComponent.scss']
44 /** Exporting a class @exports HeaderComponent */
45 export class HeaderComponent implements OnInit {
46 /** Invoke service injectors @public */
47 public injector: Injector;
49 /** Variables holds all the projects @public */
50 public projectList$: Observable<{}[]>;
52 /** Observable holds logined value @public */
53 public username$: Observable<string>;
55 /** Variables holds admin is logged or not @public */
56 public isAdmin: boolean;
58 /** Variables holds the selected project @public */
59 public selectedProject: Observable<string>;
61 /** project @public */
62 public getSelectedProject: string;
64 /** Version holds packages version @public */
65 public PACKAGEVERSION: string;
67 /** To check the role of the user is systemadmin or not @public */
68 public isSystemAdmin: boolean;
70 /** Contains all methods related to shared @public */
71 public sharedService: SharedService;
73 /** Property contains to show new version tag shared @public */
74 public toShowNewTag: Boolean = false;
76 /** handle translate @public */
77 public translateService: TranslateService;
79 /** Version holds version @public */
80 public getLocalStorageVersion: string;
82 /** Utilizes auth service for any auth operations @private */
83 private authService: AuthenticationService;
85 /** Holds all project details @private */
86 private projectService: ProjectService;
88 /** Utilizes modal service for any modal operations @private */
89 private modalService: NgbModal;
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);
97 this.translateService = this.injector.get(TranslateService);
100 /** Lifecyle Hooks the trigger before component is instantiate @public */
101 public ngOnInit(): void {
102 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
103 this.isSystemAdmin = sessionStorage.getItem('admin_show') === 'true' ? true : false;
104 this.selectedProject = this.authService.ProjectName;
105 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
106 this.getSelectedProject = projectNameFinal;
108 this.sharedService.fetchOSMVersion();
109 this.username$ = this.authService.username;
110 this.projectService.setHeaderProjects();
111 this.projectList$ = this.projectService.projectList;
112 this.PACKAGEVERSION = environment.packageVersion;
113 if (!isNullOrUndefined(sessionStorage.getItem('version'))) {
114 this.getLocalStorageVersion = sessionStorage.getItem('version');
115 } else if (!isNullOrUndefined(this.sharedService.osmVersion)) {
116 this.getLocalStorageVersion = this.sharedService.osmVersion;
118 if (this.getLocalStorageVersion === null) {
119 this.showNewVersion();
120 } else if (this.getLocalStorageVersion !== sessionStorage.getItem('osmVersion')) {
121 this.showNewVersion();
125 /** Logout function @public */
126 public logout(): void {
127 this.authService.logout();
130 /** Show Version function @public */
131 public showNewVersion(): void {
132 this.toShowNewTag = true;
135 /** Close Version and add in local storage @public */
136 public closeVersion(): void {
137 this.toShowNewTag = false;
138 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
141 /** Implementation of model for UserSettings options.@public */
142 public userSettings(): void {
143 // eslint-disable-next-line security/detect-non-literal-fs-filename
144 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
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' });
151 modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
152 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
153 modalRef.componentInstance.userType = 'changePassword';
154 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
156 this.sharedService.callData();
158 }).catch((): void => {
159 // Catch Navigation Error