Initial Commit - NG UI
[osm/NG-UI.git] / src / app / layouts / header / HeaderComponent.ts
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';
29 import { ProjectRoleMappings, UserDetail } from 'UserModel';
30 import { UserSettingsComponent } from 'UserSettingsComponent';
31
32 /**
33  * Creating component
34  * @Component takes HeaderComponent.html as template url
35  */
36 @Component({
37     selector: 'app-header',
38     templateUrl: './HeaderComponent.html',
39     styleUrls: ['./HeaderComponent.scss']
40 })
41 /** Exporting a class @exports HeaderComponent */
42 export class HeaderComponent implements OnInit {
43     /** Invoke service injectors @public */
44     public injector: Injector;
45
46     /** Variables holds all the projects @public */
47     public projectList$: Observable<{}[]>;
48
49     /** Observable holds logined value  @public */
50     public username$: Observable<string>;
51
52     /** Variables holds admin is logged or not @public */
53     public isAdmin: boolean;
54
55     /** Variables holds the selected project @public */
56     public selectedProject: Observable<string>;
57
58     /** project @public */
59     public getSelectedProject: string;
60
61     /** Version holds packages version @public */
62     public PACKAGEVERSION: string;
63
64     /** Contains all methods related to shared @public */
65     public sharedService: SharedService;
66
67     /** Utilizes auth service for any auth operations @private */
68     private authService: AuthenticationService;
69
70     /** Holds all project details @private */
71     private projectService: ProjectService;
72
73     /** Utilizes modal service for any modal operations @private */
74     private modalService: NgbModal;
75
76     constructor(injector: Injector) {
77         this.injector = injector;
78         this.authService = this.injector.get(AuthenticationService);
79         this.modalService = this.injector.get(NgbModal);
80         this.projectService = this.injector.get(ProjectService);
81         this.sharedService = this.injector.get(SharedService);
82     }
83
84     /** Lifecyle Hooks the trigger before component is instantiate @public */
85     public ngOnInit(): void {
86         this.isAdmin = (localStorage.getItem('isAdmin') === 'true') ? true : false;
87         this.selectedProject = this.authService.ProjectName;
88         this.authService.ProjectName.subscribe((projectNameFinal: string) => {
89             this.getSelectedProject = projectNameFinal;
90         });
91         this.username$ = this.authService.username;
92         this.projectService.setHeaderProjects();
93         this.projectList$ = this.projectService.projectList;
94         this.PACKAGEVERSION = environment.packageVersion;
95     }
96
97     /** Logout function  @public */
98     public logout(): void {
99         this.authService.logout();
100     }
101
102     /** Implementation of model for UserSettings options.@public */
103     public userSettings(): void {
104         this.modalService.open(UserSettingsComponent, { backdrop: 'static' });
105     }
106 }