mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
fix: update time in block (#1474)
* fix: update time in block --------- Co-authored-by: arc-alex <ac@omnivox.dk>
This commit is contained in:
@@ -1,7 +1,18 @@
|
|||||||
import { PlayableEvent, Playback, TimerPhase } from 'ontime-types';
|
import { OntimeRundown, PlayableEvent, Playback, SupportedEvent, TimerPhase } from 'ontime-types';
|
||||||
import { deepmerge } from 'ontime-utils';
|
import { deepmerge } from 'ontime-utils';
|
||||||
|
|
||||||
import { type RuntimeState, addTime, clear, getState, load, pause, roll, start, stop } from '../runtimeState.js';
|
import {
|
||||||
|
type RuntimeState,
|
||||||
|
addTime,
|
||||||
|
clear,
|
||||||
|
getState,
|
||||||
|
load,
|
||||||
|
loadBlock,
|
||||||
|
pause,
|
||||||
|
roll,
|
||||||
|
start,
|
||||||
|
stop,
|
||||||
|
} from '../runtimeState.js';
|
||||||
import { initRundown } from '../../services/rundown-service/RundownService.js';
|
import { initRundown } from '../../services/rundown-service/RundownService.js';
|
||||||
|
|
||||||
const mockEvent = {
|
const mockEvent = {
|
||||||
@@ -328,3 +339,125 @@ describe('roll mode', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('loadBlock', () => {
|
||||||
|
test('from no-block to a block will clear startedAt', () => {
|
||||||
|
const rundown = [
|
||||||
|
{ id: '0', type: SupportedEvent.Event },
|
||||||
|
{ id: '1', type: SupportedEvent.Block },
|
||||||
|
{ id: '2', type: SupportedEvent.Event },
|
||||||
|
{ id: '3', type: SupportedEvent.Block },
|
||||||
|
{ id: '4', type: SupportedEvent.Event },
|
||||||
|
] as OntimeRundown;
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
currentBlock: {
|
||||||
|
block: null,
|
||||||
|
startedAt: 123,
|
||||||
|
},
|
||||||
|
eventNow: rundown[2],
|
||||||
|
} as RuntimeState;
|
||||||
|
|
||||||
|
loadBlock(rundown, state);
|
||||||
|
|
||||||
|
expect(state).toMatchObject({
|
||||||
|
currentBlock: { block: rundown[1], startedAt: null },
|
||||||
|
eventNow: rundown[2],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('from block to a different block will clear startedAt', () => {
|
||||||
|
const rundown = [
|
||||||
|
{ id: '0', type: SupportedEvent.Event },
|
||||||
|
{ id: '1', type: SupportedEvent.Block },
|
||||||
|
{ id: '2', type: SupportedEvent.Event },
|
||||||
|
{ id: '3', type: SupportedEvent.Block },
|
||||||
|
{ id: '4', type: SupportedEvent.Event },
|
||||||
|
] as OntimeRundown;
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
currentBlock: {
|
||||||
|
block: rundown[1],
|
||||||
|
startedAt: 123,
|
||||||
|
},
|
||||||
|
eventNow: rundown[4],
|
||||||
|
} as RuntimeState;
|
||||||
|
|
||||||
|
loadBlock(rundown, state);
|
||||||
|
|
||||||
|
expect(state).toMatchObject({
|
||||||
|
currentBlock: { block: rundown[3], startedAt: null },
|
||||||
|
eventNow: rundown[4],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('from block to a no-block will clear startedAt', () => {
|
||||||
|
const rundown = [
|
||||||
|
{ id: '0', type: SupportedEvent.Event },
|
||||||
|
{ id: '1', type: SupportedEvent.Block },
|
||||||
|
{ id: '2', type: SupportedEvent.Event },
|
||||||
|
{ id: '3', type: SupportedEvent.Block },
|
||||||
|
{ id: '4', type: SupportedEvent.Event },
|
||||||
|
] as OntimeRundown;
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
currentBlock: {
|
||||||
|
block: rundown[1],
|
||||||
|
startedAt: 123,
|
||||||
|
},
|
||||||
|
eventNow: rundown[0],
|
||||||
|
} as RuntimeState;
|
||||||
|
|
||||||
|
loadBlock(rundown, state);
|
||||||
|
|
||||||
|
expect(state).toMatchObject({
|
||||||
|
currentBlock: { block: null, startedAt: null },
|
||||||
|
eventNow: rundown[0],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('from block to same block will keep startedAt', () => {
|
||||||
|
const rundown = [
|
||||||
|
{ id: '0', type: SupportedEvent.Block },
|
||||||
|
{ id: '1', type: SupportedEvent.Event },
|
||||||
|
{ id: '2', type: SupportedEvent.Event },
|
||||||
|
] as OntimeRundown;
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
currentBlock: {
|
||||||
|
block: rundown[0],
|
||||||
|
startedAt: 123,
|
||||||
|
},
|
||||||
|
eventNow: rundown[2],
|
||||||
|
} as RuntimeState;
|
||||||
|
|
||||||
|
loadBlock(rundown, state);
|
||||||
|
|
||||||
|
expect(state).toMatchObject({
|
||||||
|
currentBlock: { block: rundown[0], startedAt: 123 },
|
||||||
|
eventNow: rundown[2],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('from no-block to no-block will keep startedAt', () => {
|
||||||
|
const rundown = [
|
||||||
|
{ id: '0', type: SupportedEvent.Event },
|
||||||
|
{ id: '1', type: SupportedEvent.Event },
|
||||||
|
] as OntimeRundown;
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
currentBlock: {
|
||||||
|
block: null,
|
||||||
|
startedAt: 123,
|
||||||
|
},
|
||||||
|
eventNow: rundown[0],
|
||||||
|
} as RuntimeState;
|
||||||
|
|
||||||
|
loadBlock(rundown, state);
|
||||||
|
|
||||||
|
expect(state).toMatchObject({
|
||||||
|
currentBlock: { block: null, startedAt: 123 },
|
||||||
|
eventNow: rundown[0],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -674,6 +674,11 @@ export function roll(rundown: OntimeRundown, offset = 0): { eventId: MaybeString
|
|||||||
|
|
||||||
// there is something to run, load event
|
// there is something to run, load event
|
||||||
|
|
||||||
|
// update runtime
|
||||||
|
if (runtimeState.currentBlock.startedAt === null) {
|
||||||
|
runtimeState.currentBlock.startedAt = runtimeState.clock;
|
||||||
|
}
|
||||||
|
|
||||||
// event will finish on time
|
// event will finish on time
|
||||||
// account for event that finishes the day after
|
// account for event that finishes the day after
|
||||||
const endTime =
|
const endTime =
|
||||||
@@ -696,26 +701,25 @@ export function roll(rundown: OntimeRundown, offset = 0): { eventId: MaybeString
|
|||||||
return { eventId: runtimeState.eventNow.id, didStart: true };
|
return { eventId: runtimeState.eventNow.id, didStart: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadBlock(rundown: OntimeRundown) {
|
/**
|
||||||
if (runtimeState.eventNow === null) {
|
* handle block loading, not for use outside of runtimeState
|
||||||
|
* @param rundown
|
||||||
|
*/
|
||||||
|
export function loadBlock(rundown: OntimeRundown, state = runtimeState) {
|
||||||
|
if (state.eventNow === null) {
|
||||||
// we need a loaded event to have a block
|
// we need a loaded event to have a block
|
||||||
runtimeState.currentBlock.block = null;
|
state.currentBlock.block = null;
|
||||||
runtimeState.currentBlock.startedAt = null;
|
state.currentBlock.startedAt = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newCurrentBlock = getPreviousBlock(rundown, runtimeState.eventNow.id);
|
const newCurrentBlock = getPreviousBlock(rundown, state.eventNow.id);
|
||||||
|
|
||||||
// test all block change posibiletys
|
|
||||||
const formNoBlockToBlock = runtimeState.currentBlock.block === null && newCurrentBlock !== null;
|
|
||||||
const formBlockToNoBlock = runtimeState.currentBlock.block !== null && newCurrentBlock === null;
|
|
||||||
const formBlockToNewBlock = runtimeState.currentBlock.block?.id !== newCurrentBlock?.id;
|
|
||||||
|
|
||||||
// update time only if the block has changed
|
// update time only if the block has changed
|
||||||
if (formNoBlockToBlock || formBlockToNoBlock || formBlockToNewBlock) {
|
if (state.currentBlock.block?.id !== newCurrentBlock?.id) {
|
||||||
runtimeState.currentBlock.startedAt = null;
|
state.currentBlock.startedAt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the block anyway
|
// update the block anyway
|
||||||
runtimeState.currentBlock.block = newCurrentBlock === null ? null : { ...newCurrentBlock };
|
state.currentBlock.block = newCurrentBlock === null ? null : { ...newCurrentBlock };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user