-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportalconfig.htm
190 lines (156 loc) · 5.08 KB
/
portalconfig.htm
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>HomeDing Portal Config</title>
<link rel="icon" type="image/png" href="/favicon48.png" sizes="48x48">
<meta name="application-name" content="Ding" />
<meta name="msapplication-config" content="/browserconfig.xml" />
<meta name="msapplication-TileColor" content="#2b5797" />
<meta name="msapplication-TileImage" content="/favicon144.png" />
<link rel="apple-touch-icon" sizes="180x180" href="/favicon180.png" />
<meta name="mobile-web-app-capable" content="yes" />
<link rel="manifest" href="/site.webmanifest" />
<meta name="theme-color" content="#ffffff" />
<link Content-Type="text/css" href="/iotstyle.css" rel="stylesheet" />
<script src="/micro.js"></script>
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
#ppage {
display: flex;
flex-direction: column;
height: 100%;
min-height: 100%;
}
#pbody {
flex: 1;
display: flex;
flex-direction: row;
background-color: silver;
}
main {
flex: 1;
}
ul>hr {
border: 0
}
ul>li {
margin-bottom: 0.3em;
}
#devices>h3 {
margin: 0.5rem 0;
}
#devices>div {
margin: 0.2rem 0 0.2rem 1rem;
}
.card {
height: 2rem;
margin-bottom: 0.2rem;
}
.card .block {
background-color: bisque;
vertical-align: top;
}
.card .block .icon {
height: 1.6rem;
width: 1.6rem;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row u-header">
<a href="/" title="Start-Page"><img class="icon" src="/favicon.svg" /></a>
<h1>Portal Config</h1>
</div>
<div class="row u-navbar">
<a class="button" href="/portal.htm">Portal</a>
</div>
<div class="row wrap">
<div class="col-6">
<p>Select the elements to be shown on the portal board:</p>
</div>
<div id="devices" class="col-6"></div>
</div>
</div>
<script>
var devicesObj = document.querySelector('#devices');
var devList = [];
var devData = {};
var uElements = {};
function createUseElement(parentNode, iconName) {
var svgObj = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svgObj.setAttribute('class', 'icon');
var useObj = document.createElementNS('http://www.w3.org/2000/svg', 'use');
useObj.setAttribute('href', 'icons.svg#' + iconName);
svgObj.appendChild(useObj);
parentNode.appendChild(svgObj);
return (svgObj);
}
// initiate a fetch with JSON response expected.
async function fetchJSON(url, options) {
var p = fetch(url, options)
.then(function (result) {
return (result.json());
});
return (p)
}
function startContent() {
if (devList.length > 0) {
var deviceName = devList.pop();
var deviceHeader = createHTMLElement(devicesObj, 'h3');
deviceHeader.innerText = devData[deviceName].title + ' (' + deviceName + ')';
var deviceRow = createHTMLElement(devicesObj, 'div', {class:'row wrap'});
fetch('/api/config/' + deviceName)
.then(function (result) {
return result.json();
})
.then(function (data) {
var url = 'http://' + devData[deviceName].host + '/api/state/';
for (t in data) {
for (i in data[t]) {
if ((uElements[t]) && (!uElements[t].sys)) {
var cnfElem = data[t][i];
var divObj = createHTMLElement(deviceRow, 'div', { class: 'col card small' });
var bObj = createHTMLElement(divObj, 'div', { class: 'block' });
createUseElement(bObj, t);
var cbObj = createHTMLElement(bObj, 'input', { type: 'checkbox', title: url + t + '/' + i });
var titleText = cnfElem.title || cnfElem.description || '';
createHTMLElement(bObj, 'span').innerText = '(' + t + '/' + i + ') ' + titleText;
}
}
}
// pre.innerText = JSON.stringify(data, null, 2);
window.setTimeout(startContent, 10);
});
// window.setTimeout(startContent, 10);
}
}
function loadDevices() {
var p2 = fetchJSON('/elements.json')
.then(function (json) {
uElements = json;
});
var p1 = fetch('/api/discovery')
.then(function (result) {
return result.json();
})
.then(function (data) {
devData = data;
devList = Object.keys(data);
});
Promise.allSettled([p1, p2]).then(function () {
window.setTimeout(startContent, 10);
});
} // loadDevices()
window.addEventListener('load', loadDevices);
</script>
</body>
</html>