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 {ActivatedRoute, NavigationEnd, Router} from "@angular/router"; import {SelfUpdaterService} from "./kanban/shared/self-updater.service"; // import {TspInfoService} from "./tsp-info/shared/tsp-info.service"; const TIMER_DEPLOY_REFRESH = 30000; const TIMER_JIRA_REFRESH = 60000; // const TIMER_TSPINFO_REFRESH = 60000; // const TIMER_PAGE_SWITCH_TICK = 1000; /** * Page switch timer in seconds * @type {number} */ // const TIMESPENT_KANBAN = 120000; // const TIMESPENT_TSPINFO = 30000; // const PAGE_KANBAN = '/kanban'; // const PAGE_TSPINFO = '/tspinfopage'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit, OnDestroy { // private currentPage: string = PAGE_KANBAN; // private lastNavOccured: number = Date.now(); // private autoSwitchEnabled: boolean = true; private selfUpdateCheckerTimer: Subscription; private reloadKanbanTimer: Subscription; // private reloadTspInfoTimer: Subscription; // private pageSwitchTimer: Subscription; constructor(private selfUpdaterService: SelfUpdaterService, private kanbanService: KanbanService, // private tspInfoService: TspInfoService, // private router: Router, // private activatedRoute: ActivatedRoute ) {} /** * Initialize application timers: * - selfUpdateCheckerTimer is used to see if there is a newer revision deployed on the server * - reloadKanbanTimer is used to refresh the status of the jira board * - pageSwitchTimer handles switching back and forth between page views */ 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.reloadKanbanTimer = timer1.subscribe(() => { this.kanbanService.reload(); }); // let timer2 = TimerObservable.create(TIMER_TSPINFO_REFRESH, TIMER_TSPINFO_REFRESH); // this.reloadTspInfoTimer = timer2.subscribe(() => { // this.tspInfoService.reload(); // }); // this.router.events // .filter(e => e instanceof NavigationEnd) // .map(() => { // let route = this.activatedRoute; // while (route.firstChild) { // route = route.firstChild; // } // return route; // }) // .filter((route) => route.outlet === 'primary') // .mergeMap((route) => route.data) // .subscribe(data => { // if (!data['disableAutoSwitch']) { // let timer4 = TimerObservable.create(TIMER_PAGE_SWITCH_TICK, TIMER_PAGE_SWITCH_TICK); // this.pageSwitchTimer = timer4.subscribe(this.switchSubscriber.bind(this)); // } // }); } public ngOnDestroy() { this.selfUpdateCheckerTimer.unsubscribe(); this.reloadKanbanTimer.unsubscribe(); // this.reloadTspInfoTimer.unsubscribe(); // 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() == 10) { // if (this.autoSwitchEnabled && now.getMinutes() > 14) { // this.navigateToPage(PAGE_KANBAN); // this.autoSwitchEnabled = false; // } // if (!this.autoSwitchEnabled && now.getMinutes() > 30) { // 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(); // } // } }