This repository has been archived by the owner on Feb 7, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog_add_event.html
398 lines (322 loc) · 12.3 KB
/
dialog_add_event.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Add event</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="./node_modules/@primer/octicons/build/build.css">
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="./node_modules/animate.css/animate.min.css">
<style>
table.scroll {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
border: 1px solid black;
}
table.scroll tbody,
table.scroll thead {
display: block;
width: 100%;
}
thead tr th {
height: 25px;
line-height: 15px;
text-align: left;
vertical-align: top;
}
table.scroll tbody.vscpclass {
height: 30vh;
background-color: rgb(247, 248, 231);
overflow-y: auto;
overflow-x: hidden;
}
table.scroll tbody.vscptype {
height: 30vh;
background-color: rgb(247, 248, 231);
overflow-y: auto;
overflow-x: hidden;
}
table.scroll td.ctext,
table.scroll th.ctext {
text-align: center;
vertical-align: middle;
}
tbody {
border-top: 1px solid black;
}
tbody td,
thead th {
overflow: hidden;
height: 22px;
line-height: 15px;
border-right: 1px solid black;
white-space: nowrap;
}
tbody td:last-child,
thead th:last-child {
border-right: none;
}
body {
margin-right: 10px;
}
</style>
</head>
<body class="bg-light" style="padding-top: 20px;">
<div class="container-fluid">
<div class="row">
<div id="selectHeader" class="col-10">
<h4>Add event</h4>
</div>
<div class="col-2">
</div>
</div>
<div class="row">
<div class="col-10">
<table id="table-vscpclass"
class="table scroll table-sm table-responsive table-hover table-striped table-hover ">
<thead class="thead-light">
<tr class="d-flex">
<th class="col-12 ctext">VSCP classes</th>
</tr>
</thead>
<tbody class="vscpclass">
<tr class="d-flex clickable-row" style="cursor: pointer">
<td class="col-10"><strong>class1.measurement</strong>
<span class="text-monospace" style="color:darkgreen;">(0x000a 10)</span></td>
</tr>
<tr class="d-flex clickable-row" style="cursor: pointer">
<td class="col-10"><strong>class1.control</strong>
<span class="text-monospace" style="color:darkgreen;">(0x001e 30)</span></td>
</tr>
</tbody>
</table>
</div>
<div class="col-2">
<button id="btnAddAllowEvent" type="button" class="btn btn-sm btn-warning rounded">
<strong>Search class</strong></button>
</div>
</div>
<div class="row">
<div class="col-10">
<table id="table-filter"
class="table scroll filter table-sm table-responsive table-hover table-striped table-hover "
id="table-filter">
<thead class="thead-light">
<tr class="d-flex">
<th class="col-12 ctext">VSCP types for selected class</th>
</tr>
</thead>
<tbody class="vscptype">
<tr class="d-flex clickable-row" style="cursor: pointer">
<td class="col-10"><strong>All types</strong></td>
</tr>
<tr class="d-flex clickable-row" style="cursor: pointer">
<td class="col-10"><strong>Temperature</strong>
<span class="text-monospace" style="color:darkgreen;">(0x0006 6)</span></td>
</tr>
</tbody>
</table>
</div>
<div class="col-2">
<button id="btnAddFilterEvent" type="button" class="btn btn-sm btn-warning rounded">
<strong>Search type</strong></button>
</div>
</div>
<div class="row">
<div class="col-sm-12 text-center">
<div>
<hr />
</div>
<div class="row">
<div class="col-sm-12" text-center">
<button id="btnCancel" class="btn-sm btn-default">Cancel</button>
<button id="btnSubmit" type="submit" class="btn-sm btn-default">OK</button>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap Optional JavaScript -->
<!-- jQuery first, then popper.js, then Bootstrap JS -->
<script>let $ = jQuery = require('./node_modules/jquery/dist/jquery.min.js');</script>
<script>require('./node_modules/@popperjs/core/dist/cjs/popper.js');</script>
<script>require('./node_modules/bootstrap/dist/js/bootstrap.min.js');</script>
</body>
<script>
const { remote, ipcRenderer } = require('electron');
const { app, dialog } = remote;
const win = remote.getCurrentWindow();
const vscp = require('node-vscp'); // TODO: use module
const vscp_tcp_Client = require('./src/vscptcp'); // TODO: use module
let guid = '';
let testProgress = '';
let vscpif = [];
///////////////////////////////////////////////////////////////////////////
// getInterfaces
//
const getInterfaces = async (options) => {
// Defaults
let remoteHost = '';
let remotePort = 9598;
let user = '';
let password = '';
if ('undefined' === typeof options) {
throw new Error("options is not defined.");
}
if ('string' !== typeof options.host) {
throw new Error("options.host is not defined.");
}
if (-1 == options.host.search(':')) {
// No port given - use default
remoteHost = options.host;
}
else {
let sep = options.host.split(':');
remoteHost = sep[0];
if (sep.length > 1) remotePort = parseInt(sep[1], 10);
}
if ('string' === typeof options.username) {
user = options.username;
}
if ('string' === typeof options.password) {
password = options.password;
}
let response = {};
let vscp_tcp_client = new vscp_tcp_Client();
response = await vscp_tcp_client.connect(
{
host: remoteHost,
port: remotePort,
timeout: 10000,
onSuccess: null
});
console.log(response);
if ('success' === response.result) {
testProgress = "connection OK\n";
}
if (user.length) {
response = await vscp_tcp_client.user({ username: user });
console.log(response);
if ('success' === response.result) {
testProgress += "user OK\n";
}
}
if (password.length) {
response = await vscp_tcp_client.password({ password: password });
console.log(response);
if ('success' === response.result) {
testProgress += "pass OK\n";
}
}
vscpif = response = await vscp_tcp_client.getInterfaces();
console.log(response);
if ('success' === response.result) {
testProgress += "interface OK\n";
}
response = await vscp_tcp_client.disconnect();
console.log(response);
if ('success' === response.result) {
testProgress += "disconnect OK\n"
}
$("#btnTestConnection").removeClass('connerr').addClass('active ');
console.log(testProgress);
}
///////////////////////////////////////////////////////////////////////////
// addInterfaceRow
//
var addInterfaceRow = function (name, guid, type) {
let tblInterface = document.getElementById("interface-table-id");
let tableRef = tblInterface.getElementsByTagName('tbody')[0];
let row = tableRef.insertRow(-1);
row.classList.add("clickable-row");
row.style.cursor = "pointer";
// Name
let cellName = row.insertCell(0);
cellName.innerHTML = name;
cellName.style.width = "40%";
// GUID
let cellGuid = row.insertCell(1);
cellGuid.innerHTML = guid;
cellGuid.style.width = "40%";
// Type
let cellType = row.insertCell(2);
cellType.innerHTML = type;
cellType.classList.add("ctext");
cellType.style.width = "20%";
adjustListHeader();
}
function adjustListHeader() {
document.getElementById('id-head-name').style.width = "5000px";
document.getElementById('id-head-guid').style.width = "40%";
document.getElementById('id-head-type').style.width = "20%";
}
///////////////////////////////////////////////////////////////////////////
// Document ready
//
$(document).ready(function ($) {
var options = ipcRenderer.sendSync("dialog-open", "");
var params = JSON.parse(options);
console.log(params);
$("#hostname").html("<kbd>Host:</kbd> " + params.host);
///////////////////////////////////////////////////////////////////////////
// Cancel
//
$("#btnCancel").on('click', function (e) {
ipcRenderer.send("dialog-close", '');
remote.getCurrentWindow().close();
});
///////////////////////////////////////////////////////////////////////////
// Save selected interface
//
$("#btnSubmit").on('click', function (e) {
//e.preventDefault();
console.log('submit')
ipcRenderer.send("dialog-close", guid);
remote.getCurrentWindow().close();
});
// Select table row
$('#interface-table-id').on('click', '.clickable-row', function (event) {
$(this).addClass('bg-info').siblings().removeClass('bg-info');
guid = event.currentTarget.cells[1].innerHTML;
});
// double click table row
$('#interface-table-id').on('dblclick', '.clickable-row', function (event) {
guid = event.currentTarget.cells[1].innerHTML;
$(this).addClass('bg-info').siblings().removeClass('bg-info');
ipcRenderer.send("dialog-close", guid);
remote.getCurrentWindow().close();
});
///////////////////////////////////////////////////////////////////////////////
// getInterfaces
//
getInterfaces({
host: params.host,
username: params.username,
password: params.password
})
.then(res => {
console.log(vscpif);
vscpif.forEach((item) => {
addInterfaceRow(item.name, item.guid, item.type);
});
})
.catch(err => {
let options = {
type: 'error',
buttons: ['OK'],
title: 'Interface failure',
message: 'Failed to get interfaces from remote host/device',
detail: 'Error: ' + err.message + ' \n' + testProgress
}
dialog.showMessageBox(remote.getCurrentWindow(), options);
console.log("Failed to get interfaces");
console.log(err);
$(this).removeClass('active').addClass('connerr ');
$("#errorHost").addClass("d-block");
$("#errorHost").html(err.message);
});
});
</script>
</html>