-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
373 lines (365 loc) · 11.5 KB
/
script.js
File metadata and controls
373 lines (365 loc) · 11.5 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import Vue from 'vue';
import log from 'loglevel';
import { makeURL } from '@/js/utils';
export default {
state: {
currentRevision: null,
revisions: [],
script: {},
cues: {},
cuts: [],
stageDirectionStyles: [],
compiledScripts: [],
},
mutations: {
SET_REVISIONS(state, revisions) {
state.revisions = revisions;
},
SET_CURRENT_REVISION(state, currentRevision) {
state.currentRevision = currentRevision;
},
SET_SCRIPT_PAGE(state, { pageNumber, page }) {
Vue.set(state.script, pageNumber, page);
},
SET_CUES(state, cues) {
state.cues = cues;
},
SET_CUTS(state, cuts) {
state.cuts = cuts;
},
SET_STAGE_DIRECTION_STYLES(state, styles) {
state.stageDirectionStyles = styles;
},
SET_COMPILED_SCRIPTS(state, compiledScripts) {
state.compiledScripts = compiledScripts;
},
},
actions: {
async GET_SCRIPT_REVISIONS(context) {
const response = await fetch(`${makeURL('/api/v1/show/script/revisions')}`);
if (response.ok) {
const revisions = await response.json();
context.commit('SET_REVISIONS', revisions.revisions);
context.commit('SET_CURRENT_REVISION', revisions.current_revision);
} else {
log.error('Unable to get script revisions');
}
},
async ADD_SCRIPT_REVISION(context, scriptRevision) {
const payload = {
description: scriptRevision.description,
};
// Add optional parent_revision_id if provided
if (scriptRevision.parent_revision_id != null) {
payload.parent_revision_id = scriptRevision.parent_revision_id;
}
// Add optional set_as_current if provided (defaults to true on backend)
if (scriptRevision.set_as_current != null) {
payload.set_as_current = scriptRevision.set_as_current;
}
const response = await fetch(`${makeURL('/api/v1/show/script/revisions')}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
if (response.ok) {
context.dispatch('GET_SCRIPT_REVISIONS');
Vue.$toast.success('Added new script revision!');
} else {
const data = await response.json().catch(() => ({}));
log.error('Unable to add new script revision');
Vue.$toast.error(data.message || 'Unable to add new script revision');
}
},
async DELETE_SCRIPT_REVISION(context, revisionID) {
const searchParams = new URLSearchParams({
rev_id: revisionID,
});
const response = await fetch(`${makeURL('/api/v1/show/script/revisions')}?${searchParams}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
context.dispatch('GET_SCRIPT_REVISIONS');
Vue.$toast.success('Deleted script revision!');
} else {
const data = await response.json().catch(() => ({}));
log.error('Unable to delete script revision');
Vue.$toast.error(data.message || 'Unable to delete script revision');
}
},
async LOAD_SCRIPT_REVISION(context, revisionID) {
const response = await fetch(`${makeURL('/api/v1/show/script/revisions/current')}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
new_rev_id: revisionID,
}),
});
if (response.ok) {
context.dispatch('GET_SCRIPT_REVISIONS');
Vue.$toast.success('Loaded script revision!');
} else {
const data = await response.json().catch(() => ({}));
log.error('Unable to load script revision');
Vue.$toast.error(data.message || 'Unable to load script revision');
}
},
async SCRIPT_REVISION_CHANGED(context) {
await context.dispatch('GET_SCRIPT_REVISIONS');
for (const page of Object.keys(context.state.script)) {
await context.dispatch('LOAD_SCRIPT_PAGE', page);
}
await context.dispatch('LOAD_CUES');
await context.dispatch('GET_CUTS');
},
async LOAD_SCRIPT_PAGE(context, page) {
const searchParams = new URLSearchParams({
page,
});
const response = await fetch(`${makeURL('/api/v1/show/script')}?${searchParams}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
const respJson = await response.json();
context.commit('SET_SCRIPT_PAGE', {
pageNumber: respJson.page,
page: respJson.lines,
});
} else {
log.error('Unable to load script page');
}
},
async LOAD_CUES(context) {
const response = await fetch(`${makeURL('/api/v1/show/cues')}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
const respJson = await response.json();
context.commit('SET_CUES', respJson.cues);
} else {
log.error('Unable to load cues');
}
},
async ADD_NEW_CUE(context, cue) {
const response = await fetch(`${makeURL('/api/v1/show/cues')}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(cue),
});
if (response.ok) {
context.dispatch('LOAD_CUES');
Vue.$toast.success('Added new cue!');
} else {
log.error('Unable to add new cue');
Vue.$toast.error('Unable to add new cue');
}
},
async EDIT_CUE(context, cue) {
const response = await fetch(`${makeURL('/api/v1/show/cues')}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(cue),
});
if (response.ok) {
context.dispatch('LOAD_CUES');
Vue.$toast.success('Edited cue!');
} else {
log.error('Unable to edit cue');
Vue.$toast.error('Unable to edit cue');
}
},
async DELETE_CUE(context, cue) {
const searchParams = new URLSearchParams({
cueId: cue.cueId,
lineId: cue.lineId,
});
const response = await fetch(`${makeURL('/api/v1/show/cues')}?${searchParams}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
context.dispatch('LOAD_CUES');
Vue.$toast.success('Deleted cue!');
} else {
log.error('Unable to delete cue');
Vue.$toast.error('Unable to delete cue');
}
},
async SEARCH_CUES(context, { identifier, cueTypeId }) {
const params = new URLSearchParams();
params.append('identifier', identifier);
params.append('cue_type_id', cueTypeId);
const response = await fetch(`${makeURL('/api/v1/show/cues/search')}?${params}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
const result = await response.json();
return result;
}
log.error('Unable to search for cue');
throw new Error('Cue search failed');
},
async GET_CUTS(context) {
const response = await fetch(`${makeURL('/api/v1/show/script/cuts')}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
const respJson = await response.json();
context.commit('SET_CUTS', respJson.cuts);
} else {
log.error('Unable to load script cuts');
}
},
async SAVE_SCRIPT_CUTS(context, cuts) {
const response = await fetch(`${makeURL('/api/v1/show/script/cuts')}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
cuts,
}),
});
if (response.ok) {
await context.dispatch('GET_CUTS');
Vue.$toast.success('Saved script cuts!');
} else {
log.error('Unable to save script cuts');
Vue.$toast.error('Unable to save script cuts');
}
},
async GET_STAGE_DIRECTION_STYLES(context) {
const response = await fetch(`${makeURL('/api/v1/show/script/stage_direction_styles')}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
const respJson = await response.json();
context.commit('SET_STAGE_DIRECTION_STYLES', respJson.styles);
} else {
log.error('Unable to load stage direction styles');
}
},
async ADD_STAGE_DIRECTION_STYLE(context, style) {
const response = await fetch(`${makeURL('/api/v1/show/script/stage_direction_styles')}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(style),
});
if (response.ok) {
context.dispatch('GET_STAGE_DIRECTION_STYLES');
Vue.$toast.success('Added new stage direction style!');
} else {
log.error('Unable to add new stage direction style');
Vue.$toast.error('Unable to add new stage direction style');
}
},
async DELETE_STAGE_DIRECTION_STYLE(context, styleId) {
const searchParams = new URLSearchParams({
id: styleId,
});
const response = await fetch(
`${makeURL('/api/v1/show/script/stage_direction_styles')}?${searchParams}`,
{
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
}
);
if (response.ok) {
context.dispatch('GET_STAGE_DIRECTION_STYLES');
Vue.$toast.success('Deleted stage direction style!');
} else {
log.error('Unable to delete stage direction style');
Vue.$toast.error('Unable to delete stage direction style');
}
},
async UPDATE_STAGE_DIRECTION_STYLE(context, style) {
const response = await fetch(`${makeURL('/api/v1/show/script/stage_direction_styles')}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(style),
});
if (response.ok) {
context.dispatch('GET_STAGE_DIRECTION_STYLES');
Vue.$toast.success('Updated stage direction style!');
} else {
log.error('Unable to edit stage direction style');
Vue.$toast.error('Unable to edit stage direction style');
}
},
async GET_COMPILED_SCRIPTS(context) {
const response = await fetch(`${makeURL('/api/v1/show/script/compiled_scripts')}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
if (response.ok) {
const respJson = await response.json();
context.commit('SET_COMPILED_SCRIPTS', respJson.scripts);
} else {
log.error('Unable to load compiled scripts');
}
},
},
getters: {
SCRIPT_REVISIONS(state) {
return state.revisions;
},
CURRENT_REVISION(state) {
return state.currentRevision;
},
GET_SCRIPT_PAGE: (state) => (page) => {
const pageStr = page.toString();
if (Object.keys(state.script).includes(pageStr)) {
return state.script[pageStr];
}
return [];
},
SCRIPT_CUES(state) {
return state.cues;
},
SCRIPT_CUTS(state) {
return state.cuts;
},
STAGE_DIRECTION_STYLES(state) {
return state.stageDirectionStyles;
},
COMPILED_SCRIPTS(state) {
return state.compiledScripts;
},
},
};