add listeners for status handling
This commit is contained in:
parent
f73390c9ae
commit
048a16d939
54
web/index.js
54
web/index.js
|
@ -76,18 +76,19 @@
|
||||||
}
|
}
|
||||||
getJson('/api/status')
|
getJson('/api/status')
|
||||||
.then(function (jsonData) {
|
.then(function (jsonData) {
|
||||||
|
if (jsonData.salt !== undefined) {
|
||||||
|
lastSalt=jsonData.salt;
|
||||||
|
delete jsonData.salt;
|
||||||
|
}
|
||||||
|
if (jsonData.minUser !== undefined){
|
||||||
|
minUser=jsonData.minUser;
|
||||||
|
delete jsonData.minUser;
|
||||||
|
}
|
||||||
|
callListeners(api.EVENTS.status,jsonData);
|
||||||
let statusPage = document.getElementById('statusPageContent');
|
let statusPage = document.getElementById('statusPageContent');
|
||||||
let even = true; //first counter
|
let even = true; //first counter
|
||||||
|
if (statusPage){
|
||||||
for (let k in jsonData) {
|
for (let k in jsonData) {
|
||||||
if (k == "salt") {
|
|
||||||
lastSalt = jsonData[k];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (k == "minUser") {
|
|
||||||
minUser = parseInt(jsonData[k]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!statusPage) continue;
|
|
||||||
if (typeof (jsonData[k]) === 'object') {
|
if (typeof (jsonData[k]) === 'object') {
|
||||||
if (k.indexOf('count') == 0) {
|
if (k.indexOf('count') == 0) {
|
||||||
createCounterDisplay(statusPage, k.replace("count", "").replace(/in$/, " in").replace(/out$/, " out"), k, even);
|
createCounterDisplay(statusPage, k.replace("count", "").replace(/in$/, " in").replace(/out$/, " out"), k, even);
|
||||||
|
@ -118,6 +119,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
lastUpdate = (new Date()).getTime();
|
lastUpdate = (new Date()).getTime();
|
||||||
if (reloadConfig) {
|
if (reloadConfig) {
|
||||||
reloadConfig = false;
|
reloadConfig = false;
|
||||||
|
@ -382,6 +384,7 @@
|
||||||
icon.classList.add('icon-less');
|
icon.classList.add('icon-less');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
callListeners(api.EVENTS.counterDisplayCreated,row);
|
||||||
}
|
}
|
||||||
function validKey(key) {
|
function validKey(key) {
|
||||||
if (!key) return;
|
if (!key) return;
|
||||||
|
@ -1996,8 +1999,16 @@
|
||||||
hideDashboardItem(name); //will recreate it on next data receive
|
hideDashboardItem(name); //will recreate it on next data receive
|
||||||
}
|
}
|
||||||
const api= {
|
const api= {
|
||||||
registerListener: function (callback) {
|
registerListener: function (callback,opt_event) {
|
||||||
|
if (opt_event === undefined){
|
||||||
listeners.push(callback);
|
listeners.push(callback);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
listeners.push({
|
||||||
|
event:opt_event,
|
||||||
|
callback:callback
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* helper for creating dom elements
|
* helper for creating dom elements
|
||||||
|
@ -2058,11 +2069,13 @@
|
||||||
parseBoatDataLine: parseBoatDataLine,
|
parseBoatDataLine: parseBoatDataLine,
|
||||||
EVENTS: {
|
EVENTS: {
|
||||||
init: 0, //called when capabilities are loaded, data is capabilities
|
init: 0, //called when capabilities are loaded, data is capabilities
|
||||||
tab: 1, //tab page activated data is the id of the tab page
|
tab: 1, //tab page activated, data is the id of the tab page
|
||||||
config: 2, //data is the config object
|
config: 2, //called when the config data is loaded,data is the config object
|
||||||
boatData: 3, //data is the list of boat Data items
|
boatData: 3, //called when boatData is received, data is the list of boat Data items
|
||||||
dataItemCreated: 4, //data is an object with
|
dataItemCreated: 4, //data is an object with
|
||||||
// name: the item name, element: the frame item of the boat data display
|
// name: the item name, element: the frame item of the boat data display
|
||||||
|
status: 5, //status received, data is the status object
|
||||||
|
counterDisplayCreated: 6 //data is the row for the display
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function callListeners(event,data){
|
function callListeners(event,data){
|
||||||
|
@ -2070,6 +2083,13 @@
|
||||||
if (typeof(listener) === 'function'){
|
if (typeof(listener) === 'function'){
|
||||||
listener(event,data);
|
listener(event,data);
|
||||||
}
|
}
|
||||||
|
else if (typeof(listener) === 'object'){
|
||||||
|
if (listener.event === event){
|
||||||
|
if (typeof(listener.callback) === 'function'){
|
||||||
|
listener.callback(event,data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
window.esp32nmea2k = api;
|
window.esp32nmea2k = api;
|
||||||
|
@ -2120,14 +2140,6 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
let statusPage = document.getElementById('statusPageContent');
|
|
||||||
/*if (statusPage){
|
|
||||||
let even=true;
|
|
||||||
for (let c in counters){
|
|
||||||
createCounterDisplay(statusPage,counters[c],c,even);
|
|
||||||
even=!even;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
forEl('#uploadFile', function (el) {
|
forEl('#uploadFile', function (el) {
|
||||||
el.addEventListener('change', function (ev) {
|
el.addEventListener('change', function (ev) {
|
||||||
if (ev.target.files.length < 1) return;
|
if (ev.target.files.length < 1) return;
|
||||||
|
|
Loading…
Reference in New Issue