-
Notifications
You must be signed in to change notification settings - Fork 8
/
construct.html
65 lines (60 loc) · 2.19 KB
/
construct.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
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<script src="js/jquery.min.js"></script>
<script>
const electron = require('electron')
const ipc = require('electron').ipcRenderer
ipc.on('build', function(event, json) {
document.body.appendChild(buildHtmlTable(json));
})
ipc.on('clear', function(event) {
build_clear()
})
var _table_ = document.createElement('table'),
_tr_ = document.createElement('tr'),
_th_ = document.createElement('th'),
_td_ = document.createElement('td');
// Builds the HTML Table out of myList json data from Ivy restful service.
function buildHtmlTable(json) {
var table = _table_.cloneNode(false),
columns = addAllColumnHeaders(json, table);
for (var i=0, maxi=json.length; i < maxi; ++i) {
var tr = _tr_.cloneNode(false);
for (var j=0, maxj=columns.length; j < maxj ; ++j) {
var td = _td_.cloneNode(false);
cellValue = json[i][columns[j]];
td.appendChild(document.createTextNode(json[i][columns[j]] || ''));
tr.appendChild(td);
}
table.appendChild(tr);
}
return table;
}
function addAllColumnHeaders(json, table)
{
var columnSet = [],
tr = _tr_.cloneNode(false);
for (var i=0, l=json.length; i < l; i++) {
for (var key in json[i]) {
if (json[i].hasOwnProperty(key) && columnSet.indexOf(key)===-1) {
columnSet.push(key);
var th = _th_.cloneNode(false);
th.appendChild(document.createTextNode(key));
tr.appendChild(th);
}
}
}
table.appendChild(tr);
return columnSet;
}
</script>
<script src="js/build.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>