Skip to content

Commit fd936d0

Browse files
authored
feat: support prompter-editor SOFIE-2846 (Sofie-Automation#1151)
1 parent 1d0f8fc commit fd936d0

File tree

5 files changed

+133
-7
lines changed

5 files changed

+133
-7
lines changed

meteor/lib/api/pubsub.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
PackageManagerPlayoutContext,
6262
} from '@sofie-automation/shared-lib/dist/package-manager/publications'
6363
import { logger } from '../logging'
64+
import { PackageInfoDB } from '@sofie-automation/corelib/dist/dataModel/PackageInfos'
6465

6566
/**
6667
* Ids of possible DDP subscriptions
@@ -220,6 +221,7 @@ export interface PubSubTypes {
220221
selector: MongoQuery<PackageContainerStatusDB>,
221222
token?: string
222223
) => PackageContainerStatusDB
224+
[PubSub.packageInfos]: (deviceId: PeripheralDeviceId, token?: string) => PackageInfoDB
223225

224226
// For a PeripheralDevice
225227
[PubSub.rundownsForDevice]: (deviceId: PeripheralDeviceId, token: string) => DBRundown

meteor/server/migration/1_50_0.ts

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { addMigrationSteps } from './databaseMigration'
2-
import { PeripheralDevices, RundownPlaylists, Studios } from '../collections'
2+
import {
3+
AdLibActions,
4+
AdLibPieces,
5+
ExpectedPackages,
6+
PeripheralDevices,
7+
Pieces,
8+
RundownPlaylists,
9+
Studios,
10+
} from '../collections'
311
import { assertNever, clone, literal } from '@sofie-automation/corelib/dist/lib'
412
import {
513
MappingExt,
@@ -21,6 +29,13 @@ import {
2129
} from '@sofie-automation/corelib/dist/settings/objectWithOverrides'
2230
import { JSONBlobStringify, JSONSchema, TSR } from '@sofie-automation/blueprints-integration'
2331
import { DEFAULT_MINIMUM_TAKE_SPAN } from '@sofie-automation/shared-lib/dist/core/constants'
32+
import { PartId } from '@sofie-automation/shared-lib/dist/core/model/Ids'
33+
import { protectString } from '@sofie-automation/shared-lib/dist/lib/protectedString'
34+
import { ExpectedPackageDBType } from '@sofie-automation/corelib/dist/dataModel/ExpectedPackages'
35+
import { AdLibActionId, PieceId, RundownBaselineAdLibActionId } from '@sofie-automation/corelib/dist/dataModel/Ids'
36+
import { Piece } from '@sofie-automation/corelib/dist/dataModel/Piece'
37+
import { AdLibPiece } from '@sofie-automation/corelib/dist/dataModel/AdLibPiece'
38+
import { AdLibAction } from '@sofie-automation/corelib/dist/dataModel/AdlibAction'
2439

2540
/*
2641
* **************************************************************************************
@@ -145,6 +160,12 @@ const oldDeviceTypeToNewMapping = {
145160
[OldDeviceType.MULTI_OSC]: TSR.DeviceType.MULTI_OSC,
146161
}
147162

163+
const EXPECTED_PACKAGE_TYPES_ADDED_PART_ID = [
164+
ExpectedPackageDBType.PIECE,
165+
ExpectedPackageDBType.ADLIB_PIECE,
166+
ExpectedPackageDBType.ADLIB_ACTION,
167+
]
168+
148169
export const addSteps = addMigrationSteps('1.50.0', [
149170
{
150171
id: `Mos gateway fix up config`,
@@ -824,6 +845,88 @@ export const addSteps = addMigrationSteps('1.50.0', [
824845
)
825846
},
826847
},
848+
849+
{
850+
id: `ExpectedPackageDBFromAdLibAction and ExpectedPackageDBFromPiece add partId`,
851+
canBeRunAutomatically: true,
852+
validate: async () => {
853+
const objectCount = await ExpectedPackages.countDocuments({
854+
fromPieceType: { $in: EXPECTED_PACKAGE_TYPES_ADDED_PART_ID as any }, // Force the types, as the query does not match due to the interfaces
855+
partId: { $exists: false },
856+
})
857+
858+
if (objectCount) {
859+
return `object needs to be updated`
860+
}
861+
return false
862+
},
863+
migrate: async () => {
864+
const objects = await ExpectedPackages.findFetchAsync({
865+
fromPieceType: { $in: EXPECTED_PACKAGE_TYPES_ADDED_PART_ID as any }, // Force the types, as the query does not match due to the interfaces
866+
partId: { $exists: false },
867+
})
868+
869+
const neededPieceIds: Array<PieceId | AdLibActionId | RundownBaselineAdLibActionId> = _.compact(
870+
objects.map((obj) => obj.pieceId)
871+
)
872+
const [pieces, adlibPieces, adlibActions] = await Promise.all([
873+
Pieces.findFetchAsync(
874+
{
875+
_id: { $in: neededPieceIds as PieceId[] },
876+
},
877+
{
878+
projection: {
879+
_id: 1,
880+
startPartId: 1,
881+
},
882+
}
883+
) as Promise<Pick<Piece, '_id' | 'startPartId'>[]>,
884+
AdLibPieces.findFetchAsync(
885+
{
886+
_id: { $in: neededPieceIds as PieceId[] },
887+
},
888+
{
889+
projection: {
890+
_id: 1,
891+
partId: 1,
892+
},
893+
}
894+
) as Promise<Pick<AdLibPiece, '_id' | 'partId'>[]>,
895+
AdLibActions.findFetchAsync(
896+
{
897+
_id: { $in: neededPieceIds as AdLibActionId[] },
898+
},
899+
{
900+
projection: {
901+
_id: 1,
902+
partId: 1,
903+
},
904+
}
905+
) as Promise<Pick<AdLibAction, '_id' | 'partId'>[]>,
906+
])
907+
908+
const partIdLookup = new Map<PieceId | AdLibActionId | RundownBaselineAdLibActionId, PartId>()
909+
for (const piece of pieces) {
910+
partIdLookup.set(piece._id, piece.startPartId)
911+
}
912+
for (const adlib of adlibPieces) {
913+
if (adlib.partId) partIdLookup.set(adlib._id, adlib.partId)
914+
}
915+
for (const action of adlibActions) {
916+
partIdLookup.set(action._id, action.partId)
917+
}
918+
919+
for (const expectedPackage of objects) {
920+
if (!expectedPackage.pieceId) continue
921+
922+
await ExpectedPackages.mutableCollection.updateAsync(expectedPackage._id, {
923+
$set: {
924+
partId: partIdLookup.get(expectedPackage.pieceId) ?? protectString(''),
925+
},
926+
})
927+
}
928+
},
929+
},
827930
])
828931

829932
function updatePlayoutDeviceTypeInOverride(op: SomeObjectOverrideOp): ObjectOverrideSetOp | undefined {

meteor/server/publications/studio.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import {
2626
ExpectedPackageWorkStatuses,
2727
ExternalMessageQueue,
2828
PackageContainerStatuses,
29+
PackageInfos,
2930
PeripheralDevices,
3031
Studios,
3132
} from '../collections'
33+
import { PackageInfoDB } from '@sofie-automation/corelib/dist/dataModel/PackageInfos'
3234

3335
meteorPublish(PubSub.studios, async function (selector0, token) {
3436
const { cred, selector } = await AutoFillSelector.organizationId<DBStudio>(this.userId, selector0, token)
@@ -88,6 +90,16 @@ meteorPublish(PubSub.packageContainerStatuses, async function (selector, token)
8890
}
8991
return null
9092
})
93+
meteorPublish(PubSub.packageInfos, async function (deviceId, token) {
94+
if (!deviceId) throw new Meteor.Error(400, 'deviceId argument missing')
95+
const modifier: FindOptions<PackageInfoDB> = {
96+
fields: {},
97+
}
98+
if (await PeripheralDeviceReadAccess.peripheralDeviceContent(deviceId, { userId: this.userId, token })) {
99+
return PackageInfos.findWithCursor({ deviceId }, modifier)
100+
}
101+
return null
102+
})
91103

92104
meteorCustomPublish(
93105
PubSub.mappingsForDevice,

packages/corelib/src/dataModel/ExpectedPackages.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
BucketAdLibId,
88
BucketId,
99
ExpectedPackageId,
10+
PartId,
1011
PieceId,
1112
RundownBaselineAdLibActionId,
1213
RundownId,
@@ -23,17 +24,19 @@ import {
2324
The Package Manager will then copy the file to the right place.
2425
*/
2526

26-
export type ExpectedPackageFromRundown =
27-
| ExpectedPackageDBFromPiece
28-
| ExpectedPackageDBFromAdLibAction
27+
export type ExpectedPackageFromRundown = ExpectedPackageDBFromPiece | ExpectedPackageDBFromAdLibAction
28+
29+
export type ExpectedPackageFromRundownBaseline =
2930
| ExpectedPackageDBFromBaselineAdLibAction
3031
| ExpectedPackageDBFromBaselineAdLibPiece
32+
| ExpectedPackageDBFromRundownBaselineObjects
33+
34+
export type ExpectedPackageDBFromBucket = ExpectedPackageDBFromBucketAdLib | ExpectedPackageDBFromBucketAdLibAction
3135

3236
export type ExpectedPackageDB =
3337
| ExpectedPackageFromRundown
34-
| ExpectedPackageDBFromBucketAdLib
35-
| ExpectedPackageDBFromBucketAdLibAction
36-
| ExpectedPackageDBFromRundownBaselineObjects
38+
| ExpectedPackageDBFromBucket
39+
| ExpectedPackageFromRundownBaseline
3740
| ExpectedPackageDBFromStudioBaselineObjects
3841

3942
export enum ExpectedPackageDBType {
@@ -67,6 +70,8 @@ export interface ExpectedPackageDBFromPiece extends ExpectedPackageDBBase {
6770
fromPieceType: ExpectedPackageDBType.PIECE | ExpectedPackageDBType.ADLIB_PIECE
6871
/** The Piece this package belongs to */
6972
pieceId: PieceId
73+
/** The Part this package belongs to */
74+
partId: PartId
7075
/** The Segment this package belongs to */
7176
segmentId: SegmentId
7277
/** The rundown of the Piece this package belongs to */
@@ -85,6 +90,8 @@ export interface ExpectedPackageDBFromAdLibAction extends ExpectedPackageDBBase
8590
fromPieceType: ExpectedPackageDBType.ADLIB_ACTION
8691
/** The Adlib Action this package belongs to */
8792
pieceId: AdLibActionId
93+
/** The Part this package belongs to */
94+
partId: PartId
8895
/** The Segment this package belongs to */
8996
segmentId: SegmentId
9097
/** The rundown of the Piece this package belongs to */

packages/job-worker/src/ingest/expectedPackages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function generateExpectedPackagesForPiece(
180180
...base,
181181
rundownId,
182182
segmentId,
183+
partId,
183184
pieceId: piece._id,
184185
fromPieceType: type,
185186
})
@@ -227,6 +228,7 @@ function generateExpectedPackagesForAdlibAction(
227228
...base,
228229
rundownId,
229230
segmentId,
231+
partId: action.partId,
230232
pieceId: action._id,
231233
fromPieceType: ExpectedPackageDBType.ADLIB_ACTION,
232234
})

0 commit comments

Comments
 (0)