| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 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'; |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 29 | import { 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 */ |
| 41 | export 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 R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame^] | 66 | /** Property contains to show new version tag shared @public */ |
| 67 | public toShowNewTag: Boolean = false; |
| 68 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 69 | /** 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 { |
| 88 | this.isAdmin = (localStorage.getItem('isAdmin') === 'true') ? true : false; |
| 89 | this.selectedProject = this.authService.ProjectName; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame^] | 90 | this.authService.ProjectName.subscribe((projectNameFinal: string): void => { |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 91 | 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; |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame^] | 97 | const getLocalStorageVersion: string = localStorage.getItem('osmVersion'); |
| 98 | if (getLocalStorageVersion === null) { |
| 99 | this.showNewVersion(); |
| 100 | } else if (getLocalStorageVersion !== this.sharedService.osmVersion) { |
| 101 | this.showNewVersion(); |
| 102 | } |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** Logout function @public */ |
| 106 | public logout(): void { |
| 107 | this.authService.logout(); |
| 108 | } |
| 109 | |
| Barath Kumar R | 063a3f1 | 2020-12-29 16:35:09 +0530 | [diff] [blame^] | 110 | /** 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; |
| 118 | localStorage.setItem('osmVersion', this.sharedService.osmVersion); |
| 119 | } |
| 120 | |
| kumaran.m | 3b4814a | 2020-05-01 19:48:54 +0530 | [diff] [blame] | 121 | /** Implementation of model for UserSettings options.@public */ |
| 122 | public userSettings(): void { |
| 123 | this.modalService.open(UserSettingsComponent, { backdrop: 'static' }); |
| 124 | } |
| 125 | } |