Skip to content

Commit

Permalink
Merge remote-tracking branch 'ewowi/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoudwijma committed Jul 23, 2024
2 parents 2cd0bac + 7786bbf commit d5a6d30
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 549 deletions.
79 changes: 61 additions & 18 deletions data/newui.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,36 @@ function cE(e, id = null, classs = null, inner = null) {
return node;
}

//by @aaroneous
class NewApp {

init() {
// Update the copyright notice in the footer
// Fetch data from the server
this.#fetchData() //async
}

async #fetchData() {
// Mock fetch for testing while using Live Server. No error checking for brevity.
// Replace with call to server websocket
this.#modules = await (await fetch('../misc/model.json')).json()
// this.#modules = await (await fetch('model.json')).json()

// Print out the response for debugging
console.log(this.#modules)
// console.log(JSON.stringify(this.#modules, null, 2))

for (let module of this.#modules) {
addModule(module)
}

}

#modules = []

}

//by ewowi
class NavBar {

//create navbar, menu, nav-list
Expand Down Expand Up @@ -126,7 +156,14 @@ function onLoad() {
gId("screenSize").innerText = window.innerWidth + "x" + window.innerHeight;
};

makeWS();
//aaroneous: run this code if Live Server is invoked
if (window.location.href.includes("127.0.0.1")) {
//is window.app predefined?
window.app = new NewApp()
window.app.init();
}
else
makeWS();

d.addEventListener('visibilitychange', function () {
console.log("handleVisibilityChange");
Expand All @@ -135,6 +172,28 @@ function onLoad() {

}

//used by NewApp and by makeWS
function addModule(module) {
// let module = json;
model.push((module)); //this is the model
console.log("WS receive module", module);

//create dropdownItem for module.id (level 2) under module.type (level 1 - module.type will be created if not exists)
navBar.addDropdownItem(module.type, module.id, function(event) {
console.log("DropdownItem click", event.target.innerText);
for (let module of model) {
if (module.id == event.target.innerText) {
gId("modName").innerText = module.id;
gId("modelJson").innerHTML = JSON.stringify(module, null, 2); //pretty
}
}
});

gId("vApp").innerText = appName(); //tbd: should be set by server
gId("screenSize").innerText = window.innerWidth + "x" + window.innerHeight;

}

function makeWS() {
if (ws) return;
let url = (window.location.protocol == "https:"?"wss":"ws")+'://'+window.location.hostname+'/ws';
Expand Down Expand Up @@ -173,23 +232,7 @@ function makeWS() {
found = true;
}
if (!found) {
let module = json;
model.push((module)); //this is the model
console.log("WS receive module", module);

//create dropdownItem for module.id (level 2) under module.type (level 1 - module.type will be created if not exists)
navBar.addDropdownItem(module.type, module.id, function(event) {
console.log("DropdownItem click", event.target.innerText);
for (let module of model) {
if (module.id == event.target.innerText) {
gId("modName").innerText = module.id;
gId("modelJson").innerHTML = JSON.stringify(module, null, 2); //pretty
}
}
});

gId("vApp").innerText = appName(); //tbd: should be set by server
gId("screenSize").innerText = window.innerWidth + "x" + window.innerHeight;
addModule(json);
}
else
console.log("html of module already generated", json);
Expand Down
Loading

0 comments on commit d5a6d30

Please sign in to comment.