From 82b24d9085dac5755bbd492afba3f41a22777120 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Wed, 17 Jan 2024 10:45:32 +0100 Subject: [PATCH] fix: set rundown rank using playlist.rundownIdsInOrder --- .../dataHandlers/RundownPlaylistHandler.ts | 4 +++ .../dataTransformers/RundownTransformer.ts | 25 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/apps/backend/src/sofie-core-connection/dataHandlers/RundownPlaylistHandler.ts b/packages/apps/backend/src/sofie-core-connection/dataHandlers/RundownPlaylistHandler.ts index 6bd3b92..d0001bc 100644 --- a/packages/apps/backend/src/sofie-core-connection/dataHandlers/RundownPlaylistHandler.ts +++ b/packages/apps/backend/src/sofie-core-connection/dataHandlers/RundownPlaylistHandler.ts @@ -25,8 +25,10 @@ export class RundownPlaylistHandler extends DataHandler { if (!playlist) { this.store.playlists.remove(this.convertId(id)) + this.transformers.rundowns.updateCorePlaylist(id, undefined) } else { this.store.playlists.create(this.convert(playlist)) + this.transformers.rundowns.updateCorePlaylist(id, playlist) } } private onChanged(id: Core.RundownPlaylistId): void { @@ -35,8 +37,10 @@ export class RundownPlaylistHandler extends DataHandler { if (!playlist) { this.store.playlists.remove(this.convertId(id)) + this.transformers.rundowns.updateCorePlaylist(id, undefined) } else { this.store.playlists.update(this.convert(playlist)) + this.transformers.rundowns.updateCorePlaylist(id, playlist) } } private onRemoved(id: Core.RundownPlaylistId): void { diff --git a/packages/apps/backend/src/sofie-core-connection/dataTransformers/RundownTransformer.ts b/packages/apps/backend/src/sofie-core-connection/dataTransformers/RundownTransformer.ts index 6e0702b..45bea86 100644 --- a/packages/apps/backend/src/sofie-core-connection/dataTransformers/RundownTransformer.ts +++ b/packages/apps/backend/src/sofie-core-connection/dataTransformers/RundownTransformer.ts @@ -10,6 +10,7 @@ export class RundownTransformer { // public readonly rundowns = observable.map() private readonly coreRundowns = observable.map() + private readonly corePlaylistsInfo = observable.map() constructor() { makeObservable(this, { @@ -51,15 +52,21 @@ export class RundownTransformer { const coreRundown = this.coreRundowns.get(coreRundownId) if (!coreRundown) return undefined + const playlist = this.corePlaylistsInfo.get(coreRundown.playlistId) + if (!playlist) return undefined + + const rank = playlist.rundownIdsInOrder.indexOf(coreRundownId) + return { _id: this.convertId(coreRundown._id), playlistId: this.convertId(coreRundown.playlistId), label: coreRundown.name, - rank: 0, // todo + rank: rank, } }) + /** This is called whenever the data from Core changes */ updateCoreRundown(coreRundownId: Core.RundownId, coreRundown: Core.Rundown | undefined) { if (coreRundown) { if (!isEqual(this.coreRundowns.get(coreRundownId), coreRundown)) { @@ -71,6 +78,20 @@ export class RundownTransformer { } } } + /** This is called whenever the data from Core changes */ + updateCorePlaylist(id: Core.RundownPlaylistId, playlist: Core.DBRundownPlaylist | undefined) { + if (playlist) { + const corePlaylistInfo: CorePlaylistInfo = { + rundownRanksAreSetInSofie: playlist.rundownRanksAreSetInSofie, + rundownIdsInOrder: playlist.rundownIdsInOrder, + } + if (!isEqual(this.corePlaylistsInfo.get(id), corePlaylistInfo)) { + this.corePlaylistsInfo.set(id, corePlaylistInfo) + } + } else { + this.corePlaylistsInfo.delete(id) + } + } get showStyleBaseIds(): Core.ShowStyleBaseId[] { const showStyleBaseIds = new Set() @@ -93,3 +114,5 @@ export class RundownTransformer { return id as any } } + +type CorePlaylistInfo = Pick