aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rwxr-xr-xabrechenbarkeit.lua (renamed from strichliste.lua)93
-rw-r--r--gnix.yaml2
-rw-r--r--readme.md4
4 files changed, 54 insertions, 47 deletions
diff --git a/.gitignore b/.gitignore
index 3564e40..ffe2fa3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
/*
!/gnix.yaml
!/readme.md
-!/strichliste.lua
+!/abrechenbarkeit.lua
!/.gitignore
!/collapse_log.lua
diff --git a/strichliste.lua b/abrechenbarkeit.lua
index fbdfbb5..dc3685b 100755
--- a/strichliste.lua
+++ b/abrechenbarkeit.lua
@@ -51,19 +51,20 @@ local path = os.getenv("PATH_INFO")
local method = os.getenv("REQUEST_METHOD")
local query = parse_query(os.getenv("QUERY_STRING"))
-local stylesheet = [[
- /* body { background-color: #161616; }
- h1, h2, h3, h4, h5, h6, p, label, a { color: #e2e2e2; } */
- .amount-presets form { display: inline-block; width: 60px }
- .amount-pos { color: green; }
- .amount-neg { color: red; }
- nav h2 { display: inline-block }
- .notif { padding: 0.5em; margin: 0.5em; background-color: #ddd; }
- .notif.error { background-color: #faa; }
- .notif p { margin: 5px; }
- form.box { border: 2px solid grey; padding: 0.5em; margin: 0.5em; display: inline-block; }
- form h3 { margin: 5px; }
-]]
+local stylesheet = io.open("a.css"):read("a")
+-- local stylesheet = [[
+-- /* body { background-color: #161616; }
+-- h1, h2, h3, h4, h5, h6, p, label, a { color: #e2e2e2; } */
+-- .amount-presets form { display: inline-block; width: 60px }
+-- .amount-pos { color: green; }
+-- .amount-neg { color: red; }
+-- nav h2 { display: inline-block }
+-- .notif { padding: 0.5em; margin: 0.5em; background-color: #ddd; }
+-- .notif.error { background-color: #faa; }
+-- .notif p { margin: 5px; }
+-- form.box { border: 2px solid grey; padding: 0.5em; margin: 0.5em; display: inline-block; }
+-- form h3 { margin: 5px; }
+-- ]]
local script = [[
document.addEventListener("keypress", ev => {
@@ -91,10 +92,15 @@ local function respond(status, title, body)
</head>
<body>
<nav>
- <h2><a href="/">Strichliste v2</a></h2>
- <span><a href="/?log">Log</a></span>
- <span><a href="/?products">Products</a></span>
- <span><a href="https://codeberg.org/metamuffin/strichliste">Source</a></span>
+ <a class="logo" href="/">
+ <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-receipt-cutoff" viewBox="0 0 16 16">
+ <path d="M3 4.5a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5M11.5 4a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1zm0 2a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1z"/>
+ <path d="M2.354.646a.5.5 0 0 0-.801.13l-.5 1A.5.5 0 0 0 1 2v13H.5a.5.5 0 0 0 0 1h15a.5.5 0 0 0 0-1H15V2a.5.5 0 0 0-.053-.224l-.5-1a.5.5 0 0 0-.8-.13L13 1.293l-.646-.647a.5.5 0 0 0-.708 0L11 1.293l-.646-.647a.5.5 0 0 0-.708 0L9 1.293 8.354.646a.5.5 0 0 0-.708 0L7 1.293 6.354.646a.5.5 0 0 0-.708 0L5 1.293 4.354.646a.5.5 0 0 0-.708 0L3 1.293zm-.217 1.198.51.51a.5.5 0 0 0 .707 0L4 1.707l.646.647a.5.5 0 0 0 .708 0L6 1.707l.646.647a.5.5 0 0 0 .708 0L8 1.707l.646.647a.5.5 0 0 0 .708 0L10 1.707l.646.647a.5.5 0 0 0 .708 0L12 1.707l.646.647a.5.5 0 0 0 .708 0l.509-.51.137.274V15H2V2.118z"/>
+ </svg>
+ Abrechenbarkeit</a>
+ <a href="/?log">Log</a>
+ <a href="/?products">Products</a>
+ <a href="https://codeberg.org/metamuffin/strichliste">Source</a>
</nav>
]], escape(title), stylesheet, script, config.head_extra or ""))
body()
@@ -223,7 +229,7 @@ local function r_user(username)
if method == "POST" then
notif = r_user_post(username)
end
- return respond(200, string.format("Strichliste: %s", username), function()
+ return respond(200, string.format("Abrechenbarheit: %s", username), function()
print(string.format("<h1>%s</h1>", username))
local balance = balances()[username]
local last_txn = last_txns()[username]
@@ -236,48 +242,49 @@ local function r_user(username)
]])
else
print(string.format([[
- <p>Current balance: <span class="amount-%s">%.02f€</p>
+ <p><span class="balance">Current balance:</span><span class="amount-%s balance-value">%.02f€</p>
]], balance >= 0 and "pos" or "neg", balance / 100))
print(string.format([[
<p>Last transaction added %s ago. <a href="/%s?log">View user log</a>
]], format_duration(os.time() - last_txn), username))
end
+ print([[<div class="transactions container">]])
+ print([[<div class="amount-presets box">]])
+ for _, type in ipairs({ 1, -1 }) do
+ for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
+ print(string.format([[
+ <form action="" method="POST">
+ <input type="number" name="amount" id="amount" value="%d" hidden />
+ <input type="text" name="comment" id="comment" value="" hidden />
+ <input type="submit" value="%s%.02f€" class="amount-%s" />
+ </form>
+ ]], amount * type, ({ [-1] = "-", [1] = "+" })[type], amount / 100,
+ ({ [-1] = "neg", [1] = "pos" })[type]))
+ end
+ end
+ print("</div>")
print([[
<form class="transaction box" action="" method="POST">
<h3>Create Transaction</h3>
<label for="amount">Amount: </label>
- <input type="number" name="amount" id="amount" /><br/>
+ <input type="number" name="amount" id="amount" />
<label for="comment">Comment: </label>
- <input type="text" name="comment" id="comment" /><br/>
+ <input type="text" name="comment" id="comment" />
<input type="submit" value="Update" />
</form>
<form class="transaction box" action="" method="POST" id="buy_product">
<h3>Buy Product</h3>
<label for="product">Product: </label>
- <input type="text" name="product" id="product" /><br/>
+ <input type="text" name="product" id="product" />
<input type="submit" value="Buy" />
</form>
]])
- print([[<div class="amount-presets">]])
- for _, type in ipairs({ 1, -1 }) do
- for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
- print(string.format([[
- <form action="" method="POST">
- <input type="number" name="amount" id="amount" value="%d" hidden />
- <input type="text" name="comment" id="comment" value="" hidden />
- <input type="submit" value="%s%.02f€" class="amount-%s" />
- </form>
- ]], amount * type, ({ [-1] = "-", [1] = "+" })[type], amount / 100,
- ({ [-1] = "neg", [1] = "pos" })[type]))
- end
- print("<br/>")
- end
print("</div>")
end)
end
local function r_log(filter)
- return respond(200, "Strichliste Log", function()
+ return respond(200, "Abrechnungen", function()
print("<table>")
print("<tr><th>Time</th><th>Username</th><th>Amount</th><th>Comment</th></tr>")
for time, username, amount, comment in read_log() do
@@ -312,19 +319,19 @@ local function r_log(filter)
end
local function r_index()
- return respond(200, "Strichliste", function()
+ return respond(200, "Abrechenbarkeit", function()
print([[
- <form action="/" method="GET" class="box">
+ <form action="/" method="GET" class="creation">
<h3>User Creation</h3>
<label for="username">Username: </label>
- <input type="text" name="create_user" id="username" /><br/>
+ <input type="text" name="create_user" id="username" />
<input type="submit" value="Continue" />
</form>
]])
print("<ul>")
for username, balance in pairs(balances()) do
print(string.format([[
- <li><a href="/%s">%s</a>: <span class="amount-%s">%.02f€</span></li>
+ <li><a href="/%s"><span class="name">%s</span> <span class="amount amount-%s">%.02f€</span></a></li>
]],
urlencode(username),
escape(username),
@@ -344,9 +351,9 @@ local function r_create_user()
end
local function r_products()
- respond(200, "Strichliste Product List", function()
+ respond(200, "Abrechenbare Products", function()
print("<h1>Product List</h1>")
- print("<table><tr><th>Name</th><th>Price</th><th>Amount</th></tr>")
+ print("<table><tr><th>Name</th><th>Price</th><th>Barcode</th></tr>")
for barcode, price, name in read_products() do
print(string.format([[
<tr><td>%s</td><td class="amount-%s">%.02f€</td><td>%s</td></tr>
diff --git a/gnix.yaml b/gnix.yaml
index 5f8470c..8815f2a 100644
--- a/gnix.yaml
+++ b/gnix.yaml
@@ -1,2 +1,2 @@
http: { bind: "0.0.0.0:8080" }
-handler: !cgi { bin: ./strichliste.lua }
+handler: !cgi { bin: ./abrechenbarkeit.lua }
diff --git a/readme.md b/readme.md
index 2ea03f7..4785d95 100644
--- a/readme.md
+++ b/readme.md
@@ -1,8 +1,8 @@
-# Strichliste v2
+# Abrechenbarkeit v2
A _simpler_ trust based ledger.
-The entire application is contained within `strichliste.lua`. This script
+The entire application is contained within `abrechenbarkeit.lua`. This script
implements CGI. It was tested against Lua version 5.4.7. Application data is
stored in a number of files in the process working directory (See below).