-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathportal.htm
154 lines (129 loc) · 4.36 KB
/
portal.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>HomeDing Portal</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>
ul.devices>hr {
border: 0
}
ul.devices>li {
margin-bottom: 0.3em;
}
</style>
</head>
<body class="sitelayout" style="max-width:100%;--layout-gap: 0;--content-back:none">
<header>
<h1>HomeDing Portal</h1>
</header>
<div class="navbar">
<svg class="button" id="menuButton" tabindex=0>
<use href="./icons.svg#menu" />
</svg>
<a href="#/board.htm">HomePortal</a>
<span class="gap"></span>
<a href="#/monitor.htm">Monitor</a>
<svg class="button" id="reload" tabindex=0>
<use href="./icons.svg#reload" />
</svg>
</div>
<nav>
<ul id="devices" style="padding-inline-start: 1rem;list-style-type: none;">
</ul>
</nav>
<main style="min-height:800px">
<iframe id="content" name="content" style="width: 100%;height:100%;border:0" src="about:blank"></iframe>
</main>
</div>
<script>
const param = {
SCREEN_TIMEOUT: 4 * 60 * 1000,
MENU_MIN_WIDTH: 1030
};
var iframeObj = document.querySelector('iframe#content');
var timerRef = 0;
// handle nav menu
var devList = [];
// when the user is not using the application for SCREEN_TIMEOUT milliseconds
// the portal will go to idle mode.
// call resetTimeout when user activity is detected.
function resetTimeout() {
if (timerRef) window.clearTimeout(timerRef);
timerRef = window.setTimeout(() => {
iframeObj.src = 'portalidle.htm';
window.location.hash = '';
}, param.SCREEN_TIMEOUT);
}
function setupMenu() {
var mbObj = document.querySelector('#menuButton');
var navObj = document.querySelector('nav');
navObj.classList.remove('open');
navObj.addEventListener('click', function(e) {
navObj.classList.remove('open');
resetTimeout();
});
mbObj.addEventListener('click', function(e) {
navObj.classList.toggle('open');
resetTimeout();
});
} // setupMenu()
function loadDevices() {
fetch('/api/discovery')
.then(function(result) {
return result.json();
})
.then(function(data) {
devList = data;
var devObj = document.querySelector('#devices')
for (d in data) {
var devData = data[d];
var o = createHTMLElement(devObj, 'li');
createHTMLElement(o, 'a', { href: '#' + d + devData.path }).innerText = devData.title || d;
}
window.setTimeout(startContent, 10);
});
} // loadDevices()
// display to content in iframe, specified by url-hash
function startContent() {
var h = String(window.location.hash);
if (h) {
h = h.substring(1);
if (h.startsWith('/')) {
// "/monitor.htm"
// show html from the portal app
iframeObj.src = h;
} else {
// "#nodeding/board.htm"
// show html from a device
iframeObj.src = 'http://' + h;
} // if
} // if
resetTimeout();
} // startContent()
window.addEventListener('hashchange', startContent);
window.addEventListener('load', () => {
setupMenu();
loadDevices();
if (!window.location.hash) {
window.location.hash = "#/board.htm";
}
});
document.querySelector('#reload').addEventListener('click', function() {
window.location.reload(true);
resetTimeout();
});
</script>
</body>
</html>