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 } from '@ng-bootstrap/ng-bootstrap';
24 import { AuthenticationService } from 'AuthenticationService';
25 import { environment } from 'environment';
26 import { ProjectService } from 'ProjectService';
27 import { Observable } from 'rxjs';
28 import { SharedService } from 'SharedService';
29 import { UserSettingsComponent } from 'UserSettingsComponent';
33 * @Component takes HeaderComponent.html as template url
36 selector: 'app-header',
37 templateUrl: './HeaderComponent.html',
38 styleUrls: ['./HeaderComponent.scss']
40 /** Exporting a class @exports HeaderComponent */
41 export class HeaderComponent implements OnInit {
42 /** Invoke service injectors @public */
43 public injector: Injector;
45 /** Variables holds all the projects @public */
46 public projectList$: Observable<{}[]>;
48 /** Observable holds logined value @public */
49 public username$: Observable<string>;
51 /** Variables holds admin is logged or not @public */
52 public isAdmin: boolean;
54 /** Variables holds the selected project @public */
55 public selectedProject: Observable<string>;
57 /** project @public */
58 public getSelectedProject: string;
60 /** Version holds packages version @public */
61 public PACKAGEVERSION: string;
63 /** Contains all methods related to shared @public */
64 public sharedService: SharedService;
66 /** Property contains to show new version tag shared @public */
67 public toShowNewTag: Boolean = false;
69 /** Utilizes auth service for any auth operations @private */
70 private authService: AuthenticationService;
72 /** Holds all project details @private */
73 private projectService: ProjectService;
75 /** Utilizes modal service for any modal operations @private */
76 private modalService: NgbModal;
78 constructor(injector: Injector) {
79 this.injector = injector;
80 this.authService = this.injector.get(AuthenticationService);
81 this.modalService = this.injector.get(NgbModal);
82 this.projectService = this.injector.get(ProjectService);
83 this.sharedService = this.injector.get(SharedService);
86 /** Lifecyle Hooks the trigger before component is instantiate @public */
87 public ngOnInit(): void {
88 this.isAdmin = (localStorage.getItem('isAdmin') === 'true') ? true : false;
89 this.selectedProject = this.authService.ProjectName;
90 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
91 this.getSelectedProject = projectNameFinal;
93 this.username$ = this.authService.username;
94 this.projectService.setHeaderProjects();
95 this.projectList$ = this.projectService.projectList;
96 this.PACKAGEVERSION = environment.packageVersion;
97 const getLocalStorageVersion: string = localStorage.getItem('osmVersion');
98 if (getLocalStorageVersion === null) {
99 this.showNewVersion();
100 } else if (getLocalStorageVersion !== this.sharedService.osmVersion) {
101 this.showNewVersion();
105 /** Logout function @public */
106 public logout(): void {
107 this.authService.logout();
110 /** Show Version function @public */
111 public showNewVersion(): void {
112 this.toShowNewTag = true;
115 /** Close Version and add in local storage @public */
116 public closeVersion(): void {
117 this.toShowNewTag = false;
118 localStorage.setItem('osmVersion', this.sharedService.osmVersion);
121 /** Implementation of model for UserSettings options.@public */
122 public userSettings(): void {
123 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });