mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 02:43:50 +00:00
Skip fixes (#805)
* refactor: resolve current in time-to-end * refactor: recalculate on skip * Alpha tweaks (#806) * style: small tweaks to interface * refactor: simplify quick add
This commit is contained in:
@@ -277,7 +277,7 @@ export async function previewSpreadsheet(req: Request, res: Response) {
|
||||
}
|
||||
|
||||
const options = JSON.parse(req.body.options);
|
||||
const data = handleMaybeExcel(filePath, options);
|
||||
const { data } = handleMaybeExcel(filePath, options);
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: String(error) });
|
||||
|
||||
@@ -68,7 +68,7 @@ export async function addEvent(
|
||||
|
||||
notifyChanges({ timer: [newEvent.id], external: true });
|
||||
|
||||
// notify runtime that rundown size has changed
|
||||
// notify runtime that rundown has changed
|
||||
updateRuntimeOnChange();
|
||||
|
||||
return newEvent;
|
||||
@@ -84,7 +84,7 @@ export async function deleteEvent(eventId: string) {
|
||||
|
||||
notifyChanges({ timer: [eventId], external: true });
|
||||
|
||||
// notify event loader that rundown size has changed
|
||||
// notify event loader that rundown has changed
|
||||
updateRuntimeOnChange();
|
||||
}
|
||||
|
||||
@@ -114,6 +114,9 @@ export async function editEvent(patch: Partial<OntimeEvent> | Partial<OntimeBloc
|
||||
|
||||
notifyChanges({ timer: [patch.id], external: true });
|
||||
|
||||
// notify event loader that rundown has changed
|
||||
updateRuntimeOnChange();
|
||||
|
||||
return newEvent;
|
||||
}
|
||||
|
||||
@@ -127,6 +130,9 @@ export async function batchEditEvents(ids: string[], data: Partial<OntimeEvent>)
|
||||
await scopedMutation({ patch: data, eventIds: ids });
|
||||
|
||||
notifyChanges({ timer: ids, external: true });
|
||||
|
||||
// notify event loader that rundown has changed
|
||||
updateRuntimeOnChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,6 +147,9 @@ export async function reorderEvent(eventId: string, from: number, to: number) {
|
||||
|
||||
notifyChanges({ timer: true, external: true });
|
||||
|
||||
// notify event loader that rundown has changed
|
||||
updateRuntimeOnChange();
|
||||
|
||||
return reorderedItem;
|
||||
}
|
||||
|
||||
@@ -162,6 +171,9 @@ export async function swapEvents(from: string, to: string) {
|
||||
await scopedMutation({ fromId: from, toId: to });
|
||||
|
||||
notifyChanges({ timer: true, external: true });
|
||||
|
||||
// notify event loader that rundown has changed
|
||||
updateRuntimeOnChange();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +181,8 @@ export async function swapEvents(from: string, to: string) {
|
||||
* Called when we make changes to the rundown object
|
||||
*/
|
||||
function updateRuntimeOnChange() {
|
||||
updateRundownData(getPlayableEvents());
|
||||
// schedule an update for the end of the event loop
|
||||
setImmediate(() => updateRundownData(getPlayableEvents()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,10 +193,8 @@ export function notifyChanges(options: { timer?: boolean | string[]; external?:
|
||||
const playableEvents = getPlayableEvents();
|
||||
// notify timer service of changed events
|
||||
// timer can be true or an array of changed IDs
|
||||
if (Array.isArray(options.timer)) {
|
||||
runtimeService.maybeUpdate(playableEvents, options.timer);
|
||||
}
|
||||
runtimeService.maybeUpdate(playableEvents);
|
||||
const affected = Array.isArray(options.timer) ? options.timer : undefined;
|
||||
runtimeService.maybeUpdate(playableEvents, affected);
|
||||
}
|
||||
|
||||
if (options.external) {
|
||||
|
||||
@@ -8,7 +8,7 @@ export function getLink(currentIndex: number, rundown: OntimeRundown): OntimeEve
|
||||
// currently the link is the previous event
|
||||
for (let i = currentIndex - 1; i >= 0; i--) {
|
||||
const event = rundown[i];
|
||||
if (isOntimeEvent(event)) {
|
||||
if (isOntimeEvent(event) && !event.skip) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,13 +147,13 @@ class RuntimeService {
|
||||
*/
|
||||
maybeUpdate(playableEvents: OntimeEvent[], affectedIds?: string[]) {
|
||||
const state = runtimeState.getState();
|
||||
const hasLoadedElements = state.eventNow || state.eventNext;
|
||||
const hasLoadedElements = state.eventNow !== null || state.eventNext !== null;
|
||||
if (!hasLoadedElements) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we need to reload in a few scenarios:
|
||||
// 1. we are not confident that changes do not affect running event
|
||||
// 1. we are not confident that changes do not affect running event (eg. all events where changed)
|
||||
const safeOption = typeof affectedIds === 'undefined';
|
||||
// 2. the edited event is in memory (now or next) running
|
||||
const eventInMemory = safeOption ? false : this.affectsLoaded(affectedIds);
|
||||
@@ -166,15 +166,18 @@ class RuntimeService {
|
||||
}
|
||||
// load stuff again, but keep running if our events still exist
|
||||
const eventNow = getEventWithId(state.eventNow.id);
|
||||
if (eventNow) {
|
||||
const onlyChangedNow = affectedIds?.length === 1 && affectedIds.at(0) === eventNow.id;
|
||||
if (onlyChangedNow) {
|
||||
runtimeState.reload(eventNow);
|
||||
} else {
|
||||
runtimeState.reloadAll(eventNow, playableEvents);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Maybe the event will become the next
|
||||
isNext = this.isNewNext();
|
||||
if (isNext) {
|
||||
// TODO: do i need to load here?
|
||||
runtimeState.loadNext(playableEvents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,11 @@ export function updateRundownData(playableRundown: OntimeEvent[]) {
|
||||
|
||||
runtimeState.runtime.plannedStart = firstEvent?.timeStart ?? null;
|
||||
runtimeState.runtime.plannedEnd = lastEvent?.timeEnd ?? null;
|
||||
if (runtimeState.runtime.plannedEnd === null) {
|
||||
runtimeState.runtime.expectedEnd = null;
|
||||
} else {
|
||||
runtimeState.runtime.expectedEnd = (runtimeState.runtime.plannedEnd + runtimeState.runtime.offset) % dayInMs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,6 +260,18 @@ export function reload(event?: OntimeEvent) {
|
||||
runtimeState.timer.expectedFinish = getExpectedFinish(runtimeState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in situations when we want to reload all events
|
||||
* without interrupting timer
|
||||
* @param eventNow
|
||||
* @param playableEvents
|
||||
*/
|
||||
export function reloadAll(eventNow: OntimeEvent, playableEvents: OntimeEvent[]) {
|
||||
loadNow(eventNow, playableEvents);
|
||||
loadNext(playableEvents);
|
||||
reload(eventNow);
|
||||
}
|
||||
|
||||
export function start(state: RuntimeState = runtimeState): boolean {
|
||||
if (state.eventNow === null) {
|
||||
return false;
|
||||
@@ -307,8 +324,10 @@ export function stop(state: RuntimeState = runtimeState): boolean {
|
||||
if (state.timer.playback === Playback.Stop) {
|
||||
return false;
|
||||
}
|
||||
runtimeState.runtime.actualStart = null;
|
||||
|
||||
clear();
|
||||
runtimeState.runtime.actualStart = null;
|
||||
runtimeState.runtime.expectedEnd = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user