summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarin Ivanov <[email protected]>2024-08-21 10:20:12 +0300
committerMarin Ivanov <[email protected]>2024-08-21 10:20:12 +0300
commita693f2cc0f734f5c084687a3fd6eab0daef17825 (patch)
tree9d9cc0e156eba0316f0eabba06aa27a8c4f9d1ec
parente259a1465e5417220e85dd7b6136d15135f4d95a (diff)
improvements
-rw-r--r--app.js35
-rw-r--r--build.py3
2 files changed, 23 insertions, 15 deletions
diff --git a/app.js b/app.js
index f335dba..3579ca6 100644
--- a/app.js
+++ b/app.js
@@ -1,23 +1,26 @@
(() => {
let state = {};
- let isLoading = 0;
- let loading = (val) => {
- isLoading = val;
- loader.$cls(isLoading ? "" : "hide");
+ let loading = 0;
+ let error = null;
+
+ let setLoading = (val) => {
+ loading = val;
+ loader.$cls(loading ? "" : "hide");
}
- loader.$click(() => loading(0));
+ loader.$click(() => setLoading(0));
- let error = null;
let setError = (err) => {
- error = String(err);
+ error = err&&String(err);
app.reload();
}
+
window.onerror = (message) => {
setError(message);
};
window.onunhandledrejection = (e) => {
setError(e.reason);
};
+
let parsetxt = (data) => fromEntries(data.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split("=")));
let buildtxt = (data) => entries(data).map(([k,v])=>`${k}=${v}\n`).join("");
let resptext = r => {
@@ -29,29 +32,30 @@
let getconfig = () => fetch("/cgi-bin/getconfig").then(resptext).then(x => parsetxt(x));
let cmd = (body) => fetch("/cgi-bin/cmd",{method:"POST",body}).then(resptext);
let setconfig = (data) => {
- loading(1);
+ setLoading(1);
cmd(buildtxt(data)+"save\n")
- .finally(() => loading(0))
+ .finally(() => setLoading(0))
};
let loadconfig = () => {
- loading(1);
- getconfig("/cgi-bin/getconfig")
+ setLoading(1);
+ setError();
+ getconfig()
.then(x => {
state = {...state, ...x};
app.reload();
})
- .finally(() => loading(0));
+ .finally(() => setLoading(0));
}
let reboot = (data) => {
let ok = 0;
- loading(1);
+ setLoading(1);
cmd("reboot\n")
.then(() => {
ok = 1;
})
.finally(() => {
setTimeout(() => {
- loading(0);
+ setLoading(0);
app.reload();
}, ok?10000:0);
})
@@ -144,8 +148,9 @@
p("The requested page is not available.")
),
});
+
let CApp = (h) => {
- loading(isLoading);
+ setLoading(loading);
return [
div(error && CErr(String(error))),
main(
diff --git a/build.py b/build.py
index 9c9531a..ea11922 100644
--- a/build.py
+++ b/build.py
@@ -8,6 +8,9 @@ for name in inputs:
config = tomllib.loads(files["config.toml"])
configjson = json.dumps(config, separators=(',',':'))
+with open("config.js","w") as f:
+ f.write("config="+configjson+";")
+
index = files["index.html"]
index = index.replace('<link rel="stylesheet" href="style.css">', f'<style>{files["main.css"]}</style>')