config: show loaded values on page

This commit is contained in:
Daniel 2023-01-15 16:36:09 +01:00
parent 988a823b4e
commit 1baead7804
5 changed files with 25 additions and 13 deletions

View File

@ -6,8 +6,8 @@ This will be a dashboard hosted on my homeserver with self-hosted stuff. But, fo
#### Still to do before prod: #### Still to do before prod:
- [ ] External config loaded with XHR (app list) - [x] External config loaded with XHR (app list)
- [ ] Apply config for the rest stuff (data shown in More page, default user settings) - [x] Apply config for the rest stuff (data shown in More page, default user settings)
- [ ] Make 'Security' module functional - [ ] Make 'Security' module functional
- [ ] Security screen on/off - [ ] Security screen on/off
- [ ] CSS global color variables for easier theming - [ ] CSS global color variables for easier theming

View File

@ -4,7 +4,7 @@
"desc": "Nice and sweet place for all your self-hosted services.", "desc": "Nice and sweet place for all your self-hosted services.",
"icon": "img/icon.png", "icon": "img/icon.png",
"wallpaper": "img/background.jpg", "wallpaper": "img/background.jpg",
"wallpaper_dark": "img/background_dark.jpg", "wallpaper_dark": "img/background-dark.jpg",
"dark_mode": false, "dark_mode": false,
"open_new_tab": false, "open_new_tab": false,
"hosted_by": "somebody", "hosted_by": "somebody",

View File

@ -19,9 +19,9 @@
<div class="page home hidden" id="page-home"> <div class="page home hidden" id="page-home">
<div class="wrapper"> <div class="wrapper">
<div class="home"> <div class="home">
<img src="img/icon.png" class="appicon"> <img class="appicon" id="app-icon">
<div class="appname">honey</div> <div class="appname" id="app-name"></div>
<div class="appdesc">Nice and sweet place for all your self-hosted services.</div> <div class="appdesc" id="app-desc"></div>
</div> </div>
<div class="buttons"> <div class="buttons">
<div onclick="switch_theme()"> <div onclick="switch_theme()">
@ -73,9 +73,7 @@
<div class="text">6 out of 7 listed services use secure connections</div> <div class="text">6 out of 7 listed services use secure connections</div>
</div> </div>
</div> </div>
<div class="hostedby"> <div class="hostedby">All services hosted by <b id="app-hostedby"></b></div>
<div>All services hosted by <b>nobody</b></div>
</div>
<div class="boxes static"> <div class="boxes static">
<div class="box"> <div class="box">
<div class="icon" style="--color: 144deg">lock</div> <div class="icon" style="--color: 144deg">lock</div>

View File

@ -2,6 +2,10 @@ function get(id) {
return document.getElementById(id); return document.getElementById(id);
} }
function set(id, text) {
get(id).innerText = text;
}
function get_class(class_name, parent) { function get_class(class_name, parent) {
if (!parent) parent = document; if (!parent) parent = document;
return parent.getElementsByClassName(class_name); return parent.getElementsByClassName(class_name);
@ -55,4 +59,15 @@ function config(key, value) {
function get_bool(key) { function get_bool(key) {
return config(key) == "true"; return config(key) == "true";
}
function load_config(conf) {
CONFIG = JSON.parse(conf);
let ui = CONFIG.ui;
set("app-name", ui.name);
set("app-desc", ui.desc);
get("app-icon").src = ui.icon;
if (ui.hosted_by) set("app-hostedby", ui.hosted_by);
else get("app-hostedby").parentNode.style.display = "none";
load_apps();
} }

View File

@ -2,12 +2,11 @@ function onload() {
let xhr = new XMLHttpRequest(); let xhr = new XMLHttpRequest();
xhr.open("GET", "config/config.json"); xhr.open("GET", "config/config.json");
xhr.onload = function() { xhr.onload = function() {
CONFIG = JSON.parse(this.responseText); load_config(this.responseText);
for_all("back", (btn) => { for_all("back", (btn) => {
btn.onclick = show; btn.onclick = show;
}); });
switch_theme(config("dark_mode") == "true"); switch_theme(config("dark_mode") == "true");
load_apps();
setTimeout(() => { setTimeout(() => {
show(); show();
document.body.classList.remove("init"); document.body.classList.remove("init");
@ -41,13 +40,13 @@ function switch_theme(value) {
setting.classList.add("checked"); setting.classList.add("checked");
icon.innerText = "dark_mode"; icon.innerText = "dark_mode";
bg.add("dark"); bg.add("dark");
get_background().src = "img/background-dark.jpg"; get_background().src = CONFIG.ui.wallpaper_dark;
} }
else { else {
setting.classList.remove("checked"); setting.classList.remove("checked");
icon.innerText = "light_mode"; icon.innerText = "light_mode";
bg.remove("dark"); bg.remove("dark");
get_background().src = "img/background.jpg"; get_background().src = CONFIG.ui.wallpaper;
} }
} }