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 App Components
22 import { Component, HostListener, Injector } from '@angular/core';
23 import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
24 import { DEFAULT_INTERRUPTSOURCES, Idle } from '@ng-idle/core';
25 import { AuthenticationService } from 'AuthenticationService';
26 import { DeviceCheckService } from 'DeviceCheckService';
27 import { SharedService, isNullOrUndefined } from 'SharedService';
31 * @Component takes AppComponent.html as template url
35 templateUrl: './AppComponent.html',
36 styleUrls: ['./AppComponent.scss']
38 /** Exporting a class @exports AppComponent */
39 export class AppComponent {
40 /** Handle idle time out @public */
41 public idleTime: number;
42 /** To inject services @public */
43 public injector: Injector;
44 /** Instance for modal service @public */
45 public modalService: NgbModal;
46 /** Device Check service @private */
47 private deviceCheckService: DeviceCheckService;
48 /** Utilizes auth service for any auth operations @private */
49 private authService: AuthenticationService;
50 /** Handle idle time out service @private */
52 /** Contains all methods related to shared @private */
53 private sharedService: SharedService;
55 constructor(injector: Injector) {
56 this.injector = injector;
57 this.idle = this.injector.get(Idle);
58 this.authService = this.injector.get(AuthenticationService);
59 this.modalService = this.injector.get(NgbModal);
60 this.deviceCheckService = this.injector.get(DeviceCheckService);
62 this.sharedService = this.injector.get(SharedService);
66 * Lifecyle Hooks the trigger before component is instantiate
68 public ngOnInit(): void {
69 this.sharedService.fetchOSMVersion();
72 /** To handle handleIdle @public */
73 public handleIdle(): void {
74 if (!isNullOrUndefined((sessionStorage.getItem('timeout')))) {
75 this.idleTime = Number(sessionStorage.getItem('timeout'));
79 const idleTimeOutWarning: number = 5;
80 // sets an idle timeout in seconds.
81 this.idle.setIdle(this.idleTime);
82 //sets a timeout period in seconds. after idleTime seconds of inactivity, the user will be considered timed out.
83 this.idle.setTimeout(idleTimeOutWarning);
84 // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document
85 this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);
86 this.idle.watch(true);
90 /** Method to capture idle time out event @public */
91 public idleTimeOut(): void {
92 this.idle.onTimeout.subscribe(() => {
94 if (sessionStorage.getItem('id_token') !== null) {
95 this.authService.logout();
100 /** Handling Window's Storage Hostlistener @public */
101 @HostListener('window:storage', ['$event'])
102 public handleLocalStorageEvent(evt: StorageEvent): void {
104 if (evt.key === 'token_state' && !isNullOrUndefined(evt.key)) {
105 if (evt.oldValue !== evt.newValue) {
106 window.location.reload();
109 // On Langauges Change
110 if (evt.key === 'languageCode' && !isNullOrUndefined(evt.key)) {
111 if (evt.oldValue !== evt.newValue) {
112 window.location.reload();
117 /** Handling Window's POP State Hostlistener @public */
118 @HostListener('window:popstate', ['$event'])
119 public handleOnPOPState(evt: PopStateEvent): void {
120 this.modalService.dismissAll();
123 /** Handling Window's orientationchange Hostlistener @public */
124 @HostListener('window:resize', ['$event'])
125 public onResize(event: Event): void {
126 this.deviceCheckService.checkDeviceType();