diff options
| author | Marin Ivanov <[email protected]> | 2024-08-20 15:24:28 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-08-20 15:24:28 +0300 |
| commit | 0c24aba5dd6b7804ba63d596e3ae692fccb68e88 (patch) | |
| tree | 89f39b64d3c713f833ce7a0f17bfd4d1716f1aba | |
| parent | ec34163617e3588a63dc611834a372746f9d4107 (diff) | |
add errors
| -rw-r--r-- | app.js | 45 | ||||
| -rw-r--r-- | index.html | 9 | ||||
| -rw-r--r-- | ka.js | 4 | ||||
| -rw-r--r-- | style.css | 20 |
4 files changed, 57 insertions, 21 deletions
@@ -6,10 +6,15 @@ const loading = (val) => { loader.$click(() => loading(0)); let error = null; +function errClose() { + error = null; + app.reload(); +} let data = {}; function onerror(err) { error = err; console.error(err); + app.reload(); } function parsedata(r) { return Object.fromEntries(r.split("\n").map(x=>x.trim()).filter(x=>x).map(x=>x.split('='))); @@ -24,7 +29,7 @@ function cmd(url, body) { }) .then(r => parsedata(r)); }; -function loaddata() { +function loadconfig() { loading(1); cmd("/cgi-bin/getconfig") .then(x => { @@ -34,21 +39,34 @@ function loaddata() { .catch(onerror) .then(() => loading(0)) } +function saveconfig(groups) { + cmd("/cgi-bin/setconfig", data) + .catch(onerror) + .then(loadconfig) +} + +function CErr(text) { + var el = div( + div("🗙").$cls("close").$click(errClose), + span("⚠ "), + text, + ).$cls("err"); + function errClose() { + error = null; + el.remove(); + }; + return el; +} const routes = { "/": () => div( h2("Lorem Ipsum"), p("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "), p("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."), - - h2("Ipsum Lorem"), - p("Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), - p("Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), - p("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."), - p("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "), ), "/network": () => div( - h1("Мрежови настройки"), + error && CErr(error.message), + h1("Network settings"), table( tr( td("IP"), @@ -62,10 +80,9 @@ const routes = { ), ) ).$cls("network"), - input("button").$value("Съхрани") + input("button").$value("Save").$click(saveconfig) ), "/config": () => { - loaddata(); return div(); }, "/waiting": () => { @@ -73,11 +90,11 @@ const routes = { setTimeout(() => { loading(0); }, 3000); - return div("Пуйчи"); + return div(""); }, "": () => div( - h1("Несъществуваща страница"), - p("Страницата не е намерена.") + h1("Not Found"), + p("The requested page is not available.") ), }; const onchange = () => { @@ -86,4 +103,4 @@ const onchange = () => { }; router(app, routes, onchange); -loaddata(); +loadconfig(); @@ -13,11 +13,10 @@ <label for="showmenu"><span>☰</span> Меню</label> <input type="checkbox" id="showmenu" /> - <a class="active" href="#">Данни</a> - <a href="#/network">Мрежа</a> - <a href="#/config">Настройки</a> - <a href="#/tools">Инструменти</a> - <a href="#/waiting">Пуйчи</a> + <a class="active" href="#">Home</a> + <a href="#/network">Network</a> + <a href="#/config">Configuration</a> + <a href="#/tools">Tools</a> </nav> <section id="app"></section> </main> @@ -34,13 +34,13 @@ elproto.$change2state = function(state, field, valgetter=getvalue) { function tag(name, attrs, ...children) { const el = doc.createElement(name); el.$attrs(attrs||{}); - for (const child of children) { + for (const child of children.filter(x=>x)) { el.appendChild((typeof(child) === 'string') ? doc.createTextNode(child) : child); } return el; } -const TRIVIAL = "h1,h2,h3,p,a,div,span,select,table,tr,td"; +const TRIVIAL = "h1,h2,h3,p,,div,span,select,table,tr,td"; for (let name of TRIVIAL.split(",")) { window[name] = (...children) => tag(name, null, ...children); } @@ -86,6 +86,26 @@ input[type=button]:active { background-color: #079290; } +.err { + color: #fff; + background-color: #f00; + position: relative; + padding: 16px; + margin-bottom: 10px; + line-height: 1.3em; +} +.err span { + font-size: 1.5em; + font-weight: bold; +} +.err .close { + font-size: 1.3em; + position: absolute; + top:16px; + right:16px; + cursor: pointer; +} + #loader { position: absolute; left: 0; |
