@@ -12,6 +12,7 @@ import { BucketAdLib } from '@sofie-automation/corelib/dist/dataModel/BucketAdLi
12
12
import { interpollateTranslation } from '@sofie-automation/corelib/dist/TranslatableMessage'
13
13
import { AdLibActionType , AdLibStatus } from './adLibsTopic'
14
14
import { CollectionHandlers } from '../liveStatusServer'
15
+ import { sortContent , WithSortingMetadata } from './helpers/contentSorting'
15
16
16
17
const THROTTLE_PERIOD_MS = 100
17
18
@@ -50,63 +51,29 @@ export class BucketsTopic extends WebSocketTopicBase implements WebSocketTopic {
50
51
}
51
52
52
53
sendStatus ( subscribers : Iterable < WebSocket > ) : void {
53
- const buckets : BucketStatus [ ] = this . _buckets . map ( ( bucket ) => {
54
+ const sortedBuckets = sortContent ( this . _buckets . map ( this . addBucketSortingMetadata ) )
55
+
56
+ const bucketStatuses : BucketStatus [ ] = sortedBuckets . map ( ( bucket ) => {
54
57
const bucketId = unprotectString ( bucket . _id )
55
- const bucketAdLibs = ( this . _adLibsByBucket ?. [ bucketId ] ?? [ ] ) . map ( ( adLib ) => {
56
- const sourceLayerName = this . _sourceLayersMap . get ( adLib . sourceLayerId )
57
- const outputLayerName = this . _outputLayersMap . get ( adLib . outputLayerId )
58
- return literal < BucketAdLibStatus > ( {
59
- id : unprotectString ( adLib . _id ) ,
60
- name : adLib . name ,
61
- sourceLayer : sourceLayerName ?? 'invalid' ,
62
- outputLayer : outputLayerName ?? 'invalid' ,
63
- actionType : [ ] ,
64
- tags : adLib . tags ,
65
- externalId : adLib . externalId ,
66
- publicData : adLib . publicData ,
67
- } )
68
- } )
69
- const bucketAdLibActions = ( this . _adLibActionsByBucket ?. [ bucketId ] ?? [ ] ) . map ( ( action ) => {
70
- const sourceLayerName = this . _sourceLayersMap . get (
71
- ( action . display as IBlueprintActionManifestDisplayContent ) . sourceLayerId
72
- )
73
- const outputLayerName = this . _outputLayersMap . get (
74
- ( action . display as IBlueprintActionManifestDisplayContent ) . outputLayerId
75
- )
76
- const triggerModes = action . triggerModes
77
- ? action . triggerModes . map ( ( t ) =>
78
- literal < AdLibActionType > ( {
79
- name : t . data ,
80
- label : interpollateTranslation ( t . display . label . key , t . display . label . args ) ,
81
- } )
82
- )
83
- : [ ]
84
- return literal < BucketAdLibStatus > ( {
85
- id : unprotectString ( action . _id ) ,
86
- name : interpollateTranslation ( action . display . label . key , action . display . label . args ) ,
87
- sourceLayer : sourceLayerName ?? 'invalid' ,
88
- outputLayer : outputLayerName ?? 'invalid' ,
89
- actionType : triggerModes ,
90
- tags : action . display . tags ,
91
- externalId : action . externalId ,
92
- publicData : action . publicData ,
93
- } )
94
- } )
58
+
59
+ const bucketAdLibs = ( this . _adLibsByBucket ?. [ bucketId ] ?? [ ] ) . map ( this . toSortableBucketAdLib )
60
+ const bucketAdLibActions = ( this . _adLibActionsByBucket ?. [ bucketId ] ?? [ ] ) . map (
61
+ this . toSortableBucketAdLibAction
62
+ )
63
+
95
64
return {
96
65
id : bucketId ,
97
66
name : bucket . name ,
98
- adLibs : [ ...bucketAdLibs , ...bucketAdLibActions ] ,
67
+ adLibs : sortContent ( [ ...bucketAdLibs , ...bucketAdLibActions ] ) ,
99
68
}
100
69
} )
101
70
102
71
const bucketsStatus : BucketsStatus = {
103
72
event : 'buckets' ,
104
- buckets : buckets ,
73
+ buckets : bucketStatuses ,
105
74
}
106
75
107
- for ( const subscriber of subscribers ) {
108
- this . sendMessage ( subscriber , bucketsStatus )
109
- }
76
+ this . sendMessage ( subscribers , bucketsStatus )
110
77
}
111
78
112
79
private onShowStyleBaseUpdate = ( showStyleBase : ShowStyle | undefined ) : void => {
@@ -118,7 +85,8 @@ export class BucketsTopic extends WebSocketTopicBase implements WebSocketTopic {
118
85
119
86
private onBucketsUpdate = ( buckets : Bucket [ ] | undefined ) : void => {
120
87
this . logUpdateReceived ( 'buckets' )
121
- this . _buckets = buckets ?? [ ]
88
+ buckets ??= [ ]
89
+ this . _buckets = sortContent ( buckets . map ( this . addBucketSortingMetadata ) )
122
90
this . throttledSendStatusToAll ( )
123
91
}
124
92
@@ -133,4 +101,66 @@ export class BucketsTopic extends WebSocketTopicBase implements WebSocketTopic {
133
101
this . _adLibsByBucket = _ . groupBy ( adLibs ?? [ ] , 'bucketId' )
134
102
this . throttledSendStatusToAll ( )
135
103
}
104
+
105
+ private addBucketSortingMetadata = ( bucket : Bucket ) : WithSortingMetadata < Bucket > => {
106
+ return {
107
+ obj : bucket ,
108
+ id : unprotectString ( bucket . _id ) ,
109
+ itemRank : bucket . _rank ,
110
+ label : bucket . name ,
111
+ }
112
+ }
113
+
114
+ private toSortableBucketAdLib = ( adLib : BucketAdLib ) : WithSortingMetadata < BucketAdLibStatus > => {
115
+ const sourceLayerName = this . _sourceLayersMap . get ( adLib . sourceLayerId )
116
+ const outputLayerName = this . _outputLayersMap . get ( adLib . outputLayerId )
117
+ return {
118
+ obj : {
119
+ id : unprotectString ( adLib . _id ) ,
120
+ name : adLib . name ,
121
+ sourceLayer : sourceLayerName ?? 'invalid' ,
122
+ outputLayer : outputLayerName ?? 'invalid' ,
123
+ actionType : [ ] ,
124
+ tags : adLib . tags ,
125
+ externalId : adLib . externalId ,
126
+ publicData : adLib . publicData ,
127
+ } ,
128
+ id : unprotectString ( adLib . _id ) ,
129
+ itemRank : adLib . _rank ,
130
+ label : adLib . name ,
131
+ }
132
+ }
133
+
134
+ private toSortableBucketAdLibAction = ( action : BucketAdLibAction ) : WithSortingMetadata < BucketAdLibStatus > => {
135
+ const sourceLayerName = this . _sourceLayersMap . get (
136
+ ( action . display as IBlueprintActionManifestDisplayContent ) . sourceLayerId
137
+ )
138
+ const outputLayerName = this . _outputLayersMap . get (
139
+ ( action . display as IBlueprintActionManifestDisplayContent ) . outputLayerId
140
+ )
141
+ const triggerModes = action . triggerModes
142
+ ? action . triggerModes . map ( ( t ) =>
143
+ literal < AdLibActionType > ( {
144
+ name : t . data ,
145
+ label : interpollateTranslation ( t . display . label . key , t . display . label . args ) ,
146
+ } )
147
+ )
148
+ : [ ]
149
+ const name = interpollateTranslation ( action . display . label . key , action . display . label . args )
150
+ return {
151
+ obj : {
152
+ id : unprotectString ( action . _id ) ,
153
+ name,
154
+ sourceLayer : sourceLayerName ?? 'invalid' ,
155
+ outputLayer : outputLayerName ?? 'invalid' ,
156
+ actionType : triggerModes ,
157
+ tags : action . display . tags ,
158
+ externalId : action . externalId ,
159
+ publicData : action . publicData ,
160
+ } ,
161
+ id : unprotectString ( action . _id ) ,
162
+ itemRank : action . display . _rank ,
163
+ label : name ,
164
+ }
165
+ }
136
166
}
0 commit comments