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-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 09:43:50 +02:00
|
|
|
const TIMER_PAGE_SWITCH_TICK = 1000;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Page switch timer in seconds
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
|
|
|
|
const TIMESPENT_KANBAN = 120000;
|
|
|
|
|
const TIMESPENT_TSPINFO = 60000;
|
2017-08-15 16:39:19 +02:00
|
|
|
|
2017-09-08 09:43:50 +02:00
|
|
|
const PAGE_KANBAN = '/kanban';
|
|
|
|
|
const PAGE_TSPINFO = '/tsp-info-page';
|
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;
|
|
|
|
|
private reloadJiraIssueTimer: Subscription;
|
|
|
|
|
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,
|
|
|
|
|
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
|
|
|
|
|
* - reloadJiraIssueTimer is used to refresh the status of the jira board
|
|
|
|
|
* - 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);
|
|
|
|
|
this.reloadJiraIssueTimer = timer1.subscribe(() => {
|
|
|
|
|
this.kanbanService.reload();
|
|
|
|
|
});
|
2017-09-08 09:43:50 +02:00
|
|
|
this.activatedRoute.queryParamMap.subscribe(params => {
|
|
|
|
|
if (!params.has("disableAutoSwitch")) {
|
|
|
|
|
let timer2 = TimerObservable.create(TIMER_PAGE_SWITCH_TICK, TIMER_PAGE_SWITCH_TICK);
|
|
|
|
|
// this.pageSwitchTimer = timer2.subscribe(this.switchSubscriber.bind(this));
|
|
|
|
|
}
|
2017-08-15 17:53:22 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
2017-08-23 19:06:55 +02:00
|
|
|
this.selfUpdateCheckerTimer.unsubscribe();
|
2017-08-15 17:53:22 +02:00
|
|
|
this.reloadJiraIssueTimer.unsubscribe();
|
2017-09-08 09:43:50 +02:00
|
|
|
if (this.pageSwitchTimer) {
|
|
|
|
|
// this.pageSwitchTimer.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private switchSubscriber() {
|
|
|
|
|
let now = new Date();
|
|
|
|
|
let weekDay = now.getDay();
|
|
|
|
|
// on weekdays
|
|
|
|
|
if (weekDay > 0 && weekDay < 6) {
|
|
|
|
|
if (now.getHours() == 9 && now.getMinutes() >= 14 && this.autoSwitchEnabled) {
|
|
|
|
|
this.navigateToPage(PAGE_KANBAN);
|
|
|
|
|
this.autoSwitchEnabled = false;
|
|
|
|
|
}
|
|
|
|
|
if (now.getHours() == 9 && now.getMinutes() >= 29 && !this.autoSwitchEnabled) {
|
|
|
|
|
this.navigateToPage(PAGE_TSPINFO);
|
|
|
|
|
this.autoSwitchEnabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|