@@ -22,11 +22,16 @@ import {
22
22
import { doUserAction , UserAction } from '../../lib/clientUserAction'
23
23
import { withTranslation } from 'react-i18next'
24
24
import { Translated } from '../../lib/ReactMeteorData/ReactMeteorData'
25
- import { IngestAdlib } from '@sofie-automation/blueprints-integration'
25
+ import {
26
+ DefaultUserOperationImportMOSItem ,
27
+ DefaultUserOperationsTypes ,
28
+ IngestAdlib ,
29
+ UserEditingType ,
30
+ } from '@sofie-automation/blueprints-integration'
26
31
import { MeteorCall } from '../../lib/meteorApi'
27
32
import { Rundown } from '@sofie-automation/corelib/dist/dataModel/Rundown'
28
- import { Buckets , Rundowns } from '../../collections'
29
- import { BucketId , PartInstanceId , RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
33
+ import { Buckets , Rundowns , Segments } from '../../collections'
34
+ import { BucketId , PartInstanceId , RundownId , RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
30
35
import { MOS_DATA_IS_STRICT } from '@sofie-automation/meteor-lib/dist/mos'
31
36
import { mosTypes , MOS } from '@sofie-automation/meteor-lib/dist/mos'
32
37
import { RundownPlaylistCollectionUtil } from '../../collections/rundownPlaylistUtil'
@@ -35,7 +40,7 @@ import RundownViewEventBus, {
35
40
ItemDroppedEvent ,
36
41
RundownViewEvents ,
37
42
} from '@sofie-automation/meteor-lib/dist/triggers/RundownViewEventBus'
38
- import { UIPartInstances } from '../Collections'
43
+ import { UIPartInstances , UIParts } from '../Collections'
39
44
40
45
interface IProps {
41
46
layout : RundownLayoutBase
@@ -210,6 +215,36 @@ export const ExternalFramePanel = withTranslation()(
210
215
return undefined
211
216
}
212
217
218
+ private findPartId ( el : HTMLElement ) : {
219
+ rundownId : RundownId | undefined
220
+ segmentId : string | undefined
221
+ partId : string | undefined
222
+ } {
223
+ while ( el . dataset . partId === undefined && el . parentElement ) {
224
+ el = el . parentElement
225
+ }
226
+ const partId = el ?. dataset . partId
227
+
228
+ if ( partId ) {
229
+ const part = UIParts . findOne ( protectString ( partId ) )
230
+ const supportsOp = part ?. userEditOperations ?. find (
231
+ ( op ) => op . type === UserEditingType . SOFIE && op . id === DefaultUserOperationsTypes . IMPORT_MOS_ITEM
232
+ )
233
+
234
+ if ( supportsOp ) {
235
+ const segment = Segments . findOne ( part ?. segmentId )
236
+
237
+ return {
238
+ rundownId : part ?. rundownId ,
239
+ segmentId : segment ?. externalId ,
240
+ partId : part ?. externalId ,
241
+ }
242
+ }
243
+ }
244
+
245
+ return { rundownId : undefined , partId : undefined , segmentId : undefined }
246
+ }
247
+
213
248
private getShowStyleBaseId ( ) {
214
249
const { playlist } = this . props
215
250
@@ -243,11 +278,52 @@ export const ExternalFramePanel = withTranslation()(
243
278
}
244
279
245
280
receiveMOSItem ( e : any , mosItem : MOS . IMOSItem ) {
246
- const { t } = this . props
247
-
248
281
console . log ( 'Object received, passing onto blueprints' , mosItem )
249
282
250
283
const bucketId = this . findBucketId ( e . target )
284
+ if ( bucketId ) {
285
+ this . receiveMOSItemBucket ( e , bucketId , mosItem )
286
+ return
287
+ }
288
+
289
+ const { rundownId, segmentId, partId } = this . findPartId ( e . target )
290
+ if ( rundownId && partId ) {
291
+ console . log ( 'pass to part' , partId )
292
+ this . receiveMOSItemUserOp ( e , rundownId , partId , segmentId , mosItem )
293
+ return
294
+ }
295
+ }
296
+
297
+ receiveMOSItemUserOp (
298
+ e : any ,
299
+ rundownId : RundownId ,
300
+ partId : string ,
301
+ segmentId : string | undefined ,
302
+ mosItem : MOS . IMOSItem
303
+ ) {
304
+ const { t } = this . props
305
+
306
+ const operationTarget = { segmentExternalId : segmentId , partExternalId : partId , pieceExternalId : undefined }
307
+
308
+ doUserAction ( t , e , UserAction . EXECUTE_USER_OPERATION , ( e , ts ) =>
309
+ MeteorCall . userAction . executeUserChangeOperation (
310
+ e ,
311
+ ts ,
312
+ rundownId ,
313
+ operationTarget ,
314
+ literal < DefaultUserOperationImportMOSItem > ( {
315
+ id : DefaultUserOperationsTypes . IMPORT_MOS_ITEM ,
316
+
317
+ payloadType : 'MOS' ,
318
+ payload : MOS . stringifyMosObject ( mosItem , MOS_DATA_IS_STRICT ) ,
319
+ } )
320
+ )
321
+ )
322
+ }
323
+
324
+ receiveMOSItemBucket ( e : any , bucketId : BucketId , mosItem : MOS . IMOSItem ) {
325
+ const { t } = this . props
326
+
251
327
const targetBucket = bucketId ? Buckets . findOne ( bucketId ) : Buckets . findOne ( )
252
328
253
329
const showStyleBaseId = this . getShowStyleBaseId ( )
0 commit comments