Skip to content

Commit 5f88266

Browse files
committed
feat: add getUpcomingParts method to OnSetAsNextContext
For fetching upcoming parts from a blueprint
1 parent f7afd72 commit 5f88266

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

packages/blueprints-integration/src/context/onSetAsNextContext.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
IShowStyleUserContext,
1212
} from '../index.js'
1313
import { BlueprintQuickLookInfo } from './quickLoopInfo.js'
14+
import { ReadonlyDeep } from 'type-fest'
1415

1516
/**
1617
* Context in which 'current' is the part currently on air, and 'next' is the partInstance being set as Next
@@ -56,6 +57,13 @@ export interface IOnSetAsNextContext extends IShowStyleUserContext, IEventContex
5657
/** Gets the Segment. This primarily allows for accessing metadata */
5758
getSegment(segment: 'current' | 'next'): Promise<IBlueprintSegment | undefined>
5859

60+
/** Get a list of the upcoming Parts in the Rundown, in the order that they will be Taken
61+
*
62+
* @param limit The max number of parts returned. Default is 5.
63+
* @returns An array of Parts. If there is no next part, the array will be empty.
64+
*/
65+
getUpcomingParts(limit?: number): Promise<ReadonlyDeep<IBlueprintPart[]>>
66+
5967
/**
6068
* Creative actions
6169
*/

packages/job-worker/src/blueprints/__tests__/context-OnSetAsNextContext.test.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ import { JobContext, ProcessedShowStyleCompound } from '../../jobs/index.js'
66
import { mock } from 'jest-mock-extended'
77
import { PartAndPieceInstanceActionService } from '../context/services/PartAndPieceInstanceActionService.js'
88
import { OnSetAsNextContext } from '../context/index.js'
9+
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
10+
import { PartId, RundownId, SegmentId } from '@sofie-automation/corelib/dist/dataModel/Ids'
11+
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
912

1013
describe('Test blueprint api context', () => {
1114
async function getTestee(setManually = false) {
1215
const mockActionService = mock<PartAndPieceInstanceActionService>()
16+
const mockPlayoutModel = mock<PlayoutModel>()
1317
const context = new OnSetAsNextContext(
1418
{
1519
name: 'fakeContext',
1620
identifier: 'action',
1721
},
1822
mock<JobContext>(),
19-
mock<PlayoutModel>(),
23+
mockPlayoutModel,
2024
mock<ProcessedShowStyleCompound>(),
2125
mock<WatchedPackagesHelper>(),
2226
mockActionService,
@@ -26,6 +30,7 @@ describe('Test blueprint api context', () => {
2630
return {
2731
context,
2832
mockActionService,
33+
mockPlayoutModel,
2934
}
3035
}
3136

@@ -100,6 +105,42 @@ describe('Test blueprint api context', () => {
100105
expect(mockActionService.getPartForPreviousPiece).toHaveBeenCalledWith({ _id: 'pieceId' })
101106
})
102107

108+
test('getUpcomingParts', async () => {
109+
const { context, mockPlayoutModel } = await getTestee()
110+
111+
mockPlayoutModel.getAllOrderedParts.mockReturnValue(
112+
mock([
113+
{
114+
_id: protectString<PartId>('part1'),
115+
title: 'Part 1',
116+
invalid: false,
117+
floated: false,
118+
_rank: 1,
119+
rundownId: protectString<RundownId>('rundown1'),
120+
externalId: 'ext1',
121+
segmentId: protectString<SegmentId>('seg1'),
122+
expectedDurationWithTransition: 1000,
123+
userEditOperations: [],
124+
} as DBPart,
125+
{
126+
_id: protectString<PartId>('part2'),
127+
title: 'Part 2',
128+
invalid: false,
129+
floated: false,
130+
_rank: 1,
131+
rundownId: protectString<RundownId>('rundown1'),
132+
externalId: 'ext1',
133+
segmentId: protectString<SegmentId>('seg1'),
134+
expectedDurationWithTransition: 1000,
135+
userEditOperations: [],
136+
} as unknown as DBPart,
137+
])
138+
)
139+
140+
const parts = await context.getUpcomingParts()
141+
expect(parts.map((i) => i.title)).toEqual(['Part 1', 'Part 2'])
142+
})
143+
103144
test('insertPiece', async () => {
104145
const { context, mockActionService } = await getTestee()
105146

packages/job-worker/src/blueprints/context/OnSetAsNextContext.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { protectString } from '@sofie-automation/corelib/dist/protectedString'
2626
import { BlueprintQuickLookInfo } from '@sofie-automation/blueprints-integration/dist/context/quickLoopInfo'
2727
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
2828
import { selectNewPartWithOffsets } from '../../playout/moveNextPart.js'
29+
import { getOrderedPartsAfterPlayhead } from '../../playout/lookahead/util.js'
30+
import { convertPartToBlueprints } from './lib.js'
2931

3032
export class OnSetAsNextContext
3133
extends ShowStyleUserContext
@@ -57,6 +59,10 @@ export class OnSetAsNextContext
5759
return this.partAndPieceInstanceService.nextPartState
5860
}
5961

62+
async getUpcomingParts(limit: number = 5): Promise<ReadonlyDeep<IBlueprintPart[]>> {
63+
return getOrderedPartsAfterPlayhead(this.jobContext, this.playoutModel, limit).map(convertPartToBlueprints)
64+
}
65+
6066
async getPartInstance(part: 'current' | 'next'): Promise<IBlueprintPartInstance<unknown> | undefined> {
6167
return this.partAndPieceInstanceService.getPartInstance(part)
6268
}

0 commit comments

Comments
 (0)