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 } 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 /** Utilizes auth service for any auth operations @private */
79 private authService: AuthenticationService;
81 /** Holds all project details @private */
82 private projectService: ProjectService;
84 /** Utilizes modal service for any modal operations @private */
85 private modalService: NgbModal;
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);
93 this.translateService = this.injector.get(TranslateService);
96 /** Lifecyle Hooks the trigger before component is instantiate @public */
97 public ngOnInit(): void {
98 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
99 this.isSystemAdmin = sessionStorage.getItem('admin_show') === 'true' ? true : false;
100 this.selectedProject = this.authService.ProjectName;
101 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
102 this.getSelectedProject = projectNameFinal;
104 this.username$ = this.authService.username;
105 this.projectService.setHeaderProjects();
106 this.projectList$ = this.projectService.projectList;
107 this.PACKAGEVERSION = environment.packageVersion;
108 const getLocalStorageVersion: string = sessionStorage.getItem('osmVersion');
109 if (getLocalStorageVersion === null) {
110 this.showNewVersion();
111 } else if (getLocalStorageVersion !== this.sharedService.osmVersion) {
112 this.showNewVersion();
116 /** Logout function @public */
117 public logout(): void {
118 this.authService.logout();
121 /** Show Version function @public */
122 public showNewVersion(): void {
123 this.toShowNewTag = true;
126 /** Close Version and add in local storage @public */
127 public closeVersion(): void {
128 this.toShowNewTag = false;
129 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
132 /** Implementation of model for UserSettings options.@public */
133 public userSettings(): void {
134 // eslint-disable-next-line security/detect-non-literal-fs-filename
135 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
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' });
142 modalRef.componentInstance.userID = sessionStorage.getItem('user_id');
143 modalRef.componentInstance.userTitle = this.translateService.instant('PAGE.USERS.EDITCREDENTIALS');
144 modalRef.componentInstance.userType = 'changePassword';
145 modalRef.result.then((result: MODALCLOSERESPONSEDATA): void => {
147 this.sharedService.callData();
149 }).catch((): void => {
150 // Catch Navigation Error