This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
3440 lines (3254 loc) · 100 KB
/
renderer.js
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"use strict";
// Alpaca compatibility for Bootstrap Multiselect
$.fn.extend({
multipleSelect: $.fn.multiselect,
});
// Should we be in dark mode?
let rendererSettings = window.settings.renderer();
if (rendererSettings.darkMode) {
$("body").addClass("dark-mode");
$(".toggle-dark-mode").html(`<i class="fas fa-sun"></i>`);
}
// Dark mode toggle function
function toggleDarkMode() {
let rendererSettings = window.settings.renderer();
if (!rendererSettings.darkMode) {
window.saveSettings.renderer("darkMode", true);
$("body").addClass("dark-mode");
$(".toggle-dark-mode").html(`<i class="fas fa-sun"></i>`);
} else {
window.saveSettings.renderer("darkMode", false);
$("body").removeClass("dark-mode");
$(".toggle-dark-mode").html(`<i class="fas fa-moon"></i>`);
}
}
// Machine ID
let machineID = window.ipc.getMachineId();
// We should ONLY display the last 8 characters on-screen; host IDs are like passwords
$(".connecting-id").html(machineID.substr(machineID.length - 8));
// Connection
io.sails.url = "https://server.wwsu1069.org";
io.sails.query = `host=${machineID}`;
io.sails.reconnectionAttempts = 3; // Upon first loading, we should limit connection attempts to 3. But in the disconnect event, it should be infinity.
let socket = io.sails.connect();
$("#connecting").removeClass("d-none");
$("#loading").addClass("d-none");
// Add a 30-second timeout and display error if not connected within 30 seconds (works around a getcookie error that gets thrown when no internet, but does not emit error events)
let connectTimeout = setTimeout(() => {
$("#unauthorized").removeClass("d-none");
$("#connecting").addClass("d-none");
$("#reconnecting").addClass("d-none");
$("#content").addClass("d-none");
window.ipc.flashMain(true);
}, 30000);
// Add WWSU modules
let wwsumodules = new WWSUmodules(socket);
wwsumodules
.add("WWSUanimations", WWSUanimations)
.add(`WWSUutil`, WWSUutil)
.add("WWSUNavigation", WWSUNavigation)
.add("noReq", WWSUreq, { host: null })
.add("WWSUMeta", WWSUMeta)
.add("hostReq", WWSUreq, {
host: machineID,
usernameField: "host",
authPath: "/auth/host",
authName: "Host",
})
.add("WWSUdirectors", WWSUdirectors, { host: machineID })
.add("directorReq", WWSUreq, {
host: machineID,
db: "WWSUdirectors",
filter: null,
usernameField: "name",
authPath: "/auth/director",
authName: "Director",
})
.add("adminDirectorReq", WWSUreq, {
host: machineID,
db: "WWSUdirectors",
filter: { admin: true },
usernameField: "name",
authPath: "/auth/admin-director",
authName: "Administrator Director",
})
.add("masterDirectorReq", WWSUreq, {
host: machineID,
db: "WWSUdirectors",
filter: { ID: 1 },
usernameField: "name",
authPath: "/auth/admin-director",
authName: "Master Director",
})
.add("WWSUconfig", WWSUconfig)
.add("WWSUlogs", WWSUlogs)
.add("WWSUdjs", WWSUdjs)
.add("djReq", WWSUreq, {
host: machineID,
db: "WWSUdjs",
filter: { active: true },
usernameField: "name",
authPath: "/auth/dj",
authName: "DJ",
})
.add("WWSUstatus", WWSUstatus)
.add("WWSUeas", WWSUeas)
.add("WWSUannouncements", WWSUannouncements, { types: ["all"] })
.add("WWSUcalendar", WWSUcalendar)
.add("WWSUsubscriptions", WWSUsubscriptions)
.add("WWSUapi", WWSUapi)
.add("WWSUdiscipline", WWSUdiscipline)
.add("WWSUrecipients", WWSUrecipients)
.add("WWSUhosts", WWSUhosts, {
machineID: machineID,
app: window.ipc.getAppVersion(),
})
.add("WWSUrequests", WWSUrequests)
.add("WWSUtimesheet", WWSUtimesheet)
.add("WWSUstate", WWSUstate)
.add("WWSUclimacell", WWSUclimacell)
.add("WWSUinventory", WWSUinventory)
.add("WWSUmessages", WWSUmessages)
.add("WWSUversion", WWSUversion, { app: "wwsu-dj-controls" })
.add("WWSUSilence", WWSUSilence)
.add("WWSUremote", WWSUremote)
.add("WWSUremoteQuality", WWSUremoteQuality)
.add("WWSUunderwritings", WWSUunderwritings)
.add("WWSUsongs", WWSUsongs)
.add("WWSUdjnotes", WWSUdjnotes)
.add("WWSUemail", WWSUemail)
.add("WWSUehhh", WWSUehhh, { src: ["assets/voice-queues/ehhh.mp3"] })
.add("WWSUclocks", WWSUclocks);
// Reference modules to variables
let animations = wwsumodules.get("WWSUanimations");
let util = wwsumodules.get("WWSUutil");
let navigation = wwsumodules.get("WWSUNavigation");
let meta = wwsumodules.get("WWSUMeta");
let directors = wwsumodules.get("WWSUdirectors");
let config = wwsumodules.get("WWSUconfig");
let logs = wwsumodules.get("WWSUlogs");
let djs = wwsumodules.get("WWSUdjs");
let status = wwsumodules.get("WWSUstatus");
let eas = wwsumodules.get("WWSUeas");
let announcements = wwsumodules.get("WWSUannouncements");
let calendar = wwsumodules.get("WWSUcalendar");
let subscriptions = wwsumodules.get("WWSUsubscriptions");
let api = wwsumodules.get("WWSUapi");
let discipline = wwsumodules.get("WWSUdiscipline");
let recipients = wwsumodules.get("WWSUrecipients");
let hosts = wwsumodules.get("WWSUhosts");
let requests = wwsumodules.get("WWSUrequests");
let timesheets = wwsumodules.get("WWSUtimesheet");
let state = wwsumodules.get("WWSUstate");
let climacell = wwsumodules.get("WWSUclimacell");
let messages = wwsumodules.get("WWSUmessages");
let inventory = wwsumodules.get("WWSUinventory");
let _version = wwsumodules.get("WWSUversion"); // "version" is already declared; use underscore
let silence = wwsumodules.get("WWSUSilence");
let remote = wwsumodules.get("WWSUremote");
let remoteQuality = wwsumodules.get("WWSUremoteQuality");
let underwritings = wwsumodules.get("WWSUunderwritings");
let songs = wwsumodules.get("WWSUsongs");
let email = wwsumodules.get("WWSUemail");
let djnotes = wwsumodules.get("WWSUdjnotes");
let ehhh = wwsumodules.get("WWSUehhh");
let clocks = wwsumodules.get("WWSUclocks");
// Immediately initialize clocks so we can begin adding them.
clocks.init();
// Sound alerts
let sounds = {
onBreak: new Howl({ src: ["assets/voice-queues/break.mp3"] }),
oneMinute: new Howl({ src: ["assets/voice-queues/oneMinute.mp3"] }),
thirtySeconds: new Howl({
src: ["assets/voice-queues/thirtySeconds.mp3"],
}),
fifteenSeconds: new Howl({
src: ["assets/voice-queues/fifteenSeconds.mp3"],
}),
tenSeconds: new Howl({ src: ["assets/voice-queues/tenSeconds.mp3"] }),
fiveSeconds: new Howl({ src: ["assets/voice-queues/fiveSeconds.mp3"] }),
three: new Howl({ src: ["assets/voice-queues/three.mp3"] }),
two: new Howl({ src: ["assets/voice-queues/two.mp3"] }),
one: new Howl({ src: ["assets/voice-queues/one.mp3"] }),
callQuality: new Howl({ src: ["assets/voice-queues/callQuality.mp3"] }),
callSilence: new Howl({ src: ["assets/voice-queues/callSilence.mp3"] }),
callTerminated: new Howl({
src: ["assets/voice-queues/callTerminated.mp3"],
}),
};
// letiables
let breakNotified = false; // Did we notify the DJ they have to take a top of hour ID break?
let queueLength = 0; // Current queue in seconds
let countDown = 0; // Countdown to on air in seconds
let timeOut = 0; // Time left in a break in seconds
// Available audio devices
let audioDevices = [];
// Remote calls
let pendingHostCall;
let badQualityTimer;
// TODO admin item
let todos = {
status: {
danger: 0,
orange: 0,
warning: 0,
info: 0,
primary: 0,
},
accountability: {
danger: 0,
orange: 0,
warning: 0,
info: 0,
primary: 0,
},
timesheets: {
danger: 0,
orange: 0,
warning: 0,
info: 0,
primary: 0,
},
DJs: {
danger: 0,
orange: 0,
warning: 0,
info: 0,
primary: 0,
},
};
// What we notified as should be playing now
let notifiedShouldBePlaying = ``;
let nowEvent = null;
let notifyEvent = null;
// Navigation
navigation
.addItem(
"#nav-dashboard",
"#section-dashboard",
"Dashboard - WWSU DJ Controls",
"/",
true
)
.addItem(
"#nav-announcements-view",
"#section-announcements-view",
"View Announcements - WWSU DJ Controls",
"/announcements-view",
false
)
.addItem(
"#nav-chat",
"#section-chat",
"Messages / Chat - WWSU DJ Controls",
"/chat",
false
)
.addItem(
"#nav-requests",
"#section-requests",
"Track requests - WWSU DJ Controls",
"/requests",
false
)
.addItem(
"#nav-weather",
"#section-weather",
"Weather - WWSU DJ Controls",
"/weather",
false
)
.addItem(
"#nav-report",
"#section-report",
"Report a Problem - WWSU DJ Controls",
"/report",
false
)
.addItem(
"#nav-audio",
"#section-audio",
"Audio Settings - WWSU DJ Controls",
"/audio",
false,
() => {
$("#section-audio-recorder-form").alpaca({
schema: {
type: "object",
properties: {
delay: {
type: "number",
title: "Delay (milliseconds)",
},
recordPath: {
type: "string",
format: "uri",
title: "Path to audio recordings",
},
},
},
options: {
fields: {
delay: {
helper:
"How much time passes between a state change and when the input device receives the audio? For example, if the input device is subject to a delay system, you would put the amount of delay time in here.",
events: {
change: function () {
let value = this.getValue();
if (!this.handleValidate()) {
console.log(`invalid`);
return;
}
window.saveSettings.recorder("delay", value);
},
},
},
// TODO: re-compile alpaca with the capability of choosing a folder.
recordPath: {
helpers: [
`Write the full path to the directory you want audio files (webm format) to be saved`,
`Sub-directories for automation, remote, live, and sports will be created automatically after the first recording is saved.`,
`Additional sub-sub-directories will be created automatically to organize recordings by genre, show, or sport.`,
],
events: {
change: function () {
let value = this.getValue();
if (!this.handleValidate()) {
console.log(`invalid`);
return;
}
window.saveSettings.recorder("recordPath", value);
startRecording(0);
},
},
},
},
},
data: window.settings.recorder(),
});
$("#section-audio-silence-form").alpaca({
schema: {
type: "object",
properties: {
delay: {
type: "number",
title: "Delay (milliseconds)",
required: true,
minimum: 0,
},
threshold: {
type: "number",
title: "Threshold (percentile 0.0 - 1.0)",
minimum: 0,
maximum: 1,
required: true,
},
},
},
options: {
fields: {
delay: {
helper:
"How much time should elapse when the volume of the combined input devices for silence monitoring drops below the threshold before DJ Controls triggers the silence alarm in WWSU?",
events: {
change: function () {
let value = this.getValue();
if (!this.handleValidate()) {
console.log(`invalid`);
return;
}
window.saveSettings.silence("delay", value);
window.ipc.silence.setting([]);
},
},
},
threshold: {
helper:
"At what volume percentile (0.0 - 1.0) should silence be considered detected when the combined volumes of input devices with silence checked drop below this value?",
events: {
change: function () {
let value = this.getValue();
if (!this.handleValidate()) {
console.log(`invalid`);
return;
}
window.saveSettings.silence("threshold", value);
window.ipc.silence.setting([]);
},
},
},
},
},
data: window.settings.silence(),
});
}
)
.addItem(
"#nav-serial",
"#section-serial",
"Serial Port Settings - WWSU DJ Controls",
"/serial",
false
)
.addItem(
"#nav-notifications",
"#section-notifications",
"Notifications / Todo - WWSU DJ Controls",
"/notifications",
false
)
.addItem(
"#nav-announcements",
"#section-announcements",
"Manage Announcements - WWSU DJ Controls",
"/announcements",
false
)
.addItem(
"#nav-api",
"#section-api",
"Make API Query - WWSU DJ Controls",
"/api",
false
)
.addItem(
"#nav-bans",
"#section-bans",
"Manage Bans - WWSU DJ Controls",
"/bans",
false
)
.addItem(
"#nav-calendar",
"#section-calendar",
"Manage Calendar - WWSU DJ Controls",
"/calendar",
false,
() => {
fullCalendar.updateSize();
}
)
.addItem(
"#nav-directors",
"#section-directors",
"Manage Directors - WWSU DJ Controls",
"/directors",
false
)
.addItem(
"#nav-djs",
"#section-djs",
"Manage DJs - WWSU DJ Controls",
"/djs",
false
)
.addItem(
"#nav-eas",
"#section-eas",
"Manage Internal EAS - WWSU DJ Controls",
"/eas",
false
)
.addItem(
"#nav-email",
"#section-email",
"Email DJs or Directors - WWSU DJ Controls",
"/eas",
false
)
.addItem(
"#nav-hosts",
"#section-hosts",
"Manage Hosts - WWSU DJ Controls",
"/hosts",
false
)
.addItem(
"#nav-inventory",
"#section-inventory",
"Manage Inventory - WWSU DJ Controls",
"/inventory",
false
)
.addItem(
"#nav-logs",
"#section-logs",
"Operation Logs - WWSU DJ Controls",
"/logs",
false
)
.addItem(
"#nav-timesheets",
"#section-timesheets",
"Director timesheets - WWSU DJ Controls",
"/timesheets",
false
)
.addItem(
"#nav-underwritings",
"#section-underwritings",
"Manage Underwritings - WWSU DJ Controls",
"/underwritings",
false
);
// Click events
$(".status-more").on("click", () => {
status.statusModal.iziModal("open");
});
$(".eas-more").on("click", () => {
eas.easModal.iziModal("open");
});
$(".btn-calendar-definitions").on("click", () => {
calendar.definitionsModal.iziModal("open");
});
$(".btn-calendar-prerequisites").on("click", () => {
calendar.prerequisitesModal.iziModal("open");
});
$(".btn-manage-events").on("click", () => {
calendar.showSimpleEvents();
});
$("#section-logs-date-browse").on("click", () => {
logs.showAttendance($("#section-logs-date").val());
});
$(".chat-recipients").on("click", () => {
recipients.openRecipients();
});
$("#section-audio-devices-refresh").on("click", () => {
$("#section-audio-devices").block({
message: "<h1>Refreshing audio process...</h1>",
css: { border: "3px solid #a00" },
timeout: 30000,
onBlock: () => {
window.ipc.audioRefreshDevices(true);
},
});
});
$("#section-serial-delay-refresh").on("click", () => {
$("#section-serial-delay").block({
message: "<h1>Refreshing serial ports...</h1>",
css: { border: "3px solid #a00" },
timeout: 30000,
onBlock: () => {
refreshSerialPorts();
},
});
});
$(".chat-mute").on("click", () => {
if (recipients.activeRecipient)
discipline.simpleMuteForm(recipients.activeRecipient);
});
$(".chat-ban").on("click", () => {
if (recipients.activeRecipient)
discipline.simpleBanForm(recipients.activeRecipient);
});
$(".btn-dashboard-meta-clear").on("click", () => {
hosts.promptIfNotHost(`Mark DJ / Producer as talking`, () => {
logs.add(
{
logtype: "manual",
logsubtype: meta.meta ? meta.meta.show : "",
loglevel: "secondary",
logIcon: "fas fa-file",
title: "DJ / Producer began talking.",
},
true
);
});
});
$(".btn-inventory-init").on("click", () => {
if (hosts.client.admin) {
inventory.init();
inventory.initTable("#section-inventory-content");
}
});
// Operation click events
$(".btn-operation-resume").on("click", () => {
if (
meta.meta.hostCalling !== null &&
hosts.client.ID === meta.meta.hostCalling &&
(meta.meta.state.startsWith("remote_") ||
meta.meta.state.startsWith("sportsremote_") ||
pendingHostCall)
) {
let called = recipients
.db()
.get()
.find((rec) => rec.hostID === meta.meta.hostCalled);
if (!called || !called.peer || called.status !== 5) {
$(document).Toasts("create", {
class: "bg-warning",
title: "Remote host not connected",
delay: 30000,
autohide: true,
body: `The host receiving the audio for the broadcast is not connected. Please wait until the resume button flashes to indicate it re-connected, or end and restart the remote broadcast with a different host.`,
});
ehhh.play();
remote.request({ ID: meta.meta.hostCalled || pendingHostCall });
return;
}
}
state.return({});
});
$(".btn-operation-15-psa").on("click", () => {
state.queuePSA({ duration: 15 });
});
$(".btn-operation-30-psa").on("click", () => {
state.queuePSA({ duration: 30 });
});
$(".btn-operation-automation").on("click", () => {
if (
notifyEvent &&
notifyEvent.unique !== meta.meta.calendarUnique &&
["show", "sports"].indexOf(notifyEvent.type) !== -1
) {
state.automation({ transition: true });
state.showNextDJModal(notifyEvent.name);
} else {
state.automation({ transition: false });
}
});
$(".btn-operation-break").on("click", () => {
state.break({ halftime: false, problem: false });
});
$(".btn-operation-extended-break").on("click", () => {
state.break({ halftime: true, problem: false });
});
$(".btn-operation-top-add").on("click", () => {
state.queueTopAdd({});
});
$(".btn-operation-liner").on("click", () => {
state.queueLiner({});
});
$(".btn-operation-dump").on("click", () => {
state.dump({});
});
$(".btn-operation-live").on("click", () => {
state.showLiveForm();
});
$(".btn-operation-remote").on("click", () => {
state.showRemoteForm();
});
$(".btn-operation-log").on("click", () => {
logs.showLogForm();
});
$(".btn-operation-sports").on("click", () => {
state.showSportsForm();
});
$(".btn-operation-sportsremote").on("click", () => {
state.showSportsRemoteForm();
});
// Initialize stuff
status.initReportForm(`DJ Controls`, `#section-report-form`);
logs.initAttendanceTable(`#section-logs-table-div`);
logs.initDashboardLogs(`#section-dashboard-logs`);
api.initApiForm("#section-api-form");
email.initForm("#section-email-form");
requests.initTable(
"#section-requests-table-div",
"#nav-requests",
".track-requests"
);
timesheets.init(
`#section-timesheets-hours`,
`#section-timesheets-records`,
`#section-timesheets-start`,
`#section-timesheets-end`,
`#section-timesheets-browse`
);
messages.initComponents(
".chat-active-recipient",
".chat-status",
".chat-messages",
".chat-form",
".chat-mute",
".chat-ban",
".messages-new-all",
".nav-icon-messages"
);
climacell.initClockForecast("forecast", "#weather-forecast-donut");
calendar.initClock("clockwheel", "#clockwheel-donut");
// Define recorder function
function startRecording(delay) {
let recordState = null;
let preText = ``;
let preText2 = ``;
let temp = ``;
if (meta.meta.state === "live_on") {
recordState = "live";
temp = meta.meta.show.split(" - ");
preText = window.sanitize.string(temp[1]);
preText2 = `${window.sanitize.string(meta.meta.show)}`;
} else if (meta.meta.state === "prerecord_on") {
recordState = "prerecord";
temp = meta.meta.show.split(" - ");
preText = window.sanitize.string(temp[1]);
preText2 = `${window.sanitize.string(meta.meta.show)}`;
} else if (meta.meta.state === "remote_on") {
recordState = "remote";
temp = meta.meta.show.split(" - ");
preText = window.sanitize.string(temp[1]);
preText2 = `${window.sanitize.string(meta.meta.show)}${
meta.meta.state === `prerecord_on` ? ` PRERECORDED` : ``
}`;
} else if (
meta.meta.state === "sports_on" ||
meta.meta.state === "sportsremote_on"
) {
recordState = "sports";
preText = window.sanitize.string(meta.meta.show);
preText2 = window.sanitize.string(meta.meta.show);
} else if (
meta.meta.state === `automation_on` ||
meta.meta.state === `automation_genre` ||
meta.meta.state === `automation_playlist`
) {
recordState = "automation";
preText = window.sanitize.string(meta.meta.genre);
preText2 = window.sanitize.string(meta.meta.genre);
} else if (
meta.meta.state.includes("_break") ||
meta.meta.state.includes("_returning") ||
meta.meta.state.includes("_halftime")
) {
window.ipc.recorder.stop([delay]);
} else {
recordState = "automation";
preText = window.sanitize.string(meta.meta.genre);
preText2 = window.sanitize.string(meta.meta.genre);
}
if (recordState !== null) {
if (hosts.client.recordAudio) {
window.ipc.recorder.start([
`${recordState}/${preText}/${preText2} (${moment().format(
"YYYY_MM_DD HH_mm_ss"
)})`,
delay,
]);
} else {
window.ipc.recorder.stop([-1]);
}
}
}
// CALENDAR
// Initialize Calendar
let calendarEl = document.getElementById("calendar");
let fullCalendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
start: "prev,next today",
center: "title",
end: "dayGridMonth,timeGridWeek,timeGridDay,listWeek",
},
initialView: "timeGridWeek",
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectMirror: true,
nowIndicator: true,
editable: true,
eventResourceEditable: false,
themeSystem: "bootstrap",
dayMaxEvents: 5,
slotDuration: "00:15:00",
events: function (info, successCallback, failureCallback) {
animations.add("calendar-update", () => {
$("#calendar").block({
message: "<h1>Loading...</h1>",
css: { border: "3px solid #a00" },
timeout: 30000,
onBlock: () => {
calendar.getEvents(
(events) => {
events = events
.filter((event) => {
// Filter out events by filters
if (event.scheduleType === "canceled-changed") return false;
let temp = document.getElementById(`filter-${event.type}`);
if (temp !== null && temp.checked) {
return true;
} else {
return false;
}
})
.map((event) => {
let borderColor;
let title = `${event.type}: ${event.hosts} - ${event.name}`;
if (
["canceled", "canceled-system"].indexOf(
event.scheduleType
) !== -1
) {
borderColor = "#ff0000";
title += ` (CANCELED)`;
} else if (
["updated", "updated-system"].indexOf(
event.scheduleType
) !== -1
) {
borderColor = "#ffff00";
title += ` (changed this occurrence)`;
} else if (
["unscheduled"].indexOf(event.scheduleType) !== -1
) {
borderColor = "#00ff00";
title += ` (unscheduled/unauthorized)`;
} else {
borderColor = "#0000ff";
}
return {
id: event.unique,
start: moment.parseZone(event.start).toISOString(true),
end: moment.parseZone(event.end).toISOString(true),
title: title,
backgroundColor:
["canceled", "canceled-system"].indexOf(
event.scheduleType
) === -1
? event.color
: "#161616",
textColor: util.getContrastYIQ(event.color)
? "#161616"
: "#e6e6e6",
borderColor: borderColor,
extendedProps: {
event: event,
},
};
});
successCallback(events);
fullCalendar.updateSize();
$("#calendar").unblock();
},
moment(info.start).subtract(1, "days").toISOString(true),
moment(info.end).toISOString(true)
);
},
});
});
},
eventClick: function (info) {
calendar.showClickedEvent(info.event.extendedProps.event);
},
select: function (info) {
calendar.newOccurrence(info.startStr, info.endStr);
},
eventDrop: function (info) {
let duration = moment(info.event.end).diff(info.event.start, "minutes");
if (duration > 60 * 24) {
$(document).Toasts("create", {
class: "bg-warning",
title: "Multi-day Events Not Allowed",
body: "Occurrences may not last more than 24 hours. Consider setting up a recurring schedule.",
autohide: true,
delay: 15000,
});
ehhh.play();
return;
}
calendar.showOccurrenceForm(
info.event.extendedProps.event,
info.event.startStr,
duration
);
info.revert();
},
eventResize: function (info) {
let duration = moment(info.event.end).diff(info.event.start, "minutes");
if (duration > 60 * 24) {
$(document).Toasts("create", {
class: "bg-warning",
title: "Multi-day Events Not Allowed",
body: "Occurrences may not last more than 24 hours. Consider setting up a recurring schedule.",
autohide: true,
delay: 15000,
});
ehhh.play();
return;
}
calendar.showOccurrenceForm(
info.event.extendedProps.event,
info.event.startStr,
duration
);
info.revert();
},
});
fullCalendar.render();
// Add click events to the filter by switches
[
"show",
"sports",
"remote",
"prerecord",
"genre",
"playlist",
"event",
"onair-booking",
"prod-booking",
"office-hours",
].map((type) => {
let temp = document.getElementById(`filter-${type}`);
if (temp !== null) {
temp.addEventListener("click", (e) => {
fullCalendar.refetchEvents();
});
}
});
// Add click events to filter group buttons
$("#filter-group-broadcasts").on("click", (e) => {
["genre", "event", "onair-booking", "prod-booking", "office-hours"].map(
(type) => $(`#filter-${type}`).prop("checked", false)
);
["show", "sports", "remote", "prerecord", "playlist"].map((type) =>
$(`#filter-${type}`).prop("checked", true)
);
fullCalendar.refetchEvents();
});
$("#filter-group-bookings").on("click", (e) => {
[
"show",
"sports",
"remote",
"prerecord",
"genre",
"playlist",
"event",
"office-hours",
].map((type) => $(`#filter-${type}`).prop("checked", false));
["onair-booking", "prod-booking"].map((type) =>
$(`#filter-${type}`).prop("checked", true)
);
fullCalendar.refetchEvents();
});
$("#filter-group-clear").on("click", (e) => {
[
"show",
"sports",
"remote",
"prerecord",
"genre",
"playlist",
"event",
"office-hours",
"onair-booking",
"prod-booking",
].map((type) => $(`#filter-${type}`).prop("checked", false));
fullCalendar.refetchEvents();
});
window.ipc.on.console((event, arg) => {
switch (arg[0]) {
case "log":
console.log(arg[1]);
break;
case "dir":
console.dir(arg[1]);
break;
case "error":
console.error(arg[1]);
break;
}
});
// When the recorder is ready, determine if a recording should be started
window.ipc.on.recorderReady((event, arg) => {
animations.add("notifications-recorder", () => {
$(".notifications-recorder").removeClass("badge-secondary");
$(".notifications-recorder").addClass("badge-warning");
});
startRecording(-1);
});
window.ipc.on.delayReady((event, arg) => {
animations.add("notifications-delay", () => {
$(".notifications-delay").removeClass("badge-secondary");
$(".notifications-delay").removeClass("badge-warning");
$(".notifications-delay").removeClass("badge-danger");
$(".notifications-delay").addClass("badge-success");
});
});