correct some js errors in example
This commit is contained in:
parent
538f643fbf
commit
c292b82635
|
@ -5,23 +5,15 @@
|
|||
//on our case this is "testboard"
|
||||
//so we only start any action when we receive the init event
|
||||
//and we successfully checked that our requested capability is there
|
||||
let isActive=false;
|
||||
const tabName="example";
|
||||
const configName="exampleBDSel";
|
||||
const infoUrl='https://github.com/wellenvogel/esp32-nmea2000/tree/master/lib/exampletask';
|
||||
let boatItemName;
|
||||
let boatItemElement;
|
||||
api.registerListener((id, data) => {
|
||||
if (isActive){
|
||||
console.log("exampletask status listener",data);
|
||||
}
|
||||
},api.EVENTS.status)
|
||||
api.registerListener((id,data)=>{
|
||||
if (id === api.EVENTS.init){
|
||||
//data is capabilities
|
||||
//check if our requested capability is there (see GwExampleTask.h)
|
||||
if (data.testboard) isActive=true;
|
||||
if (isActive){
|
||||
if (!data.testboard) return; //do nothing if we are not active
|
||||
//add a simple additional tab page
|
||||
//you will have to build the content of the page dynamically
|
||||
//using normal dom manipulation methods
|
||||
|
@ -39,6 +31,7 @@
|
|||
return res.text();
|
||||
})
|
||||
.then((txt) => {
|
||||
//set the text content of our value element with what we received
|
||||
lcount.textContent = txt;
|
||||
})
|
||||
.catch((e) => console.log("rq:", e));
|
||||
|
@ -48,17 +41,18 @@
|
|||
})
|
||||
//add a tab for an external URL
|
||||
api.addTabPage('exhelp', 'Info', infoUrl);
|
||||
}
|
||||
}
|
||||
if (isActive){
|
||||
//console.log("exampletask listener",id,data);
|
||||
if (id === api.EVENTS.tab){
|
||||
//now as we know we are active - register all the listeners we need
|
||||
api.registerListener((id, data) => {
|
||||
console.log("exampletask status listener", data);
|
||||
}, api.EVENTS.status)
|
||||
api.registerListener((id, data) => {
|
||||
if (data === tabName) {
|
||||
//maybe we need some activity when our page is being activated
|
||||
console.log("example tab activated");
|
||||
}
|
||||
}
|
||||
if (id == api.EVENTS.config){
|
||||
}, api.EVENTS.tab);
|
||||
|
||||
api.registerListener((id, data) => {
|
||||
//we have a configuration that
|
||||
//gives us the name of a boat data item we would like to
|
||||
//handle special
|
||||
|
@ -85,8 +79,8 @@
|
|||
}
|
||||
boatItemName = nextboatItemName;
|
||||
boatItemElement = undefined;
|
||||
}
|
||||
if (id == api.EVENTS.dataItemCreated){
|
||||
}, api.EVENTS.config);
|
||||
api.registerListener((id, data) => {
|
||||
//this event is called whenever a data item has
|
||||
//been created (or recreated)
|
||||
//if this is the item we handle, we just add a css class
|
||||
|
@ -102,7 +96,6 @@
|
|||
el.classList.add("examplecss");
|
||||
}, boatItemElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}, api.EVENTS.dataItemCreated);
|
||||
}, api.EVENTS.init);
|
||||
})();
|
||||
|
|
Loading…
Reference in New Issue