This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
289 lines (250 loc) · 7.93 KB
/
view.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
var $ = require('jquery');
var popper = require('popper.js');
var bootstrap = require('bootstrap');
var func = require('./main_func');
const {dialog} = require('electron').remote
const electron = require('electron');
var osc = require('node-osc');
var ip = require('ip');
var remote = require('electron').remote
var resultFilename = remote.getGlobal('userDataPath') + "/" + "result.json"
var cueList = []
var showInfo = []
var listInfo = []
var currentList;
var allCuelists;
var toggleSwitch = 0
var runTimer;
var startTime = Date.now();
var cueCount = 0;
// Set ui states on startup
$(".colSettings .card-body").collapse("show");
$(".btnStartServer").prop( "disabled", true );
$(".btnStopServer").prop( "disabled", true );
$(".inpCueLists").prop( "disabled", true );
updateStatus("statServer", "Gestopt", "warning");
updateStatus("statIpadress", ip.address(), "dark");
// Card collapse icon init
$(".card-body").each(function(){
if($(this).hasClass("collEnable")){
$(this).parent().find(".card-header").append("<div class=\"collapseArrow down\"><i class=\"mdi mdi-chevron-left\"></i></div>");
}
})
// Card collapse toggle
$(".card .card-header").on("click", function(){
cardCollapse(this, "toggle");
})
// On filedialog Open: load and parse xml file
$(".btnHogExportFileDialog").on("click", function(){
dialog.showOpenDialog({properties: ['openFile']}, function (fileNames) {
if(fileNames !== undefined){
// File opened
$(".inpHogExportFile").val(fileNames[0]);
// Parse input xml file
func.parseHogExport(fileNames[0], function(err, result){
// TODO: controle inbouwen of onderstaande wel bestaan in xml bestand en geef melding
if(err === null){
if(result.Hog.Show[0].Cuelist !== undefined){
allCuelists = result.Hog.Show[0].Cuelist;
showInfo = result.Hog.Show[0]["$"]
// Fill current showname
$(".currentShow").val(showInfo.name);
updateStatus("statCurrShow", showInfo.name, "dark")
// Fill dropdown with available lists
$(".inpCueLists").html("<option value=\"false\">Kies een Cuelist</option>");
for(key in allCuelists){
$(".inpCueLists").append("<option value=\"" + key + "\">" + allCuelists[key]["$"].number + ": " + allCuelists[key]["$"].name + "</option>");
}
// Enable dropdown
$(".inpCueLists").prop( "disabled", false );
}else{
dialog.showMessageBox({
type: "error",
buttons:["Ok"],
message: "Onjuist Hog Export XML bestand",
detail: "Weet je zeker dat je de juiste export hebt gemaakt in de Hog?"
});
}
}else{
dialog.showMessageBox({
type: "error",
buttons:["Ok"],
message: "Dit is geen XML bestand",
detail: "Weet je zeker dat je de juiste export hebt gemaakt in de Hog?"
});
}
})
}
});
})
// On dropdown select: get current cuelist
$(".inpCueLists").on("change", function(){
var chosenListKey = $(this).val();
// Set global
currentList = allCuelists[chosenListKey];
listInfo = currentList["$"]
$(".btnStartServer").prop( "disabled", false );
$(".btnStopServer").prop( "disabled", false );
})
// Start server
$('.btnStartServer').on('click', () => {
// Check if current session has results:
func.getResult(function(resultData){
if(resultData.length < 1){
startServer({reset: true})
}else{
dialog.showMessageBox({
type: "question",
buttons:["Annuleren", "Verdergaan", "Reset"],
message: "Huidige sessie heeft opgenomen cue's",
detail: "Wil je de huidige sessie resetten of verdergaan met opnemen?"
}, function(response){
if(response == 1){
startServer({reset: false})
}else if(response == 2){
startServer({reset: true})
}
});
}
})
})
// Reset timer
$('.btnResetTimer').on('click', function(){
dialog.showMessageBox({
type: "question",
buttons:["Annuleren", "Ok"],
message: "Weet je zeker dat je deze sessie wilt resetten?",
detail: "Huidige opnames gaan verloren"
}, function(response){
if(response == 1){
setTimer("reset");
updateStatus("statRecvCuesCount", "0", "dark");
}
});
});
// Save subtitle file
$('.btnSave').on('click', function(){
// Check of er wat is opgenomen
func.getResult(function(resultData){
if(resultData.length < 1){
dialog.showMessageBox({
type: "error",
buttons:["Ok"],
message: "Er is niks opgenomen.",
detail: "Dus ook niks om op te slaan."
});
}else{
dialog.showSaveDialog({
title: "Ondertitel Opslaan",
defaultPath: '~/Showstudy.ass',
}, (fileName) => {
if (fileName === undefined){
console.log("You didn't save the file");
return;
}else{
func.loadJson(fileName);
}
});
}
});
});
// Open debug window
$('.openDebug').on('click', function(){
electron.remote.getCurrentWindow().toggleDevTools();
});
// Open help window
$('.openHelp').on('click', function(){
func.helpWindow();
});
function startServer(properties){
var serverPort = $(".inpServerPort").val();
// Set button states
$(".inpCueLists").prop( "disabled", true );
$(".btnStartServer").prop( "disabled", true );
$(".btnStopServer").prop( "disabled", false );
// Clear log window
$(".logWindow").html("");
cardCollapse(".colSettings .card-header", "hide")
// Convert to list of objects
var rawList = currentList.Cue
for(key in rawList){
cueList.push(rawList[key]["$"])
}
// Start OSC Server
try {
var oscServer = new osc.Server(serverPort, '0.0.0.0');
if(properties.reset){
setTimer("reset");
}
setTimer("run");
updateStatus("statServer", "Gestart", "success");
} catch (e) {
console.log("Error: Kan server niet verbinden (" + e + ")")
updateStatus("statServer", "Error", "danger");
}
// Handle incoming cues in gui
func.handleOSCMsg(oscServer, listInfo.number, {
onCueIncoming: function(currentCue){
// incoming cue
$(".logWindow").prepend(currentCue.time + " Cue " + currentCue.number + ": " + currentCue.name + " (" + currentCue.comment + ")\n");
cueCount++;
updateStatus("statRecvCuesCount", cueCount, "dark");
},
onPing(){
$(".statHogconnection .statusValue .badge").css({backgroundColor: "#28a745"})
setTimeout(function(){
$(".statHogconnection .statusValue .badge").css({backgroundColor: "#ffc107"});
},200)
}
});
// Bind stop button
$('.btnStopServer').off().on('click', () => {
updateStatus("statServer", "Gestopt", "warning");
$(".inpCueLists").prop( "disabled", false );
$(".btnStartServer").prop( "disabled", false );
$(".btnStopServer").prop( "disabled", true );
oscServer.kill();
setTimer("stop");
//setTimer("reset");
//updateStatus("statRecvCuesCount", "0", "dark");
});
}
function setTimer(state){
if(state == "run"){
runTimer = setInterval(function(){
var currTime = Date.now();
var parsedTime = func.tsToTime(currTime - startTime, false);
updateStatus("statCurrentTime", parsedTime[0]+":"+parsedTime[1]+":"+parsedTime[2], "dark")
}, 1000);
}else if(state == "stop"){
clearInterval(runTimer);
}else if(state == "reset"){
cueCount = 0;
startTime = Date.now();
func.resetTimer();
$(".logWindow").html("");
updateStatus("statCurrentTime", "00:00:00", "dark")
}
}
const BrowserWindow = remote.BrowserWindow;
function cardCollapse(obj, state){
var cardBody = $(obj).parent().find(".card-body");
if(cardBody.hasClass("collapse")){
cardBody.collapse(state);
$(obj).find(".collapseArrow").toggleClass("down");
}
// if collapse is settings card adjust logwindow heigt
if(state == "toggle"){
$(".logWindow").toggleClass("logWindowMax")
}else if(state == "hide"){
$(".logWindow").addClass("logWindowMax")
}else if(state == "show"){
$(".logWindow").removeClass("logWindowMax")
}
}
function updateStatus(type, value, state){
currentItem = $("."+type+" .statusValue .badge");
currentItem.html(value);
currentItem.removeClass("badge-primary badge-secondary badge-success badge-danger badge-warning badge-info badge-light badge-dark")
currentItem.addClass("badge-"+state)
}