Skip to content

Commit

Permalink
Structure in classes and files, add theme (WIP)
Browse files Browse the repository at this point in the history
NewUI

MainNav:
- rename addBody to addHTML
- rename activeModule to activeModuleJson
- rename module to moduleJson
- use controller.model and controller.mainNav

module.css: add label comment and input (WIP)
module.js: add moduleFun (to do create class)

newui.htm:
- add theme.js/css and module.js/css
- body onLoad = controller.onLoad

newui.js
- create Controller class and add all stuff in it
- add themeClass
- fetchModelForLiveServer: sort modules
- addModule do push to module
- addModule: moduleFun as parameter to updateUI
- window.controller = new Controller()

theme.js/css
- new
- css: WIP
- js: add ThemeClass: create html (WIP), setTheme, getTheme

Old UI:
- index.css: remove theme items and move to themes.css (reused old and new)
- index.htm: add theme.css
- index.js: rename module to moduleJson
  • Loading branch information
ewoudwijma committed Jul 31, 2024
1 parent 5e79219 commit 864477f
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 223 deletions.
87 changes: 0 additions & 87 deletions data/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,93 +9,6 @@
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/

:root,
:root.starbase {
--bg-color: #121212;
--text-color: #cfd096;
--th-color: #c27e66;
--h-color:#c27e66;
--border-color: #cdad6a;
--select-color: #1a8aff; /*used for view buttons*/
--label-color: #83c5eb;
--comment-color: #598a43;
--font-size: 10px;
}
:root.starlight {
--bg-color: linear-gradient(to bottom, #ffbe33 0%, #b60f62 100%);
--text-color: #030303;
--th-color: #b60f6281;
--h-color: #b60f62;
--border-color: #666;
--select-color: #FFFFFF; /*used for view buttons*/
--font-size: 10px;
}
:root.wled {
--bg-color: #121212;
--text-color: #fff;
--th-color: rgb(255, 160, 0);
--h-color: rgb(255, 160, 0);
--border-color: rgb(255, 160, 0);
--select-color: rgb(255, 160, 0);
--font-size: 10px;
}
:root.grayeen {
--bg-color: linear-gradient(to bottom, #979294 0%, #474542 100%);
--text-color: #fbf4f4;
--th-color: #21482b;
--h-color: #21482b;
--border-color: #21482b;
--select-color: #21482b; /*used for view buttons*/
--font-size: 10px;
--font-size-s: 8px; /*var(--font-size-s) not working for some reason */
}
:root.dev {
--bg-color: #121212;
--text-color: #cfd096;
--th-color: #c27e66;
--h-color:#c27e66;
--border-color: #cdad6a;
--select-color: #1a8aff; /*used for view buttons*/
--label-color: #83c5eb;
--comment-color: #598a43;
--font-size: 10px;
}
:root.light {
--bg-color: #fff;
--text-color: #123;
--h-color: #000000;
--th-color: #6d686a81;
--select-color: #6d686a81;
}
:root.dark {
--bg-color: #121212;
--text-color: #696d7d;
}
:root.blue {
--bg-color: #05396B;
--text-color: #E7F1FE;
--th-color: #b60f6281;
--h-color: #b60f62;
--select-color: #b60f6281;
}
:root.pink {
--bg-color: #ffcad4;
--text-color: #e75480;
--select-color: #e75480; /*used for view buttons*/
}
:root.space {
--bg-color: #000;
--text-color: #f2bd16;
--bg-url: url(//space);
--font-family: 'Press Start 2P', cursive;
}
:root.nyan {
--bg-color: #013367;
--text-color: #fff;
--bg-url: url(//nyan);
--font-family: 'Comic Neue', cursive;
}

/* inspired by WLED / MoonModules - temporary */
:root {
--c-1: #111;
Expand Down
1 change: 1 addition & 0 deletions data/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<!-- <link rel="mask-icon" type="image/x-icon" href="favicon-16x16.png"> for safari tabs? -->
<!-- <link rel="shortcut icon" href="https://ewowi.github.io/StarDocs/assets/images/ui/StarBase/favicon-16x16.png"> -->
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="theme.css">
<script src="app.js"></script>
<script src="index.js"></script>

Expand Down
26 changes: 13 additions & 13 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async function fetchModel() {
// Replace with call to server websocket
model = await (await fetch('../misc/model.json')).json()

for (let module of model) {
addModule(module)
for (let moduleJson of model) {
addModule(moduleJson)
}
}

Expand Down Expand Up @@ -94,18 +94,18 @@ function ppf() {
}

//used by fetchModel and by makeWS
function addModule(module) {
function addModule(moduleJson) {
// let module = json;
console.log("WS receive createHTML", module);
ppf("WS receive createHTML", module.id);
createHTML(module); //no parentNode

if (module.id == "System") {
console.log("system changes", module);
if (module.view)
savedView = module.view;
if (module.theme)
changeHTMLTheme(module.theme);
console.log("WS receive createHTML", moduleJson);
ppf("WS receive createHTML", moduleJson.id);
createHTML(moduleJson); //no parentNode

if (moduleJson.id == "System") {
console.log("system changes", moduleJson);
if (moduleJson.view)
savedView = moduleJson.view;
if (moduleJson.theme)
changeHTMLTheme(moduleJson.theme);
}

//rerun after each module added
Expand Down
49 changes: 25 additions & 24 deletions data/mainnav.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @title StarBase
// @file newui.css
// @file mainnav.js
// @date 20240720
// @repo https://github.com/ewowi/StarBase, submit changes to this file as PRs to ewowi/StarBase
// @Authors https://github.com/ewowi/StarBase/commits/main
Expand All @@ -13,7 +13,7 @@
*/
class MainNav {

addBody() {
addHTML() {
let body = document.getElementById("body");//gId("body");

body.classList += "d-flex flex-column";
Expand Down Expand Up @@ -78,27 +78,27 @@ class MainNav {
* Set the active module
* @param {object} module - A module
*/
set activeModule(module) {
if (!module) return
set activeModuleJson(moduleJson) {
if (!moduleJson) return

this.#activeModule = module
this.#activeModuleJson = moduleJson

// Update the main navigation
document.querySelectorAll('#main-nav .menu-item').forEach(menuItem => {
if (menuItem.dataset.type == this.#activeModule.type) {
if (menuItem.dataset.type == this.#activeModuleJson.type) {
menuItem.classList.add('selected')
} else {
menuItem.classList.remove('selected')
}
})

// Update the secondary navigation menu
const modules = model.filter(module => module.type == this.#activeModule.type)
const modules = controller.model.filter(moduleJson => moduleJson.type == this.#activeModuleJson.type)

const html = modules
.map(module => {
const selected = module.id == this.#activeModule.id ? 'selected' : ''
return `<div onclick="mainNav.activeModuleId=this.dataset.id" class="menu-item selectable ${selected} text-truncate pa-3" data-id="${module.id}">${module.id}</div>`
.map(moduleJson => {
const selected = moduleJson.id == this.#activeModuleJson.id ? 'selected' : ''
return `<div onclick="controller.mainNav.activeModuleId=this.dataset.id" class="menu-item selectable ${selected} text-truncate pa-3" data-id="${moduleJson.id}">${moduleJson.id}</div>`
})
.join('')
document.getElementById('second-nav').innerHTML = html
Expand All @@ -109,62 +109,63 @@ class MainNav {
document.getElementById('page').innerHTML =
`<div class="d-flex flex-column h-100 overflow-hidden">
<div class="flex-shrink-0">
<h1 class="title">${this.#activeModule.id}</h1>
<h1 class="title">${this.#activeModuleJson.id}</h1>
</div>
<div class="overflow-y-auto">` + this.#moduleFun(this.#activeModule) +
<div class="overflow-y-auto">` + this.#moduleFun(this.#activeModuleJson) +
`</div>
</div>`
}
}
} //set activeModuleJson(moduleJson)

/**
* Set the active module to the first one in the module list whose type matches
* @param {string} moduleType - The module type
*/
set activeModuleType(moduleType) {
this.activeModule = model.find(module => module.type == moduleType)
this.activeModuleJson = controller.model.find(moduleJson => moduleJson.type == moduleType)
}

/**
* Set the active module to the module specified by the id
* @param {string} id - The module id
*/
set activeModuleId(id) {
this.activeModule = model.find(module => module.id == id)
this.activeModuleJson = controller.model.find(moduleJson => moduleJson.id == id)
}

/**
* Update the UI
*/
//updateUI is made after all modules have been fetched, how to adapt to add one module?
updateUI(fun) {
updateUI(moduleJson, fun) {

this.#moduleFun = fun

// Get the unique list of module types
const uniqueTypes = model
.filter((module, index, modules) => {
return modules.findIndex(m => m.type === module.type) === index
const uniqueTypes = controller.model
.filter((moduleJson, index, modules) => {
return modules.findIndex(m => m.type === moduleJson.type) === index
})
.map(module => module.type)
.map(moduleJson => moduleJson.type)

// Each module type becomes a top level menu
const html = uniqueTypes
.map(type => {
return `<div onclick="mainNav.activeModuleType=this.dataset.type" class="menu-item selectable pa-4" data-type="${type}">${type}</div>`
return `<div onclick="controller.mainNav.activeModuleType=this.dataset.type" class="menu-item selectable pa-4" data-type="${type}">${type}</div>`
})
.join('')
document.getElementById('main-nav').innerHTML = html

// If there is no active module set it to the first one
if (this.#activeModule == '' && model.length) {
this.activeModule = model[0]
if (this.#activeModuleJson == '' && controller.model.length) {
this.activeModuleJson = controller.model[0]
}
}

/**
* Store the currently active module
*/
#activeModule = ''
#activeModuleJson = ''

//stores the function to execute to display one module
#moduleFun = null;
Expand Down
30 changes: 30 additions & 0 deletions data/module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
@title StarBase
@file module.css
@date 20240720
@repo https://github.com/ewowi/StarBase, submit changes to this file as PRs to ewowi/StarBase
@Authors https://github.com/ewowi/StarBase/commits/main
@Copyright © 2024 Github StarBase Commit Authors
@license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
@license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]
*/

/* default nodes */
label {
margin-right: 6px; /*space after*/
color: var(--label-color);
}

comment {
/* font-size: 10px; */
font-style: italic;
margin-left: 6px; /*space before*/
color: var(--comment-color);
}

input {
background: transparent;
color: var(--text-color);
font-size: 8px; /*var(--font-size-s) not working for some reason */
}

27 changes: 27 additions & 0 deletions data/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @title StarBase
// @file module.js
// @date 20240720
// @repo https://github.com/ewowi/StarBase, submit changes to this file as PRs to ewowi/StarBase
// @Authors https://github.com/ewowi/StarBase/commits/main
// @Copyright © 2024 Github StarBase Commit Authors
// @license GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007
// @license For non GPL-v3 usage, commercial licenses must be purchased. Contact [email protected]

function moduleFun(moduleJson) {
let code = "";
for (variable of moduleJson.n) {
// console.log(variable);
code += `<p>`
code += `<label>${variable.id}</label>`
switch (variable.type) {
case "progress":
code += `<progress max="${variable.max}" id="${variable.id}" class="progress"></progress>`
break
default:
code += `<input type=${variable.type} class="${variable.type}"></input>`
}
code += `<p>`
}
code += '<pre>' + JSON.stringify(moduleJson, null, 2) + '</pre>'
return code
}
8 changes: 6 additions & 2 deletions data/newui.htm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
<link rel="icon" href="https://ewowi.github.io/StarDocs/assets/images/ui/starbase/favicon-16x16.png">
<script src="app.js"></script>
<script src="newui.js"></script>
<link rel="stylesheet" href="mainnav.css">
<script src="theme.js"></script>
<link rel="stylesheet" href="theme.css">
<script src="mainnav.js"></script>
<link rel="stylesheet" href="mainnav.css">
<script src="module.js"></script>
<link rel="stylesheet" href="module.css">
</head>
<body id="body" onload="onLoad()"></body>
<body id="body" onload="controller.onLoad()"></body>
</html>
Loading

0 comments on commit 864477f

Please sign in to comment.