all repos — piggy @ 53d67a45604e097a55d1cd03ed984e0a67206f26

Dead simple finance manager in Go, HTML and JS.

add favicon, select menus for bookmakers and accounts
Marco Andronaco andronacomarco@gmail.com
Mon, 07 Oct 2024 18:09:23 +0200
commit

53d67a45604e097a55d1cd03ed984e0a67206f26

parent

e82c0fc1e0a153fffa9de1c390f9d0cc4cee487d

2 files changed, 24 insertions(+), 2 deletions(-)

jump to
M static/js/common.jsstatic/js/common.js

@@ -1,4 +1,5 @@

document.addEventListener('DOMContentLoaded', function () { + // navbar const navObject = document.getElementsByTagName("nav")[0]; for (const page of navPages) { const a = document.createElement("a");

@@ -6,6 +7,8 @@ a.innerText = page.name;

a.href = page.href; navObject.appendChild(a) } + // favicon + document.getElementsByTagName("head")[0].innerHTML += favicon; }); // Global constants

@@ -15,6 +18,7 @@ { name: "Bookmakers", href: "/bookmakers" },

{ name: "Accounts", href: "/accounts" }, { name: "Records", href: "/records" }, ]; +const favicon = `<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>💰</text></svg>">`; const currency = "€"; const locale = "it-IT";

@@ -90,6 +94,20 @@ input.className = name;

input.placeholder = label; input.value = value ?? ""; flatpickr(input, flatpickrOptions); + l.innerHTML += label + "<br />"; + l.appendChild(input); + return l; +} + +function newInputSelect(label, value, name, options) { + const l = document.createElement("label"); + const input = document.createElement("select"); + input.className = name; + input.placeholder = label; + for (const o of options) { + input.options.add(new Option(o.name, o.id)); + } + input.value = value ?? ""; l.innerHTML += label + "<br />"; l.appendChild(input); return l;
M static/js/records-edit.jsstatic/js/records-edit.js

@@ -10,11 +10,15 @@ document.getElementById('delete').addEventListener('click', remove);

} }); +let accounts = []; +let bookmakers = []; let id; async function handleID() { id = getQueryStringID(); const record = id === 0 ? null : await getRecord(id); + accounts = await getAccounts(); + bookmakers = await getBookmakers(); document.getElementById("main-container").appendChild(loadRecord(record)); }

@@ -66,10 +70,10 @@ deleteEntry.onclick = () => div.remove();

div.appendChild(deleteEntry); // entry.bookmaker_id - div.appendChild(newInputText("Bookmaker ID", entry?.bookmaker_id, "entry-bookmaker_id")) + div.appendChild(newInputSelect("Bookmaker", entry?.bookmaker_id, "entry-bookmaker_id", bookmakers)) // entry.account_id - div.appendChild(newInputText("Account ID", entry?.account_id, "entry-account_id")) + div.appendChild(newInputSelect("Account", entry?.account_id, "entry-account_id", accounts)) // entry.amount div.appendChild(newInputText("Amount", formatValue(entry?.amount), "entry-amount"))