2017-08-15 16:39:19 +02:00
|
|
|
import {Component, OnDestroy, OnInit} from '@angular/core';
|
|
|
|
|
import {Subscription} from "rxjs/Subscription";
|
|
|
|
|
import {TimerObservable} from "rxjs/observable/TimerObservable";
|
|
|
|
|
|
|
|
|
|
import {KanbanService} from "./kanban/shared/kanban.service";
|
2017-09-08 09:43:50 +02:00
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
2017-08-23 19:06:55 +02:00
|
|
|
import {SelfUpdaterService} from "./kanban/shared/self-updater.service";
|
2017-09-08 15:42:27 +02:00
|
|
|
import {TspInfoService} from "./tsp-info/shared/tsp-info.service";
|
2017-08-15 17:53:22 +02:00
|
|
|
|
2017-09-08 09:43:50 +02:00
|
|
|
|
2017-08-23 19:06:55 +02:00
|
|
|
const TIMER_DEPLOY_REFRESH = 30000;
|
2017-08-15 17:53:22 +02:00
|
|
|
const TIMER_JIRA_REFRESH = 60000;
|
2017-09-08 15:42:27 +02:00
|
|
|
const TIMER_TSPINFO_REFRESH = 60000;
|
2017-09-08 09:43:50 +02:00
|
|
|
const TIMER_PAGE_SWITCH_TICK = 1000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Page switch timer in seconds
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
|
|
|
|
const TIMESPENT_KANBAN = 120000;
|
2017-09-08 15:42:27 +02:00
|
|
|
const TIMESPENT_TSPINFO = 30000;
|
2017-08-15 16:39:19 +02:00
|
|
|
|
2017-09-08 09:43:50 +02:00
|
|
|
const PAGE_KANBAN = '/kanban';
|
2017-09-08 15:42:27 +02:00
|
|
|
const PAGE_TSPINFO = '/tspinfopage';
|
2017-08-01 16:33:34 +02:00
|
|
|
|
|
|
|
|
@Component({
|
2017-08-15 17:53:22 +02:00
|
|
|
selector: 'app-root',
|
|
|
|
|
templateUrl: './app.component.html',
|
|
|
|
|
styleUrls: ['./app.component.css']
|
2017-08-01 16:33:34 +02:00
|
|
|
})
|
2017-08-15 17:53:22 +02:00
|
|
|
export class AppComponent implements OnInit, OnDestroy {
|
2017-09-08 09:43:50 +02:00
|
|
|
private currentPage: string = PAGE_KANBAN;
|
|
|
|
|
private lastNavOccured: number = Date.now();
|
|
|
|
|
private autoSwitchEnabled: boolean = true;
|
2017-08-15 17:53:22 +02:00
|
|
|
|
2017-09-08 09:43:50 +02:00
|
|
|
private selfUpdateCheckerTimer: Subscription;
|
2017-09-08 15:42:27 +02:00
|
|
|
private reloadKanbanTimer: Subscription;
|
|
|
|
|
private reloadTspInfoTimer: Subscription;
|
2017-09-08 09:43:50 +02:00
|
|
|
private pageSwitchTimer: Subscription;
|
2017-08-15 17:53:22 +02:00
|
|
|
|
2017-09-08 09:43:50 +02:00
|
|
|
constructor(private selfUpdaterService: SelfUpdaterService,
|
|
|
|
|
private kanbanService: KanbanService,
|
2017-09-08 15:42:27 +02:00
|
|
|
private tspInfoService: TspInfoService,
|
2017-09-08 09:43:50 +02:00
|
|
|
private router: Router,
|
|
|
|
|
private activatedRoute: ActivatedRoute) {
|
|
|
|
|
}
|
2017-08-15 17:53:22 +02:00
|
|
|
|
2017-08-25 11:32:29 +02:00
|
|
|
/**
|
|
|
|
|
* Initialize application timers:
|
|
|
|
|
* - selfUpdateCheckerTimer is used to see if there is a newer revision deployed on the server
|
2017-09-08 15:42:27 +02:00
|
|
|
* - reloadKanbanTimer is used to refresh the status of the jira board
|
2017-08-25 11:32:29 +02:00
|
|
|
* - pageSwitchTimer handles switching back and forth between page views
|
|
|
|
|
*/
|
2017-08-15 17:53:22 +02:00
|
|
|
public ngOnInit() {
|
2017-08-23 19:06:55 +02:00
|
|
|
let timer0 = TimerObservable.create(TIMER_DEPLOY_REFRESH, TIMER_JIRA_REFRESH);
|
|
|
|
|
this.selfUpdateCheckerTimer = timer0.subscribe(() => {
|
|
|
|
|
this.selfUpdaterService.checkAndReloadIfNecessary();
|
|
|
|
|
});
|
2017-08-15 17:53:22 +02:00
|
|
|
let timer1 = TimerObservable.create(TIMER_JIRA_REFRESH, TIMER_JIRA_REFRESH);
|
2017-09-08 15:42:27 +02:00
|
|
|
this.reloadKanbanTimer = timer1.subscribe(() => {
|
2017-08-15 17:53:22 +02:00
|
|
|
this.kanbanService.reload();
|
|
|
|
|
});
|
2017-09-08 15:42:27 +02:00
|
|
|
let timer2 = TimerObservable.create(TIMER_TSPINFO_REFRESH, TIMER_TSPINFO_REFRESH);
|
|
|
|
|
this.reloadTspInfoTimer = timer2.subscribe(() => {
|
|
|
|
|
this.tspInfoService.reload();
|
|
|
|
|
});
|
2017-09-08 09:43:50 +02:00
|
|
|
this.activatedRoute.queryParamMap.subscribe(params => {
|
|
|
|
|
if (!params.has("disableAutoSwitch")) {
|
2017-09-08 15:42:27 +02:00
|
|
|
let timer4 = TimerObservable.create(TIMER_PAGE_SWITCH_TICK, TIMER_PAGE_SWITCH_TICK);
|
|
|
|
|
this.pageSwitchTimer = timer4.subscribe(this.switchSubscriber.bind(this));
|
2017-09-08 09:43:50 +02:00
|
|
|
}
|
2017-08-15 17:53:22 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
2017-08-23 19:06:55 +02:00
|
|
|
this.selfUpdateCheckerTimer.unsubscribe();
|
2017-09-08 15:42:27 +02:00
|
|
|
this.reloadKanbanTimer.unsubscribe();
|
|
|
|
|
this.reloadTspInfoTimer.unsubscribe();
|
2017-09-08 09:43:50 +02:00
|
|
|
if (this.pageSwitchTimer) {
|
2017-09-08 15:42:27 +02:00
|
|
|
this.pageSwitchTimer.unsubscribe();
|
2017-09-08 09:43:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private switchSubscriber() {
|
|
|
|
|
let now = new Date();
|
|
|
|
|
let weekDay = now.getDay();
|
|
|
|
|
// on weekdays
|
|
|
|
|
if (weekDay > 0 && weekDay < 6) {
|
2017-09-08 18:28:42 +02:00
|
|
|
if(now.getHours() == 10) {
|
|
|
|
|
if (this.autoSwitchEnabled && now.getMinutes() > 14) {
|
|
|
|
|
this.navigateToPage(PAGE_KANBAN);
|
|
|
|
|
this.autoSwitchEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
if (!this.autoSwitchEnabled && now.getMinutes() > 30) {
|
|
|
|
|
this.navigateToPage(PAGE_TSPINFO);
|
|
|
|
|
this.autoSwitchEnabled = true;
|
|
|
|
|
}
|
2017-09-08 09:43:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (this.autoSwitchEnabled) {
|
|
|
|
|
let compareTimer: number = 0;
|
|
|
|
|
let switchTo: string = '';
|
|
|
|
|
switch (this.currentPage) {
|
|
|
|
|
case PAGE_KANBAN:
|
|
|
|
|
compareTimer = TIMESPENT_KANBAN;
|
|
|
|
|
switchTo = PAGE_TSPINFO;
|
|
|
|
|
break;
|
|
|
|
|
case PAGE_TSPINFO:
|
|
|
|
|
compareTimer = TIMESPENT_TSPINFO;
|
|
|
|
|
switchTo = PAGE_KANBAN;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
console.error("Unknown page in pageSwitcherTimer");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if ((Date.now() - this.lastNavOccured) > compareTimer) {
|
|
|
|
|
this.navigateToPage(switchTo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private navigateToPage(page: string) {
|
|
|
|
|
if (page != this.currentPage) {
|
|
|
|
|
this.router.navigate([page]);
|
|
|
|
|
this.currentPage = page;
|
|
|
|
|
this.lastNavOccured = Date.now();
|
|
|
|
|
}
|
2017-08-15 17:53:22 +02:00
|
|
|
}
|
2017-08-01 16:33:34 +02:00
|
|
|
}
|