mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 12:53:32 +00:00
add shortcut to jump between blocks (#1181)
* add shortcut * chore: rename getRelevantBlock to getPreviousBlock
This commit is contained in:
committed by
GitHub
parent
f708dc0bc4
commit
340f5478fb
@@ -8,9 +8,9 @@ export { sanitiseCue } from './src/cue-utils/cueUtils.js';
|
||||
export { getCueCandidate } from './src/cue-utils/cueUtils.js';
|
||||
export { generateId } from './src/generate-id/generateId.js';
|
||||
export {
|
||||
getEventWithId,
|
||||
filterPlayable,
|
||||
filterTimedEvents,
|
||||
getEventWithId,
|
||||
getFirst,
|
||||
getFirstEvent,
|
||||
getFirstEventNormal,
|
||||
@@ -19,6 +19,7 @@ export {
|
||||
getLastEventNormal,
|
||||
getLastNormal,
|
||||
getNext,
|
||||
getNextBlockNormal,
|
||||
getNextEvent,
|
||||
getNextEventNormal,
|
||||
getNextNormal,
|
||||
@@ -26,7 +27,8 @@ export {
|
||||
getPreviousEvent,
|
||||
getPreviousEventNormal,
|
||||
getPreviousNormal,
|
||||
getRelevantBlock,
|
||||
getPreviousBlock,
|
||||
getPreviousBlockNormal,
|
||||
swapEventData,
|
||||
} from './src/rundown-utils/rundownUtils.js';
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import {
|
||||
getNext,
|
||||
getNextEvent,
|
||||
getPrevious,
|
||||
getPreviousBlock,
|
||||
getPreviousEvent,
|
||||
getRelevantBlock,
|
||||
swapEventData,
|
||||
} from './rundownUtils';
|
||||
|
||||
@@ -278,23 +278,23 @@ describe('getLastEvent', () => {
|
||||
];
|
||||
|
||||
it('returns the relevant block', () => {
|
||||
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'h');
|
||||
const block = getPreviousBlock(testRundown as unknown as OntimeRundown, 'h');
|
||||
|
||||
expect(block?.id).toBe('g');
|
||||
});
|
||||
it('returns the relevant block', () => {
|
||||
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'f');
|
||||
const block = getPreviousBlock(testRundown as unknown as OntimeRundown, 'f');
|
||||
|
||||
expect(block?.id).toBe('e');
|
||||
});
|
||||
it('returns the relevant block', () => {
|
||||
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'a');
|
||||
const block = getPreviousBlock(testRundown as unknown as OntimeRundown, 'a');
|
||||
|
||||
expect(block).toBeNull();
|
||||
});
|
||||
it('also works on index 0', () => {
|
||||
testRundown.unshift({ id: '0', type: SupportedEvent.Block });
|
||||
const block = getRelevantBlock(testRundown as unknown as OntimeRundown, 'a');
|
||||
const block = getPreviousBlock(testRundown as unknown as OntimeRundown, 'a');
|
||||
expect(block?.id).toBe('0');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -302,7 +302,53 @@ export function getEventWithId(rundown: OntimeRundown, id: string): OntimeRundow
|
||||
/**
|
||||
* Gets relevant block element for a given ID
|
||||
*/
|
||||
export function getRelevantBlock(rundown: OntimeRundown, currentId: string): OntimeBlock | null {
|
||||
export function getPreviousBlockNormal(rundown: NormalisedRundown, order: string[], currentId: string): IndexAndEntry {
|
||||
let foundCurrentEvent = false;
|
||||
// Iterate backwards through the rundown to find the current event
|
||||
for (let index = order.length - 1; index >= 0; index--) {
|
||||
const id = order[index];
|
||||
if (!foundCurrentEvent && id === currentId) {
|
||||
// set the flag when the current event is found
|
||||
foundCurrentEvent = true;
|
||||
continue;
|
||||
}
|
||||
// the first block before the current event is the relevant one
|
||||
const entry = rundown[id];
|
||||
if (foundCurrentEvent && isOntimeBlock(entry)) {
|
||||
return { entry, index };
|
||||
}
|
||||
}
|
||||
// no blocks exist before current event
|
||||
return { entry: null, index: null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets next block element for a given ID
|
||||
*/
|
||||
export function getNextBlockNormal(rundown: NormalisedRundown, order: string[], currentId: string): IndexAndEntry {
|
||||
let foundCurrentEvent = false;
|
||||
// Iterate backwards through the rundown to find the current event
|
||||
for (let index = 0; index < order.length; index++) {
|
||||
const id = order[index];
|
||||
if (!foundCurrentEvent && id === currentId) {
|
||||
// set the flag when the current event is found
|
||||
foundCurrentEvent = true;
|
||||
continue;
|
||||
}
|
||||
// the first block before the current event is the relevant one
|
||||
const entry = rundown[id];
|
||||
if (foundCurrentEvent && isOntimeBlock(entry)) {
|
||||
return { entry, index };
|
||||
}
|
||||
}
|
||||
// no blocks exist before current event
|
||||
return { entry: null, index: null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets relevant block element for a given ID
|
||||
*/
|
||||
export function getPreviousBlock(rundown: OntimeRundown, currentId: string): OntimeBlock | null {
|
||||
let foundCurrentEvent = false;
|
||||
// Iterate backwards through the rundown to find the current event
|
||||
for (let i = rundown.length - 1; i >= 0; i--) {
|
||||
|
||||
Reference in New Issue
Block a user