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