taurus-tv/src/app/app.component.ts

61 lines
2.1 KiB
TypeScript
Raw Normal View History

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";
import {Router} from "@angular/router";
import {SelfUpdaterService} from "./kanban/shared/self-updater.service";
const TIMER_DEPLOY_REFRESH = 30000;
const TIMER_JIRA_REFRESH = 60000;
const TIMER_PAGE_SWITCH = 300000;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
selfUpdateCheckerTimer: Subscription;
reloadJiraIssueTimer: Subscription;
pageSwitchTimer: Subscription;
constructor(
private selfUpdaterService: SelfUpdaterService,
private kanbanService: KanbanService,
private router: Router
) {}
/**
* 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
* @todo: pageSwitchTimer
*/
public ngOnInit() {
let timer0 = TimerObservable.create(TIMER_DEPLOY_REFRESH, TIMER_JIRA_REFRESH);
this.selfUpdateCheckerTimer = timer0.subscribe(() => {
this.selfUpdaterService.checkAndReloadIfNecessary();
});
let timer1 = TimerObservable.create(TIMER_JIRA_REFRESH, TIMER_JIRA_REFRESH);
this.reloadJiraIssueTimer = timer1.subscribe(() => {
this.kanbanService.reload();
});
let timer2 = TimerObservable.create(TIMER_PAGE_SWITCH, TIMER_PAGE_SWITCH);
this.pageSwitchTimer = timer2.subscribe(() => {
// navigate to next page
// this.router.navigate();
console.log("pageSwitch");
});
}
public ngOnDestroy() {
this.selfUpdateCheckerTimer.unsubscribe();
this.reloadJiraIssueTimer.unsubscribe();
this.pageSwitchTimer.unsubscribe();
}
}