-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderer.js
410 lines (374 loc) · 15.4 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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
// how to call a function in main?
var jQuery = require('jquery');
var {
ipcRenderer,
remote
} = require('electron');
//console.log('ipcRenderer: ' + ipcRenderer + " " + ipcRenderer.send('giveMeSomething', 'blub'));
var main = remote.require("./main.js");
const dialog = remote.dialog;
var current_form = '';
ipcRenderer.on('calledFromMain', function(event, arg) {
console.log("called from Main with :" + arg);
});
ipcRenderer.on('updateInstrumentList', function(event, data) {
jQuery('#current-instrument-list').children().each(function() {
if (jQuery(this).hasClass('fixed'))
return true;
jQuery(this).remove();
});
console.log("Add instrument names");
for (var i = 0; i < data.length; i++) {
/*<li class="list-group-item">
<img class="img-circle media-object pull-left" src="/assets/img/avatar2.png" width="32" height="32">
<div class="media-body">
<strong>List item title</strong>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</li> */
// lets check if we have an alternative name for this instrument
ipcRenderer.send('getTags', [{
'item': data[i][0],
'prefix': 'instrument-'
}, {
'item': data[i][0],
'prefix': 'guard-'
}]);
//console.log("for " + data[i][0] + " we have : " + data[i][1] + " in updateInstrumentList");
jQuery('#current-instrument-list').append(
'<li class="list-group-item" value=' + data[i][0] + '>' +
'<img class="img-circle media-object pull-left" src="img/instrument.png" width="32" height="32">' +
'<div class="media-body">' +
' <strong>' + data[i][0] + '</strong>' +
' <div><button class="btn btn-default edit"><span class="icon icon-feather"></span></button> <span class="description">' + data[i][1] + '</span></div>' +
' <div class="guard-group"><span class="guard_name"></span></div>' +
'</div></li>');
}
});
/*
ipcRenderer.on('message', function(event, data) {
alert(data);
});
*/
ipcRenderer.on('updateItems', function(event, data) {
// console.log("show these items:" + data);
jQuery('#current-items-list').children().remove();
// we should sort the data by the order from the data dictionary first
for (var i = 0; i < data.length; i++) {
jQuery('#current-items-list').append(
'<li class="list-group-item" value=' + data[i]['field_name'] + ' order=\"' + data[i]['order'] + '\">' +
'<div class="tag-group pull-left"></div>' +
//'<img class="img-circle media-object pull-left" src="img/item.png" width="32" height="32">' +
'<div class="media-body">' +
' <strong>' + data[i]['field_name'] + '</strong>' +
' <p>' + data[i]['field_label'] + '</p>' +
'</div></li>');
}
jQuery('footer h1').text(current_form + " [" + data.length + "]");
jQuery('#export-current-form-button').prop('disabled', '');
//jQuery('#export-nda-select').prop('disabled','');
jQuery('#check-data-button').prop('disabled', '');
jQuery('#clear-messages').prop('disabled', '');
jQuery('#export-current-form-data-button').prop('disabled', '');
jQuery('#current-items-list div.tag-group').append(
'<button class="btn btn-default tag" value="remove" title="Disable this item, do not export. Use Ctrl-Click to open remove by event dialog.">D</button>' +
'<button class="btn btn-default tag" value="long" title="Increase max string length to 60">L</button>' +
'<button class="btn btn-default tag" value="huge" title="Increase max string length to 200">H</button>' +
'<button class="btn btn-default tag" value="date" title="Convert the given value to NDA date">T</button>' +
'<button class="btn btn-default tag" value="label" title="Export as label not as number">V</button>' +
'<button class="btn btn-default tag" value="clearcheckboxes" title="Remove checkbox fields if none set">X</button>' +
'<button class="btn btn-default tag" value="branching2notes" title="Copy branching logic information to notes section">N</button>' +
'<button class="btn btn-default tag" value="recommended" title="If a condition exists, make this field recommended, not conditional">R</button>' +
'<button class="btn btn-default tag" value="alias" title="Add an alias for this item name">A</button>'
);
jQuery('#current-items-list div.tag-group').each(function() {
// try to get the tags for this item
var item = jQuery(this).parent().attr('value');
//console.log("try to get tags for " + item);
ipcRenderer.send('getTags', [{
'item': item,
'id': this
}]);
});
});
ipcRenderer.on('ndaSelectButtonTextChange', function(event, data) {
if (typeof data['shortName'] !== 'undefined' && data['shortName'] !== '') {
jQuery('#nda-select-button-text').text('NDA Select (' + data['shortName'] + ')');
} else {
jQuery('#nda-select-button-text').text('NDA Select');
}
});
ipcRenderer.on('updateTagValues', function(event, data) {
// if the prefix in data is not 'tag-'
console.log("updateTagValues with :" + JSON.stringify(data));
// 'tags': store.get( 'tag-' + data[i]['item'] ), 'data': data
for (var i = 0; i < data.length; i++) {
if (typeof data[i]['prefix'] !== 'undefined' && data[i]['prefix'] == 'instrument-') {
var instr = data[i]['item'];
// ok, update the name of that instrument, not the tags on an item
jQuery('#current-instrument-list li').each(function() {
if (jQuery(this).attr('value') == instr) {
//console.log("in updateTagValues: " + JSON.stringify(data[i]));
jQuery(this).attr('version', data[i]['tags'][1]);
jQuery(this).attr('nda_name', data[i]['tags'][2]);
console.log("set guard name to: " + data[i]['guard_name']);
if (typeof data[i]['guard_name'] !== 'undefined' && data[i]['guard_name'] !== "") {
jQuery(this).attr('guard_name', data[i]['guard_name']);
jQuery(this).find('span.guard_name').text(" GUARDED by " + data[i]['guard_name']);
}
jQuery(this).find('.description').text(" " + data[i]['tags'][0]);
jQuery(this).find('.edit span').addClass('from-store');
}
});
if (typeof data[i]['additional-action'] !== 'undefined' && data[i]['additional-action'] == 'delete') {
console.log("Do we have additional-action? " + JSON.stringify(data[i]));
ipcRenderer.send('deleteTags', [{
'prefix': data[i]['prefix'],
'item': instr,
'tags': [instr]
}]);
// also remove the class from this edit span again
jQuery('#current-instrument-list li').each(function() {
if (jQuery(this).attr('value') == instr) {
jQuery(this).find('.edit span').removeClass('from-store');
}
});
}
} else if (typeof data[i]['prefix'] !== 'undefined' && data[i]['prefix'] == 'guard-') {
var instr = data[i]['item'];
// ok, update the name of that instrument, not the tags on an item
jQuery('#current-instrument-list li').each(function() {
if (jQuery(this).attr('value') == instr) {
if (typeof data[i]['tags'] !== 'undefined' && data[i]['tags'].length > 0 && data[i]['tags'][0] !== "") {
jQuery(this).attr('guard_name', data[i]['tags'][0]);
jQuery(this).find('span.guard_name').text(" GUARDED by " + data[i]['tags'][0]);
}
}
});
} else {
//console.log("need to update the tag for " + data[i]['item'] + " tag: " + data[i]['tags'] );
var itemEntry = jQuery('#current-items-list').find('[value="' + data[i]['item'] + '"]');
//console.log("found itemEntry with :" + jQuery(itemEntry).text());
if (typeof data[i]['tags'] === 'string') // if by chance this tag is a string, convert to array before check
data[i]['tags'] = data[i]['tags'].split(" ");
for (var j = 0; j < data[i]['tags'].length; j++) {
jQuery(itemEntry).find('[value="' + data[i]['tags'][j] + '"]').removeClass("btn-default").addClass('btn-primary');
}
}
}
});
// draw the result for this item to the screen
ipcRenderer.on('showItemCheck', function(event, data) {
var item = data['item'];
var result = data['result'];
var form = data['form'];
var status = data['status'];
var order = data['order'];
var previous_item = jQuery('#message-list').find('[value="' + item + '"]');
if (previous_item.length > 0) {
jQuery(previous_item).children().remove();
jQuery(previous_item).append('<img class="img-circle media-object pull-left" src="img/' + status + '.png" width="32" height="32">' +
'<div class="media-body">' +
' <strong>' + item + " [" + form + ']</strong>' +
' <p>' + result + '</p>' +
'</div>');
} else {
// find the correct position to add this item (based on the order)
var inserted = false;
var elems = jQuery('#message-list li');
var it = jQuery('<li class="list-group-item" value="' + item + '" form="' + form + '" order="' + order + '">' +
'<img class="img-circle media-object pull-left" src="img/' + status + '.png" width="32" height="32">' +
'<div class="media-body">' +
' <strong>' + item + " [" + form + ']</strong>' +
' <p>' + result + '</p>' +
'</div></li>');
jQuery('#message-list').append(it);
}
// sort entries by order
jQuery('#message-list li').sort(function(a, b) {
var c1 = parseInt(jQuery(a).attr('order'));
var c2 = parseInt(jQuery(b).attr('order'));
return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
}).appendTo('#message-list');
var entry = jQuery('#message-list').find('[value="' + item + '"]');
jQuery('#message-list li.list-group-item').removeClass('active');
jQuery(entry).addClass('active');
});
ipcRenderer.on('alert', function(event, data) {
alert("Your request for checking form data failed. Most likely there is not enough memory in the server to request all the data for this form at once. Please test again using single items.\n\n\n" + data);
});
ipcRenderer.on('error', function(event, data) {
alert(data);
});
ipcRenderer.on('message', function(event, data) {
jQuery('footer h1').text(data);
});
ipcRenderer.on('info', function(event, data) {
jQuery('#console').val(jQuery('#console').val() + data + "\n");
});
//
jQuery(document).ready(function() {
jQuery('#open-setup-dialog').on('click', function() {
console.log('open another dialog and get values for connectivity to REDCap');
ipcRenderer.send('openSetupDialog', "");
console.log("open another dialog finished");
//jQuery("#redcap-access-token").value( "BLABLABLA" );
setTimeout(function() {
ipcRenderer.send('my-msg', 'hi');
}, 3000);
});
jQuery('#setup-dialog-ok').on('click', function() {
//console.log("OK button click!");
ipcRenderer.sendSync('closeSetupDialog', "");
});
jQuery('#change-label-dialog-ok').on('click', function() {
//console.log("OK button click!");
ipcRenderer.sendSync('closeChangeLabelDialog', "");
});
jQuery('#instrument-search').on('keyup', function() {
var t = jQuery(this).val();
console.log("search list");
jQuery('#current-instrument-list li.list-group-item').each(function(a) {
var t1 = jQuery(this).attr('value'); // instrument
var t2 = jQuery(this).text();
var s = new RegExp(jQuery('#instrument-search').val(), 'i');
if (t2.match(s) !== null) {
jQuery(this).show();
} else {
jQuery(this).hide();
}
});
});
jQuery('#current-instrument-list').on('click', '.list-group-item', function() {
console.log("click on list group item - update display: " + jQuery(this).attr('value'));
jQuery(this).parent().children().removeClass('active');
jQuery(this).addClass('active');
current_form = jQuery(this).attr('value');
ipcRenderer.send('getItemsForForm', current_form);
});
jQuery('#current-items-list').on('click', '.list-group-item', function() {
var item = jQuery(this).attr('value');
ipcRenderer.send('checkItem', {
item: item,
form: current_form
});
});
jQuery('#export-current-form-button').on('click', function() {
//var dialog = remote.require('dialog');
dialog.showSaveDialog({
defaultPath: current_form + "_dictionary.csv"
}, function(filename) {
if (typeof filename !== 'undefined')
ipcRenderer.send('exportForm', {
form: current_form,
filename: filename
});
});
});
jQuery('#export-nda-select').on('click', function() {
ipcRenderer.send('openNDASelectDialog', "");
});
jQuery('#nda-select-dialog-ok').on('click', function() {
console.log("OK button click!");
ipcRenderer.sendSync('closeNDASelectDialog', "");
});
jQuery('#export-current-form-data-button').on('click', function() {
dialog.showSaveDialog({
defaultPath: current_form + "_data.csv"
}, function(filename) {
if (typeof filename !== 'undefined')
ipcRenderer.send('exportData', {
form: current_form,
filename: filename
});
});
});
jQuery('#check-data-button').on('click', function() {
ipcRenderer.send('checkData', {
form: current_form
});
});
jQuery('#clear-messages').on('click', function() {
jQuery('#message-list').children().remove();
});
jQuery('#current-items-list').on('click', '.tag', function(evt) {
if (jQuery(this).hasClass('btn-primary')) {
jQuery(this).removeClass('btn-primary');
jQuery(this).addClass('btn-default');
var tag = jQuery(this).attr('value');
var item = jQuery(this).parent().parent().attr('value');
// remove the tag again
ipcRenderer.send('deleteTags', [{
'item': item,
'tags': [tag]
}]);
} else {
jQuery(this).removeClass('btn-default');
jQuery(this).addClass('btn-primary');
var tag = jQuery(this).attr('value');
var item = jQuery(this).parent().parent().attr('value');
// add the tag for this item
ipcRenderer.send('setTags', [{
'item': item,
'tags': [tag]
}]);
// for a date field we need some input
if (tag == 'date') {
ipcRenderer.send('openGetDateStringDialog', {
'item': item
});
}
if (tag == 'alias') {
ipcRenderer.send('openGetImportAliasDialog', {
'item': item
});
}
if (tag == 'remove' && evt.ctrlKey) { // we only want to open if the user did a special click
ipcRenderer.send('openDeleteEventDialog', {
'item': item
});
}
}
// disable the default
return false;
});
jQuery('#current-instrument-list').on('click', 'button.edit', function() {
console.log("click on button, name: " + jQuery(this).text());
// use the name in this dialog - if there is no name assigned show an empty string
var default_text = jQuery(this).parent().text().trim();
// console.log("got default text of : " + jQuery(this).parent().parent().find('strong').text());
var instrument = jQuery(this).parent().parent().parent().attr('value'); // unique name of this instrument
var version = jQuery(this).parent().parent().parent().attr('version');
var nda_name = jQuery(this).parent().parent().parent().attr('nda_name');
var guard_name = jQuery(this).parent().parent().parent().attr('guard_name');
// maybe we have a value for this instrument as a tag?
// no, we will only show descriptions that are current (default or tag value)
//console.log("Open change label dialog with: " + default_text + " " + instrument);
ipcRenderer.send('openChangeLabelDialog', {
'name': default_text,
'instrument': instrument,
'version': version,
'nda_name': nda_name,
'guard_name': guard_name
});
console.log("open another dialog finished with " + JSON.stringify({
'name': default_text,
'instrument': instrument,
'version': version,
'nda_name': nda_name,
'guard_name': guard_name
}));
return false;
});
// synchronize the scrolling between the two list displays (one way)
jQuery('#items-pane').on('scroll', function() {
//console.log("scroll on first column");
jQuery('#message-pane').prop("scrollTop", this.scrollTop).prop("scrollLeft", this.scrollLeft);
});
setTimeout(function() {
jQuery('#open-setup-dialog').trigger('click');
}, 500);
});