feat: edit groups

This commit is contained in:
Carlos Valente
2025-06-25 06:10:12 +02:00
committed by Carlos Valente
parent 4c08482258
commit 473f50b493
75 changed files with 916 additions and 511 deletions
@@ -10,7 +10,7 @@ const baseEvent = {
const baseBlock = {
type: SupportedEntry.Block,
events: [],
entries: [],
};
/**
@@ -570,7 +570,7 @@ describe('processRundown()', () => {
const rundown = makeRundown({
order: ['1'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['100', '200', '300'] }),
'1': makeOntimeBlock({ id: '1', entries: ['100', '200', '300'] }),
'100': makeOntimeEvent({ id: '100', timeStart: 100, timeEnd: 200, duration: 100, linkStart: false }),
'200': makeOntimeEvent({ id: '200', timeStart: 200, timeEnd: 300, duration: 100 }),
'300': makeOntimeEvent({ id: '300', timeStart: 300, timeEnd: 400, duration: 100 }),
@@ -584,7 +584,7 @@ describe('processRundown()', () => {
expect(generatedRundown.entries).toMatchObject({
'1': {
type: SupportedEntry.Block,
events: ['100', '200', '300'],
entries: ['100', '200', '300'],
startTime: 100,
endTime: 400,
duration: 300,
@@ -601,15 +601,15 @@ describe('processRundown()', () => {
order: ['0', '1', '2', '3'],
entries: {
'0': makeOntimeEvent({ id: '0', timeStart: 0, timeEnd: 10, duration: 10, linkStart: false }),
'1': makeOntimeBlock({ id: '1', events: ['101', '102', '103'] }),
'1': makeOntimeBlock({ id: '1', entries: ['101', '102', '103'] }),
'101': makeOntimeEvent({ id: '101', timeStart: 100, timeEnd: 200, duration: 100, linkStart: false }),
'102': makeOntimeEvent({ id: '102', timeStart: 200, timeEnd: 300, duration: 100, linkStart: true }),
'103': makeOntimeEvent({ id: '103', timeStart: 300, timeEnd: 400, duration: 100, linkStart: true }),
'2': makeOntimeBlock({ id: '2', events: ['201', '202', '203'] }),
'2': makeOntimeBlock({ id: '2', entries: ['201', '202', '203'] }),
'201': makeOntimeEvent({ id: '201', timeStart: 500, timeEnd: 600, duration: 100, linkStart: false }),
'202': makeOntimeEvent({ id: '202', timeStart: 600, timeEnd: 700, duration: 100, linkStart: true }),
'203': makeOntimeEvent({ id: '203', timeStart: 700, timeEnd: 800, duration: 100, linkStart: true }),
'3': makeOntimeBlock({ id: '3', events: ['301', '302', '303'] }),
'3': makeOntimeBlock({ id: '3', entries: ['301', '302', '303'] }),
'301': makeOntimeEvent({ id: '301', timeStart: 900, timeEnd: 1000, duration: 100, linkStart: false }),
'302': makeOntimeEvent({ id: '302', timeStart: 1000, timeEnd: 1100, duration: 100, linkStart: true }),
'303': makeOntimeEvent({ id: '303', timeStart: 1100, timeEnd: 1200, duration: 100, linkStart: true }),
@@ -624,7 +624,7 @@ describe('processRundown()', () => {
'0': { type: SupportedEntry.Event, parent: null },
'1': {
type: SupportedEntry.Block,
events: ['101', '102', '103'],
entries: ['101', '102', '103'],
startTime: 100,
endTime: 400,
duration: 300,
@@ -635,7 +635,7 @@ describe('processRundown()', () => {
'103': { parent: '1' },
'2': {
type: SupportedEntry.Block,
events: ['201', '202', '203'],
entries: ['201', '202', '203'],
startTime: 500,
endTime: 800,
duration: 300,
@@ -646,7 +646,7 @@ describe('processRundown()', () => {
'203': { id: '203', timeStart: 700, timeEnd: 800, duration: 100 },
'3': {
type: SupportedEntry.Block,
events: ['301', '302', '303'],
entries: ['301', '302', '303'],
startTime: 900,
endTime: 1200,
duration: 300,
@@ -789,7 +789,7 @@ describe('rundownMutation.remove()', () => {
const rundown = makeRundown({
order: ['1', '4'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['2', '3'] }),
'1': makeOntimeBlock({ id: '1', entries: ['2', '3'] }),
'2': makeOntimeEvent({ id: '2', parent: '1' }),
'3': makeOntimeDelay({ id: '3', parent: '1' }),
'4': makeOntimeEvent({ id: '4', parent: null }),
@@ -811,7 +811,7 @@ describe('rundownMutation.remove()', () => {
const rundown = makeRundown({
order: ['1', '4'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['2', '3'] }),
'1': makeOntimeBlock({ id: '1', entries: ['2', '3'] }),
'2': makeOntimeEvent({ id: '2', parent: '1' }),
'3': makeOntimeDelay({ id: '3', parent: '1' }),
'4': makeOntimeEvent({ id: '4', parent: null }),
@@ -823,7 +823,7 @@ describe('rundownMutation.remove()', () => {
expect(rundown.order).toStrictEqual(['1', '4']);
expect(rundown.entries).not.toHaveProperty('2');
expect(rundown.entries['1']).toMatchObject({
events: ['3'],
entries: ['3'],
});
});
});
@@ -853,7 +853,7 @@ describe('rundownMutation.reorder()', () => {
const rundown = makeRundown({
order: ['1', '2', '3'],
entries: {
'1': makeOntimeBlock({ id: '1', events: [] }),
'1': makeOntimeBlock({ id: '1', entries: [] }),
'2': makeOntimeEvent({ id: '2', parent: null }),
'3': makeOntimeEvent({ id: '3', parent: null }),
},
@@ -863,7 +863,7 @@ describe('rundownMutation.reorder()', () => {
expect(rundown.order).toStrictEqual(['1', '2']);
expect(rundown.entries['1']).toMatchObject({
events: ['3'],
entries: ['3'],
});
expect(rundown.entries['3']).toMatchObject({
parent: '1',
@@ -875,7 +875,7 @@ describe('rundownMutation.reorder()', () => {
order: ['1', '2'],
flatOrder: ['1', '11', '2'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['11'] }),
'1': makeOntimeBlock({ id: '1', entries: ['11'] }),
'11': makeOntimeEvent({ id: '11', parent: '1' }),
'2': makeOntimeEvent({ id: '2', parent: null }),
},
@@ -885,7 +885,7 @@ describe('rundownMutation.reorder()', () => {
expect(rundown.order).toStrictEqual(['1']);
expect(rundown.entries['1']).toMatchObject({
events: ['2', '11'],
entries: ['2', '11'],
});
expect(rundown.entries['2']).toMatchObject({
parent: '1',
@@ -931,7 +931,7 @@ describe('rundownMutation.reorder()', () => {
order: ['1', '2'],
flatOrder: ['1', '11', '2'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['11'] }),
'1': makeOntimeBlock({ id: '1', entries: ['11'] }),
'11': makeOntimeEvent({ id: '11', parent: '1' }),
'2': makeOntimeEvent({ id: '2', parent: null }),
},
@@ -941,7 +941,7 @@ describe('rundownMutation.reorder()', () => {
expect(rundown.order).toStrictEqual(['1', '11', '2']);
expect(rundown.entries['1']).toMatchObject({
events: [],
entries: [],
});
expect(rundown.entries['2']).toMatchObject({
parent: null,
@@ -953,9 +953,9 @@ describe('rundownMutation.reorder()', () => {
order: ['1', '2'],
flatOrder: ['1', '11', '2', '22'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['11'] }),
'1': makeOntimeBlock({ id: '1', entries: ['11'] }),
'11': makeOntimeEvent({ id: '11', parent: '1' }),
'2': makeOntimeBlock({ id: '2', events: ['22'] }),
'2': makeOntimeBlock({ id: '2', entries: ['22'] }),
'22': makeOntimeEvent({ id: '22', parent: '2' }),
},
});
@@ -964,10 +964,10 @@ describe('rundownMutation.reorder()', () => {
expect(rundown.order).toStrictEqual(['1', '2']);
expect(rundown.entries['1']).toMatchObject({
events: [],
entries: [],
});
expect(rundown.entries['2']).toMatchObject({
events: ['11', '22'],
entries: ['11', '22'],
});
expect(rundown.entries['11']).toMatchObject({
parent: '2',
@@ -979,8 +979,8 @@ describe('rundownMutation.reorder()', () => {
order: ['1', '2'],
flatOrder: ['1', '2', '22'],
entries: {
'1': makeOntimeBlock({ id: '1', events: [] }),
'2': makeOntimeBlock({ id: '2', events: ['22'] }),
'1': makeOntimeBlock({ id: '1', entries: [] }),
'2': makeOntimeBlock({ id: '2', entries: ['22'] }),
'22': makeOntimeEvent({ id: '22', parent: '2' }),
},
});
@@ -989,10 +989,10 @@ describe('rundownMutation.reorder()', () => {
expect(rundown.order).toStrictEqual(['1', '2']);
expect(rundown.entries['1']).toMatchObject({
events: ['22'],
entries: ['22'],
});
expect(rundown.entries['2']).toMatchObject({
events: [],
entries: [],
});
expect(rundown.entries['22']).toMatchObject({
parent: '1',
@@ -1004,9 +1004,9 @@ describe('rundownMutation.reorder()', () => {
order: ['1', '2'],
flatOrder: ['1', '11', '2', '22'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['11'] }),
'1': makeOntimeBlock({ id: '1', entries: ['11'] }),
'11': makeOntimeEvent({ id: '11', parent: '1' }),
'2': makeOntimeBlock({ id: '2', events: ['22'] }),
'2': makeOntimeBlock({ id: '2', entries: ['22'] }),
'22': makeOntimeEvent({ id: '22', parent: '2' }),
},
});
@@ -1017,13 +1017,13 @@ describe('rundownMutation.reorder()', () => {
// expect(newRundown.flatOrder).toStrictEqual(['1', '2', '11', '22']);
// expect(changeList).toStrictEqual(['1', '2', '11', '22']);
expect(rundown.entries['1']).toMatchObject({
events: ['11'],
entries: ['11'],
});
expect(rundown.entries['11']).toMatchObject({
parent: '1',
});
expect(rundown.entries['2']).toMatchObject({
events: [],
entries: [],
});
expect(rundown.entries['22']).toMatchObject({
parent: null,
@@ -1035,9 +1035,9 @@ describe('rundownMutation.reorder()', () => {
order: ['1', '2'],
flatOrder: ['1', '11', '2', '22'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['11'] }),
'1': makeOntimeBlock({ id: '1', entries: ['11'] }),
'11': makeOntimeEvent({ id: '11', parent: '1' }),
'2': makeOntimeBlock({ id: '2', events: ['22'] }),
'2': makeOntimeBlock({ id: '2', entries: ['22'] }),
'22': makeOntimeEvent({ id: '22', parent: '2' }),
},
});
@@ -1046,13 +1046,13 @@ describe('rundownMutation.reorder()', () => {
expect(rundown.order).toStrictEqual(['1', '11', '2']);
expect(rundown.entries['1']).toMatchObject({
events: [],
entries: [],
});
expect(rundown.entries['11']).toMatchObject({
parent: null,
});
expect(rundown.entries['2']).toMatchObject({
events: ['22'],
entries: ['22'],
});
expect(rundown.entries['22']).toMatchObject({
parent: '2',
@@ -1374,7 +1374,7 @@ describe('rundownMutation.applyDelay()', () => {
order: ['1', 'block', '2', '3'],
entries: {
'1': makeOntimeEvent({ id: '1', timeStart: 0, timeEnd: 100, duration: 100 }),
block: makeOntimeBlock({ id: 'block', events: ['delay'] }),
block: makeOntimeBlock({ id: 'block', entries: ['delay'] }),
delay: makeOntimeDelay({ id: 'delay', duration: 100, parent: 'block' }),
'2': makeOntimeEvent({ id: '2', timeStart: 100, timeEnd: 200, duration: 100, linkStart: true }),
'3': makeOntimeEvent({ id: '3', timeStart: 200, timeEnd: 300, duration: 100, linkStart: true }),
@@ -1417,7 +1417,7 @@ describe('rundownMutation.applyDelay()', () => {
entries: {
'1': makeOntimeEvent({ id: '1', timeStart: 0, timeEnd: 100, duration: 100 }),
delay: makeOntimeDelay({ id: 'delay', duration: 100 }),
block: makeOntimeBlock({ id: 'block', events: ['block-1'] }),
block: makeOntimeBlock({ id: 'block', entries: ['block-1'] }),
'block-1': makeOntimeEvent({
id: 'block-1',
timeStart: 100,
@@ -1520,7 +1520,7 @@ describe('rundownMutation.clone()', () => {
const testRundown = makeRundown({
order: ['1'],
entries: {
'1': makeOntimeBlock({ id: '1', events: ['1a'] }),
'1': makeOntimeBlock({ id: '1', entries: ['1a'] }),
'1a': makeOntimeEvent({ id: '1a', cue: 'nested', parent: '1' }),
},
});
@@ -1528,7 +1528,7 @@ describe('rundownMutation.clone()', () => {
const newEntry = rundownMutation.clone(testRundown, testRundown.entries['1a']);
expect(testRundown.order).toStrictEqual(['1']);
expect(testRundown.entries['1']).toMatchObject({ events: ['1a', newEntry.id] });
expect(testRundown.entries['1']).toMatchObject({ entries: ['1a', newEntry.id] });
expect(testRundown.entries[newEntry.id]).toMatchObject({
type: SupportedEntry.Event,
parent: '1',
@@ -1540,7 +1540,7 @@ describe('rundownMutation.clone()', () => {
const testRundown = makeRundown({
order: ['1'],
entries: {
'1': makeOntimeBlock({ id: '1', title: 'top', events: ['1a'] }),
'1': makeOntimeBlock({ id: '1', title: 'top', entries: ['1a'] }),
'1a': makeOntimeEvent({ id: '1a', cue: 'nested', parent: '1' }),
},
});
@@ -1550,9 +1550,9 @@ describe('rundownMutation.clone()', () => {
expect(testRundown.order).toStrictEqual(['1', newEntry.id]);
expect(testRundown.entries[newEntry.id]).toMatchObject({
type: SupportedEntry.Block,
events: [expect.any(String)],
entries: [expect.any(String)],
});
expect((testRundown.entries[newEntry.id] as OntimeBlock).events[0]).not.toBe('1a');
expect((testRundown.entries[newEntry.id] as OntimeBlock).entries[0]).not.toBe('1a');
});
});
@@ -1575,7 +1575,7 @@ describe('rundownMutation.group()', () => {
expect(rundown.entries).toMatchObject({
[blockId]: {
type: SupportedEntry.Block,
events: ['1', '2'],
entries: ['1', '2'],
},
'1': { id: '1', type: SupportedEntry.Event, parent: blockId },
'2': { id: '2', type: SupportedEntry.Event, parent: blockId },
@@ -1590,7 +1590,7 @@ describe('rundownMutation.ungroup()', () => {
order: ['1', '2'],
entries: {
'1': makeOntimeEvent({ id: '1', cue: 'data1', parent: null }),
'2': makeOntimeBlock({ id: '2', events: ['21', '22'] }),
'2': makeOntimeBlock({ id: '2', entries: ['21', '22'] }),
'21': makeOntimeEvent({ id: '21', cue: 'data21', parent: '2' }),
'22': makeOntimeEvent({ id: '22', cue: 'data22', parent: '2' }),
},
@@ -47,7 +47,7 @@ describe('parseRundown()', () => {
flatOrder: ['1', '2', '3', '4'],
entries: {
'1': { id: '1', type: SupportedEntry.Event, title: 'test', skip: false } as OntimeEvent, // OK
'2': { id: '1', type: SupportedEntry.Block, title: 'test 2', skip: false } as OntimeBlock, // duplicate ID
'2': { id: '1', type: SupportedEntry.Block, title: 'test 2' } as OntimeBlock, // duplicate ID
'3': {} as OntimeEvent, // no data
'4': { id: '4', title: 'test 2', skip: false } as OntimeEvent, // no type
},
@@ -220,7 +220,7 @@ describe('parseRundown()', () => {
order: ['block'],
flatOrder: ['block'],
entries: {
block: makeOntimeBlock({ id: 'block', events: ['1', '2'] }),
block: makeOntimeBlock({ id: 'block', entries: ['1', '2'] }),
'1': makeOntimeEvent({ id: '1' }),
'2': makeOntimeEvent({ id: '2' }),
},
@@ -229,7 +229,7 @@ describe('parseRundown()', () => {
const parsedRundown = parseRundown(rundown, {});
expect(parsedRundown.order.length).toEqual(1);
expect(parsedRundown.entries.block).toMatchObject({ events: ['1', '2'] });
expect(parsedRundown.entries.block).toMatchObject({ entries: ['1', '2'] });
expect(Object.keys(parsedRundown.entries).length).toEqual(3);
});
});
+19 -19
View File
@@ -48,7 +48,7 @@ const cachedRundown: Rundown = {
id: '',
title: '',
order: [],
flatOrder: [], // TODO: remove in favour of the metadata flatEntryOrder
flatOrder: [],
entries: {},
revision: 0,
};
@@ -150,7 +150,7 @@ export function createTransaction(options: TransactionOptions): Transaction {
cachedRundown.title = rundown.title;
cachedRundown.entries = entries;
cachedRundown.order = order;
cachedRundown.flatOrder = metadata.flatEntryOrder; // TODO: remove in favour of the metadata flatEntryOrder
cachedRundown.flatOrder = metadata.flatEntryOrder;
customFieldsMetadata.assigned = assignedCustomFields;
rundownMetadata = metadata;
}
@@ -194,12 +194,12 @@ function add(rundown: Rundown, entry: OntimeEntry, afterId: EntryId | null, pare
// 1. inserting an entry inside a block
const parentBlock = rundown.entries[parentId] as OntimeBlock;
if (afterId) {
const atEventsIndex = parentBlock.events.indexOf(afterId) + 1;
const atEventsIndex = parentBlock.entries.indexOf(afterId) + 1;
const atFlatIndex = rundown.flatOrder.indexOf(afterId) + 1;
parentBlock.events = insertAtIndex(atEventsIndex, entry.id, parentBlock.events);
parentBlock.entries = insertAtIndex(atEventsIndex, entry.id, parentBlock.entries);
rundown.flatOrder = insertAtIndex(atFlatIndex, entry.id, rundown.flatOrder);
} else {
parentBlock.events = insertAtIndex(0, entry.id, parentBlock.events);
parentBlock.entries = insertAtIndex(0, entry.id, parentBlock.entries);
const atFlatIndex = rundown.flatOrder.indexOf(parentId) + 1;
rundown.flatOrder = insertAtIndex(atFlatIndex, entry.id, rundown.flatOrder);
}
@@ -247,8 +247,8 @@ function edit(rundown: Rundown, patch: PatchWithId): { entry: OntimeEntry; didIn
function remove(rundown: Rundown, entry: OntimeEntry) {
if (isOntimeBlock(entry)) {
// for ontime blocks, we need to iterate through the children and delete them
for (let i = 0; i < entry.events.length; i++) {
const nestedEntryId = entry.events[i];
for (let i = 0; i < entry.entries.length; i++) {
const nestedEntryId = entry.entries[i];
deleteEntry(nestedEntryId);
}
} else if (entry.parent) {
@@ -256,8 +256,8 @@ function remove(rundown: Rundown, entry: OntimeEntry) {
const parentBlock = rundown.entries[entry.parent] as OntimeBlock;
if (parentBlock) {
// we call a mutation to the parent event to remove the entry from the events
const filteredEvents = deleteById(parentBlock.events, entry.id);
edit(rundown, { id: parentBlock.id, events: filteredEvents });
const filteredEvents = deleteById(parentBlock.entries, entry.id);
edit(rundown, { id: parentBlock.id, entries: filteredEvents });
}
}
deleteEntry(entry.id);
@@ -300,8 +300,8 @@ function reorder(rundown: Rundown, eventFrom: OntimeEntry, eventTo: OntimeEntry,
eventFrom.parent = toParent;
}
const sourceArray = fromParent === null ? rundown.order : (rundown.entries[fromParent] as OntimeBlock).events;
const destinationArray = toParent === null ? rundown.order : (rundown.entries[toParent] as OntimeBlock).events;
const sourceArray = fromParent === null ? rundown.order : (rundown.entries[fromParent] as OntimeBlock).entries;
const destinationArray = toParent === null ? rundown.order : (rundown.entries[toParent] as OntimeBlock).entries;
const fromIndex = sourceArray.indexOf(eventFrom.id);
const toIndex = (() => {
@@ -442,8 +442,8 @@ function clone(rundown: Rundown, entry: OntimeEntry): OntimeEntry {
const newBlock = cloneBlock(entry, getUniqueId(rundown));
const nestedIds: EntryId[] = [];
for (let i = 0; i < entry.events.length; i++) {
const nestedEntryId = entry.events[i];
for (let i = 0; i < entry.entries.length; i++) {
const nestedEntryId = entry.entries[i];
const nestedEntry = rundown.entries[nestedEntryId];
if (!nestedEntry) {
continue;
@@ -461,7 +461,7 @@ function clone(rundown: Rundown, entry: OntimeEntry): OntimeEntry {
// indexes + 1 since we are inserting after the cloned block
const atIndex = rundown.order.indexOf(entry.id) + 1;
newBlock.events = nestedIds;
newBlock.entries = nestedIds;
newBlock.title = `${entry.title || 'Untitled'} (copy)`;
rundown.entries[newBlock.id] = newBlock;
@@ -504,7 +504,7 @@ function group(rundown: Rundown, entryIds: EntryId[]): OntimeBlock {
rundown.order = rundown.order.filter((id) => id !== entryId);
}
newBlock.events = nestedEvents;
newBlock.entries = nestedEvents;
const insertIndex = Math.max(0, firstIndex);
// we have filtered the items from the order
// we will insert them now, with only the block at top level ...
@@ -519,7 +519,7 @@ function group(rundown: Rundown, entryIds: EntryId[]): OntimeBlock {
*/
function ungroup(rundown: Rundown, block: OntimeBlock) {
// get the events from the block and merge them into the order where the block was
const nestedEvents = block.events;
const nestedEvents = block.entries;
const blockIndex = rundown.order.indexOf(block.id);
rundown.order.splice(blockIndex, 1, ...nestedEvents);
@@ -714,8 +714,8 @@ export function processRundown(
const blockEvents: EntryId[] = [];
// check if the block contains nested entries
for (let j = 0; j < processedEntry.events.length; j++) {
const nestedEntryId = processedEntry.events[j];
for (let j = 0; j < processedEntry.entries.length; j++) {
const nestedEntryId = processedEntry.entries[j];
const nestedEntry = initialRundown.entries[nestedEntryId];
if (!nestedEntry) {
@@ -750,7 +750,7 @@ export function processRundown(
processedEntry.startTime = blockStartTime;
processedEntry.endTime = blockEndTime;
processedEntry.isFirstLinked = isFirstLinked;
processedEntry.events = blockEvents;
processedEntry.entries = blockEvents;
}
}
@@ -116,8 +116,8 @@ export function parseRundown(
} else if (isOntimeDelay(event)) {
newEvent = { ...delayDef, duration: event.duration, id };
} else if (isOntimeBlock(event)) {
for (let i = 0; i < event.events.length; i++) {
const nestedEventId = event.events[i];
for (let i = 0; i < event.entries.length; i++) {
const nestedEventId = event.entries[i];
const nestedEvent = rundown.entries[nestedEventId];
if (isOntimeEvent(nestedEvent)) {
@@ -149,8 +149,8 @@ export function parseRundown(
...blockDef,
title: event.title,
note: event.note,
events: event.events?.filter((eventId) => Object.hasOwn(rundown.entries, eventId)) ?? [],
skip: event.skip,
entries: event.entries?.filter((eventId) => Object.hasOwn(rundown.entries, eventId)) ?? [],
isNextDay: event.isNextDay,
colour: event.colour,
custom: { ...event.custom },
id,
@@ -99,19 +99,15 @@ router.patch('/swap', rundownSwapValidator, async (req: Request, res: Response<R
}
});
router.patch(
'/applydelay/:id',
paramsWithId,
async (req: Request, res: Response<Rundown | ErrorResponse>) => {
try {
const newRundown = await applyDelay(req.params.id);
res.status(200).send(newRundown);
} catch (error) {
const message = getErrorMessage(error);
res.status(400).send({ message });
}
},
);
router.patch('/applydelay/:id', paramsWithId, async (req: Request, res: Response<Rundown | ErrorResponse>) => {
try {
const newRundown = await applyDelay(req.params.id);
res.status(200).send(newRundown);
} catch (error) {
const message = getErrorMessage(error);
res.status(400).send({ message });
}
});
router.post('/clone/:id', paramsWithId, async (req: Request, res: Response<Rundown | ErrorResponse>) => {
try {
@@ -133,19 +129,15 @@ router.post('/group', rundownArrayOfIds, async (req: Request, res: Response<Rund
}
});
router.post(
'/ungroup/:id',
paramsWithId,
async (req: Request, res: Response<Rundown | ErrorResponse>) => {
try {
const newRundown = await ungroupEntries(req.params.id);
res.status(200).send(newRundown);
} catch (error) {
const message = getErrorMessage(error);
res.status(400).send({ message });
}
},
);
router.post('/ungroup/:id', paramsWithId, async (req: Request, res: Response<Rundown | ErrorResponse>) => {
try {
const newRundown = await ungroupEntries(req.params.id);
res.status(200).send(newRundown);
} catch (error) {
const message = getErrorMessage(error);
res.status(400).send({ message });
}
});
router.delete('/', rundownArrayOfIds, async (req: Request, res: Response<MessageResponse | ErrorResponse>) => {
try {
@@ -347,7 +347,7 @@ export async function cloneEntry(entryId: EntryId): Promise<Rundown> {
// notify timer and external services of change
if (isOntimeBlock(newEntry)) {
notifyChanges(rundownMetadata, revision, { timer: newEntry.events, external: true });
notifyChanges(rundownMetadata, revision, { timer: newEntry.entries, external: true });
} else if (isOntimeEvent(newEntry)) {
notifyChanges(rundownMetadata, revision, { timer: [newEntry.id], external: true });
} else if (isOntimeDelay(newEntry)) {
@@ -156,8 +156,9 @@ export function createBlock(patch?: Partial<OntimeBlock>): OntimeBlock {
type: SupportedEntry.Block,
title: patch.title ?? '',
note: patch.note ?? '',
events: patch.events ?? [],
skip: patch.skip ?? false,
entries: patch.entries ?? [],
isNextDay: patch.isNextDay ?? false,
targetDuration: patch.targetDuration ?? null,
colour: makeString(patch.colour, ''),
custom: patch.custom ?? {},
revision: 0,
@@ -288,7 +289,7 @@ export function cloneBlock(entry: OntimeBlock, newId: EntryId): OntimeBlock {
newEntry.id = newId;
// in blocks, we need to remove the events references
newEntry.events = [];
newEntry.entries = [];
newEntry.revision = 0;
return newEntry;
}