correct some js errors in example

This commit is contained in:
andreas 2024-11-14 18:33:18 +01:00
parent 538f643fbf
commit c292b82635
1 changed files with 83 additions and 90 deletions

View File

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