Skip to content

Commit

Permalink
Use the new HousePortal common event client code
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fb-martin committed Jan 18, 2022
1 parent 2448301 commit 4ff8aaf
Showing 1 changed file with 2 additions and 82 deletions.
84 changes: 2 additions & 82 deletions public/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,10 @@
<html>
<head>
<link rel=stylesheet type="text/css" href="/house.css" title="House">
<script src="/events.js"></script>
<script>
function wizShowStatus (response) {
document.getElementById('portal').href = 'http://'+response.proxy+'/index.html';
}

function wizStatus () {
var command = new XMLHttpRequest();
command.open("GET", "/wiz/status");
command.onreadystatechange = function () {
if (command.readyState === 4 && command.status === 200) {
wizShowStatus (JSON.parse(command.responseText));
}
}
command.send(null);
}
window.onload = function() {

function newColumn (text) {
var column = document.createElement("td");
column.innerHTML = text;
return column;
}

var lastEventId = null;

function showEvents (response) {

if (!lastEventId) {
var title = response.host + ' - Wiz Devices';
document.getElementsByTagName ('title')[0].innerHTML = title;
var elements = document.getElementsByClassName ('hostname');
for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = response.host;
}
}

lastEventId = response.wiz.latest;

var table = document.getElementsByClassName ('eventlist')[0];
for (var i = table.childNodes.length - 1; i > 1; i--) {
table.removeChild(table.childNodes[i]);
}
for (var i = response.wiz.events.length-1; i >= 0; --i) {
var event = response.wiz.events[i];
var timestamp = new Date(event[0]);
var row = document.createElement("tr");
row.appendChild(newColumn(timestamp.toLocaleString()));
row.appendChild(newColumn(event[1]));
row.appendChild(newColumn(event[2]));
row.appendChild(newColumn(event[3]));
row.appendChild(newColumn(event[4]));
table.appendChild(row);
}
}

function updateEvents() {

var command = new XMLHttpRequest();
command.open("GET", "/wiz/log/events");
command.onreadystatechange = function () {
if (command.readyState === 4 && command.status === 200) {
showEvents (JSON.parse(command.responseText));
}
}
command.send(null);
}

function checkEvents () {

var command = new XMLHttpRequest();
command.open("GET", "/wiz/log/latest");
command.onreadystatechange = function () {
if (command.readyState === 4 && command.status === 200) {
var response = JSON.parse(command.responseText);
if ((lastEventId == null) ||
(response.wiz.latest != lastEventId)) updateEvents ();
}
}
command.send(null);
}

updateEvents();
setInterval (function() {checkEvents()}, 1000);
wizStatus();
eventStart('/wiz');
}
</script>
<head>
Expand Down

0 comments on commit 4ff8aaf

Please sign in to comment.