forked from Sofie-Automation/sofie-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateNotesForSegment.ts
More file actions
185 lines (176 loc) · 5.29 KB
/
generateNotesForSegment.ts
File metadata and controls
185 lines (176 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import { ITranslatableMessage, NoteSeverity } from '@sofie-automation/blueprints-integration'
import { RundownPlaylistId } from '@sofie-automation/corelib/dist/dataModel/Ids'
import { DBPart } from '@sofie-automation/corelib/dist/dataModel/Part'
import { DBPartInstance } from '@sofie-automation/corelib/dist/dataModel/PartInstance'
import { SegmentOrphanedReason } from '@sofie-automation/corelib/dist/dataModel/Segment'
import { literal } from '@sofie-automation/corelib/dist/lib'
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
import { assertNever } from '@sofie-automation/shared-lib/dist/lib/lib'
import { UISegmentPartNote } from '@sofie-automation/meteor-lib/dist/api/rundownNotifications'
import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
import { generateTranslation } from '@sofie-automation/corelib/dist/lib'
import { SegmentFields, PartFields, PartInstanceFields } from './reactiveContentCache'
export function generateNotesForSegment(
playlistId: RundownPlaylistId,
segment: Pick<DBSegment, SegmentFields>,
nrcsName: string,
parts: Pick<DBPart, PartFields>[],
partInstances: Pick<DBPartInstance, PartInstanceFields>[]
): Array<UISegmentPartNote> {
const notes: Array<UISegmentPartNote> = []
if (segment.notes) {
notes.push(
...segment.notes.map((note, i) =>
literal<UISegmentPartNote>({
_id: protectString(`${segment._id}_segment_${i}`),
playlistId,
rundownId: segment.rundownId,
segmentId: segment._id,
note: {
rank: segment._rank,
...note,
origin: {
...note.origin,
segmentId: segment._id,
rundownId: segment.rundownId,
name: note.origin.name || segment.name,
},
},
})
)
)
}
if (segment.orphaned) {
let message: ITranslatableMessage | undefined
switch (segment.orphaned) {
case SegmentOrphanedReason.DELETED:
message = generateTranslation('Segment no longer exists in {{nrcs}}', {
nrcs: nrcsName,
})
break
case SegmentOrphanedReason.HIDDEN:
message = generateTranslation('Segment was hidden in {{nrcs}}', {
nrcs: nrcsName,
})
break
case SegmentOrphanedReason.ADLIB_TESTING:
// Ignore
break
default:
assertNever(segment.orphaned)
break
}
if (message) {
notes.push({
_id: protectString(`${segment._id}_segment_orphaned`),
playlistId,
rundownId: segment.rundownId,
segmentId: segment._id,
note: {
type: NoteSeverity.WARNING,
message,
rank: segment._rank,
origin: {
segmentId: segment._id,
rundownId: segment.rundownId,
name: segment.name,
},
},
})
}
} else {
const deletedPartInstances = partInstances.filter((p) => p.orphaned === 'deleted' && !p.reset)
if (deletedPartInstances.length > 0) {
notes.push({
_id: protectString(`${segment._id}_partinstances_deleted`),
playlistId,
rundownId: segment.rundownId,
segmentId: segment._id,
note: {
type: NoteSeverity.WARNING,
message: generateTranslation('The following parts no longer exist in {{nrcs}}: {{partNames}}', {
nrcs: nrcsName,
partNames: deletedPartInstances.map((p) => p.part.title).join(', '),
}),
rank: segment._rank,
origin: {
segmentId: segment._id,
rundownId: segment.rundownId,
name: segment.name,
},
},
})
}
}
for (const part of parts) {
const commonOrigin = {
segmentId: part.segmentId,
partId: part._id,
rundownId: part.rundownId,
segmentName: segment.name,
}
if (part.invalidReason) {
notes.push({
_id: protectString(`${segment._id}_part_${part._id}_invalid`),
playlistId,
rundownId: segment.rundownId,
segmentId: segment._id,
note: {
type: part.invalidReason.severity ?? NoteSeverity.ERROR,
message: part.invalidReason.message,
rank: segment._rank,
origin: {
...commonOrigin,
name: part.title,
},
},
})
}
if (part.notes && part.notes.length > 0) {
notes.push(
...part.notes.map((n, i) =>
literal<UISegmentPartNote>({
_id: protectString(`${segment._id}_part_${part._id}_${i}`),
playlistId,
rundownId: segment.rundownId,
segmentId: segment._id,
note: {
...n,
rank: segment._rank,
origin: {
...n.origin,
...commonOrigin,
name: n.origin.name || part.title,
},
},
})
)
)
}
}
// Generate notes for runtime invalidReason on PartInstances
// This is distinct from planned invalidReason on Parts - these are runtime validation issues
for (const partInstance of partInstances) {
// Skip if the PartInstance has been reset (no longer relevant) or has no runtime invalidReason
if (partInstance.reset || !partInstance.invalidReason) continue
notes.push({
_id: protectString(`${segment._id}_partinstance_${partInstance._id}_invalid_runtime`),
playlistId,
rundownId: partInstance.rundownId,
segmentId: segment._id,
note: {
type: partInstance.invalidReason.severity ?? NoteSeverity.ERROR,
message: partInstance.invalidReason.message,
rank: segment._rank,
origin: {
segmentId: partInstance.segmentId,
partId: partInstance.part._id,
rundownId: partInstance.rundownId,
segmentName: segment.name,
name: partInstance.part.title,
},
},
})
}
return notes
}