taurus-tv/src/app/kanban/kanban-board/kanban-board.component.ts
2017-09-08 18:28:42 +02:00

142 lines
3.7 KiB
TypeScript

import {Component, HostBinding, HostListener, OnDestroy, OnInit} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {ActivatedRoute} from '@angular/router';
import {
KanbanBoard,
KanbanService,
KanbanEntry,
} from "../shared";
import {
Fun,
FunService,
} from "../../shared";
import {Subscription} from "rxjs/Subscription";
import {TimerObservable} from "rxjs/observable/TimerObservable";
const WIP_LIMIT_INPROGRESS = 12;
const WIP_LIMIT_VERIFICATION = 8;
const STYLE_HIDDEN = 'hidden';
const STYLE_VISIBLE = 'scroll';
const FUN_TIMER = 2000;
@Component({
selector: 'app-kanban-board',
templateUrl: './kanban-board.component.html',
styleUrls: ['./kanban-board.component.css']
})
export class KanbanBoardComponent implements OnInit, OnDestroy {
private funTimer: Subscription;
@HostBinding('style.overflow') hostOverflow = STYLE_HIDDEN;
public showSomeFun: boolean = false;
constructor(private titleService: Title,
private route: ActivatedRoute,
private kanbanService: KanbanService,
private funService: FunService) {
}
/**
* Set page title, and handle preloaded kanbanBoard data
*/
ngOnInit() {
this.titleService.setTitle('TaurusXFT : Kanban board');
this.route.data.subscribe((data: {
kanbanBoard: KanbanBoard,
fun: Fun,
}) => {
this.kanbanBoard = data.kanbanBoard;
this.fun = data.fun;
});
this.lunchTime();
let timer0 = TimerObservable.create(FUN_TIMER, FUN_TIMER);
this.funTimer = timer0.subscribe(() => this.lunchTime.bind(this));
}
private lunchTime() {
let now = new Date();
this.showSomeFun = (now.getHours() == 11 && now.getMinutes() > 29) || (now.getHours() == 12 && now.getMinutes() < 31);
}
ngOnDestroy() {
this.funTimer.unsubscribe();
}
get kanbanBoard(): KanbanBoard {
return this.kanbanService.kanbanBoard;
}
set kanbanBoard(kanbanBoard: KanbanBoard) {
this.kanbanService.kanbanBoard = kanbanBoard;
}
get fun(): Fun {
return this.funService.fun;
}
set fun(fun: Fun) {
this.funService.fun = fun;
}
get inprogressWipLimit(): number {
return WIP_LIMIT_INPROGRESS;
}
get inprogressWipCount(): number {
return this.kanbanBoard.inProgress.filter(
(entry: KanbanEntry) => entry.labels.every(
label => label.toUpperCase() != 'BLOCKED'
)
).length;
}
/**
* Set 'over-wip' class on inprogress row if its over the wip limit
* This excludes issues marked as BLOCKED with labels
*
* @returns {{over-wip: boolean}}
*/
get inprogressWipClass() {
return {
'over-wip': this.inprogressWipCount > WIP_LIMIT_INPROGRESS,
};
}
get verificationWipLimit(): number {
return WIP_LIMIT_VERIFICATION;
}
get verificationWipCount(): number {
return this.kanbanBoard.verification.filter(
(entry: KanbanEntry) => entry.labels.every(
label => label.toUpperCase() != 'BLOCKED'
)
).length;
}
/**
* Set 'over-wip' class on verification row if its over the wip limit
* This excludes issues marked as BLOCKED with labels
*
* @returns {{over-wip: boolean}}
*/
get verificationWipClass() {
return {
'over-wip': this.verificationWipCount > WIP_LIMIT_VERIFICATION,
};
}
@HostListener('mouseover')
private onMouseOver() {
this.hostOverflow = STYLE_VISIBLE;
}
@HostListener('mouseout')
private onMouseOut() {
this.hostOverflow = STYLE_HIDDEN;
}
}