Files
ontime/server/classes/EventTimer.js
T
cv 8e95b06b8c feat: presenter view
- connected to websockets
- some styling changes
- reusable components
- some small bugfixes
2021-04-17 23:54:00 +02:00

232 lines
5.0 KiB
JavaScript

const Timer = require('./Timer');
/*
* EventTimer adds functions specific to APP
* namely:
* - Presenter message, text and status
* - Public message, text and status
*
*/
class EventTimer extends Timer {
presenter = {
text: '',
visible: false,
};
public = {
text: '',
visible: false,
};
lower = {
text: '',
visible: false,
};
titles = {
titleNow: null,
subtitleNow: null,
presenterNow: null,
titleNext: null,
subtitleNext: null,
presenterNext: null,
};
selectedEvent = null;
selectedEventId = null;
numEvents = null;
_eventlist = null;
constructor() {
super();
}
setupWithEventList(eventlist) {
// filter only events
const events = eventlist.filter((e) => e.type === 'event');
const numEvents = events.length;
if (numEvents < 1) return;
// set general
this._eventList = events;
this.numEvents = numEvents;
// load first event
this.loadEvent(0);
}
updateEventList(eventlist) {
// filter only events
const events = eventlist.filter((e) => e.type === 'event');
const numEvents = events.length;
// set general
this._eventList = events;
this.numEvents = numEvents;
// TODO: What to do about reloading
}
loadEvent(eventIndex) {
// set event specific
const e = this._eventList[eventIndex];
const start = e.timeStart == null || e.timeStart === '' ? 0 : e.timeStart;
const end = e.timeEnd == null || e.timeEnd === '' ? 0 : e.timeEnd;
// time stuff
this._resetTimers();
this.duration = end - start;
this.current = this.duration;
this.selectedEvent = eventIndex;
this.selectedEventId = e.id;
// event titles
this.titles.titleNow = e.title;
this.titles.subtitleNow = e.subtitle;
this.titles.presenterNow = e.presenter;
// assume tere is no next event
this.titles.titleNext = null;
this.titles.subtitleNext = null;
this.titles.presenterNext = null;
// look for event after
if (eventIndex < this.numEvents - 1) {
for (let i = eventIndex + 1 ; i < this.numEvents; i++) {
// check that is the right type
console.log(this._eventList[i]);
if (this._eventList[i].type === 'event') {
this.titles.titleNext = this._eventList[i].title;
this.titles.subtitleNext = this._eventList[i].subtitle;
this.titles.presenterNext = this._eventList[i].presenter;
break;
}
}
}
}
print() {
return `
Timer
=========
Playback
------------------------------
state = ${this.state}
current = ${this.current}
duration = ${this.duration}
Options
------------------------------
showNegative = ${this.showNegative}
Events
------------------------------
numEvents = ${this.numEvents}
selectedEvent = ${this.selectedEvent}
selectedEventId = ${this.selectedEventId}
title = ${this.titles.title}
subtitle = ${this.titles.subtitle}
presenter = ${this.titles.presenter}
Messages
------------------------------
presenter text = ${this.presenter.text}
presenter vis = ${this.presenter.visible}
public text = ${this.public.text}
public vis = ${this.public.visible}
lower text = ${this.lower.text}
lower vis = ${this.lower.visible}
Private
------------------------------
finishAt = ${this._finishAt}
startedAt = ${this._startedAt}
pausedAt = ${this._pausedAt}
pausedInterval = ${this._pausedInterval}
pausedTotal = ${this._pausedTotal}
`;
}
set presenterText(text) {
this.presenter.text = text;
}
set presenterVisible(state) {
this.presenter.visible = state;
}
set publicText(text) {
this.public.text = text;
}
set publicVisible(state) {
this.public.visible = state;
}
set lowerText(text) {
this.lower.text = text;
}
set lowerVisible(state) {
this.lower.visible = state;
}
get presenter() {
return this.presenter;
}
get public() {
return this.public;
}
get lower() {
return this.lower;
}
get titles() {
return this.titles;
}
getEventData() {}
get events() {
return this._eventList;
}
// Torbjorn: is this a good idea?
set events(events) {
this._eventList = events;
}
goto(eventIndex) {
this.loadEvent(eventIndex);
}
roll() {
console.log('roll: not yet implemented');
return false;
this.state = 'roll';
}
previous() {
const gotoEvent = this.selectedEvent > 0 ? this.selectedEvent - 1 : 0;
if (gotoEvent === this.selectedEvent) return;
this.goto(gotoEvent);
}
next() {
const gotoEvent =
this.selectedEvent < this.numEvents - 1
? this.selectedEvent + 1
: this.numEvents - 1;
if (gotoEvent === this.selectedEvent) return;
this.goto(gotoEvent);
}
}
module.exports = EventTimer;