blob: f90b5b643198efd2ed66bd4bb64db076aedac6a1 [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';
23import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
24import { AuthenticationService } from 'AuthenticationService';
25import { environment } from 'environment';
26import { ProjectService } from 'ProjectService';
27import { Observable } from 'rxjs';
28import { SharedService } from 'SharedService';
kumaran.m3b4814a2020-05-01 19:48:54 +053029import { UserSettingsComponent } from 'UserSettingsComponent';
30
31/**
32 * Creating component
33 * @Component takes HeaderComponent.html as template url
34 */
35@Component({
36 selector: 'app-header',
37 templateUrl: './HeaderComponent.html',
38 styleUrls: ['./HeaderComponent.scss']
39})
40/** Exporting a class @exports HeaderComponent */
41export class HeaderComponent implements OnInit {
42 /** Invoke service injectors @public */
43 public injector: Injector;
44
45 /** Variables holds all the projects @public */
46 public projectList$: Observable<{}[]>;
47
48 /** Observable holds logined value @public */
49 public username$: Observable<string>;
50
51 /** Variables holds admin is logged or not @public */
52 public isAdmin: boolean;
53
54 /** Variables holds the selected project @public */
55 public selectedProject: Observable<string>;
56
57 /** project @public */
58 public getSelectedProject: string;
59
60 /** Version holds packages version @public */
61 public PACKAGEVERSION: string;
62
63 /** Contains all methods related to shared @public */
64 public sharedService: SharedService;
65
Barath Kumar R063a3f12020-12-29 16:35:09 +053066 /** Property contains to show new version tag shared @public */
67 public toShowNewTag: Boolean = false;
68
kumaran.m3b4814a2020-05-01 19:48:54 +053069 /** Utilizes auth service for any auth operations @private */
70 private authService: AuthenticationService;
71
72 /** Holds all project details @private */
73 private projectService: ProjectService;
74
75 /** Utilizes modal service for any modal operations @private */
76 private modalService: NgbModal;
77
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);
84 }
85
86 /** Lifecyle Hooks the trigger before component is instantiate @public */
87 public ngOnInit(): void {
SANDHYA.JSa055cd92023-05-10 18:23:06 +053088 this.isAdmin = (sessionStorage.getItem('isAdmin') === 'true') ? true : false;
kumaran.m3b4814a2020-05-01 19:48:54 +053089 this.selectedProject = this.authService.ProjectName;
Barath Kumar R063a3f12020-12-29 16:35:09 +053090 this.authService.ProjectName.subscribe((projectNameFinal: string): void => {
kumaran.m3b4814a2020-05-01 19:48:54 +053091 this.getSelectedProject = projectNameFinal;
92 });
93 this.username$ = this.authService.username;
94 this.projectService.setHeaderProjects();
95 this.projectList$ = this.projectService.projectList;
96 this.PACKAGEVERSION = environment.packageVersion;
SANDHYA.JSa055cd92023-05-10 18:23:06 +053097 const getLocalStorageVersion: string = sessionStorage.getItem('osmVersion');
Barath Kumar R063a3f12020-12-29 16:35:09 +053098 if (getLocalStorageVersion === null) {
99 this.showNewVersion();
100 } else if (getLocalStorageVersion !== this.sharedService.osmVersion) {
101 this.showNewVersion();
102 }
kumaran.m3b4814a2020-05-01 19:48:54 +0530103 }
104
105 /** Logout function @public */
106 public logout(): void {
107 this.authService.logout();
108 }
109
Barath Kumar R063a3f12020-12-29 16:35:09 +0530110 /** Show Version function @public */
111 public showNewVersion(): void {
112 this.toShowNewTag = true;
113 }
114
115 /** Close Version and add in local storage @public */
116 public closeVersion(): void {
117 this.toShowNewTag = false;
SANDHYA.JSa055cd92023-05-10 18:23:06 +0530118 sessionStorage.setItem('osmVersion', this.sharedService.osmVersion);
Barath Kumar R063a3f12020-12-29 16:35:09 +0530119 }
120
kumaran.m3b4814a2020-05-01 19:48:54 +0530121 /** Implementation of model for UserSettings options.@public */
122 public userSettings(): void {
123 this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
124 }
125}