add spus view

This commit is contained in:
metamuffin 2024-11-09 00:35:52 +01:00
parent f5a045dc96
commit d04dbb8a4f
No known key found for this signature in database
GPG key ID: 718F9749DCDBD654
3 changed files with 45 additions and 18 deletions

View file

@ -200,8 +200,10 @@ local function respond(status, title, body)
</svg> </svg>
{+appname} {+appname}
</a> </a>
<a href="/?log">{+log}</a> <a href="/?users">{+users}</a>
<a href="/?spus">{+spus}</a>
<a href="/?products">{+products}</a> <a href="/?products">{+products}</a>
<a href="/?log">{+log}</a>
<a href="/?about">{+about}</a> <a href="/?about">{+about}</a>
</nav> </nav>
]], { ]], {
@ -211,7 +213,13 @@ local function respond(status, title, body)
script = script, script = script,
head_extra = config.head_extra or "" head_extra = config.head_extra or ""
})) }))
if config.header ~= nil then
print(config.header)
end
body() body()
if config.footer ~= nil then
print(config.footer)
end
print("</body></html>") print("</body></html>")
end end
@ -344,7 +352,7 @@ local function r_transaction_post()
return error_box("unknown product") return error_box("unknown product")
end end
end end
user_src = user_src or "@global" user_src = user_src or "@Potential"
if amount == nil then if amount == nil then
return error_box("amount invalid") return error_box("amount invalid")
end end
@ -383,12 +391,17 @@ local function r_user(username)
notif = r_transaction_post() notif = r_transaction_post()
end end
return respond(200, string.format("Abrechenbarheit: %s", username), function() return respond(200, string.format("Abrechenbarheit: %s", username), function()
print(format("<h1>{username}</h1>", { username = username })) local is_special = username:sub(1, 1) == "@"
local username_display = username:gsub("@", "")
print(format(is_special and "<h1><i>{!username}</i></h1>" or "<h1>{!username}</h1>", { username = username_display }))
local balance = balances()[username] local balance = balances()[username]
local last_txn = last_txns()[username] local last_txn = last_txns()[username]
local new_user = balance == nil local new_user = balance == nil
balance = balance or 0 balance = balance or 0
if notif then print(notif) end if notif then print(notif) end
if is_special then
print(format([[<div class="notif"><p><i>{+user.special}</i></p></div>]]))
end
if new_user then if new_user then
print(format([[<div class="notif"><p><i>{+user.lazy_creation}</i></p></div>]])) print(format([[<div class="notif"><p><i>{+user.lazy_creation}</i></p></div>]]))
else else
@ -404,7 +417,7 @@ local function r_user(username)
for _, type in ipairs({ 1, -1 }) do for _, type in ipairs({ 1, -1 }) do
for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
local a = amount * type local a = amount * type
print(format([[<form action="" method="POST"> print(format([[<form action="" method="POST" class="{disable_class}">
<input type="text" name="user_dst" value="{!username}" hidden /> <input type="text" name="user_dst" value="{!username}" hidden />
<input type="number" name="amount" value="{a_raw}" hidden /> <input type="number" name="amount" value="{a_raw}" hidden />
<input type="text" name="comment" value="" hidden /> <input type="text" name="comment" value="" hidden />
@ -413,13 +426,14 @@ local function r_user(username)
username = username, username = username,
a_raw = a, a_raw = a,
amount = format_amount(a), amount = format_amount(a),
sign = a < 0 and "neg" or "pos" sign = a < 0 and "neg" or "pos",
disable_class = is_special and "disabled" or ""
})) }))
end end
end end
print("</div>") print("</div>")
print(format([[ print(format([[
<form class="transaction box backgroundbox" action="" method="POST"> <form class="transaction box backgroundbox {disable_class}" action="" method="POST">
<h3>{+user.form.transaction}</h3> <h3>{+user.form.transaction}</h3>
<input type="text" name="user_dst" value="{!username}" hidden /> <input type="text" name="user_dst" value="{!username}" hidden />
<label for="amount">Amount (ct): </label> <label for="amount">Amount (ct): </label>
@ -428,7 +442,7 @@ local function r_user(username)
<input type="text" name="comment" id="comment" /> <input type="text" name="comment" id="comment" />
<input type="submit" value="{+user.form.transaction.submit}" class="amount-ntr button" /> <input type="submit" value="{+user.form.transaction.submit}" class="amount-ntr button" />
</form> </form>
<form class="transaction box backgroundbox" action="" method="POST" id="buy_product"> <form class="transaction box backgroundbox {disable_class}" action="" method="POST" id="buy_product">
<h3>{+user.form.buy}</h3> <h3>{+user.form.buy}</h3>
<input type="text" name="user_dst" value="{!username}" hidden /> <input type="text" name="user_dst" value="{!username}" hidden />
<input type="text" name="negate_pcount" value="1" hidden /> <input type="text" name="negate_pcount" value="1" hidden />
@ -438,7 +452,7 @@ local function r_user(username)
<input type="text" name="pcode" id="pcode" /> <input type="text" name="pcode" id="pcode" />
<input class="amount-neg button" type="submit" value="{+user.form.buy.submit}" /> <input class="amount-neg button" type="submit" value="{+user.form.buy.submit}" />
</form> </form>
<form class="transaction box backgroundbox" action="" method="POST" id="buy_product"> <form class="transaction box backgroundbox {disable_class}" action="" method="POST" id="buy_product">
<h3>{+user.form.restock}</h3> <h3>{+user.form.restock}</h3>
<input type="text" name="user_dst" value="{!username}" hidden /> <input type="text" name="user_dst" value="{!username}" hidden />
<label for="pcount">{+field.count}: </label> <label for="pcount">{+field.count}: </label>
@ -449,7 +463,7 @@ local function r_user(username)
<input type="text" name="pcode" id="pcode" /> <input type="text" name="pcode" id="pcode" />
<input type="submit" value="{+user.form.restock.submit}" class="button amount-pos" /> <input type="submit" value="{+user.form.restock.submit}" class="button amount-pos" />
</form> </form>
]], { username = username })) ]], { username = username, disable_class = is_special and "disabled" or "" }))
print("</div>") print("</div>")
end) end)
end end
@ -520,7 +534,7 @@ local function r_log(filter)
end) end)
end end
local function r_index() local function r_users(show_special)
return respond(200, "Abrechenbarkeit", function() return respond(200, "Abrechenbarkeit", function()
print(format([[ print(format([[
<form action="/" method="GET" id="user_creation"> <form action="/" method="GET" id="user_creation">
@ -533,7 +547,8 @@ local function r_index()
print([[<div class="userlist"></div>]]) -- for printing print([[<div class="userlist"></div>]]) -- for printing
print([[<ul class="userlist">]]) print([[<ul class="userlist">]])
for _, user in ipairs(get_active_users()) do for _, user in ipairs(get_active_users()) do
if user.name:sub(1, 1) ~= "@" then local is_spu = user.name:sub(1, 1) == "@"
if is_spu == show_special then
print(format([[<li> print(format([[<li>
<a href="/{username_url}"> <a href="/{username_url}">
<span class="name">{!username}</span> <span class="name">{!username}</span>
@ -541,7 +556,7 @@ local function r_index()
</a> </a>
</li>]], { </li>]], {
username_url = urlencode(user.name), username_url = urlencode(user.name),
username = user.name, username = user.name:gsub("@", ""),
balance = format_amount(user.balance, "span") balance = format_amount(user.balance, "span")
})) }))
end end
@ -696,8 +711,12 @@ if path == "/" then
return r_log() return r_log()
elseif query.create_user then elseif query.create_user then
return r_create_user() return r_create_user()
elseif query.spus then
return r_users(true)
elseif query.users then
return r_users(false)
else else
return r_index() return r_users(false)
end end
else else
local username = extract_username() local username = extract_username()

View file

@ -47,3 +47,7 @@ user.last_txn=Last transaction added {time}.
user.lazy_creation=This user account does not exist yet. It will only be created after the first transaction. user.lazy_creation=This user account does not exist yet. It will only be created after the first transaction.
user.view_log=View user log user.view_log=View user log
price.amount={sign}{amount}{unit} price.amount={sign}{amount}{unit}
user.form.transaction.success=Transaction successful
spus=SPUs
users=Users
user.special=This is a special user.

View file

@ -10,8 +10,7 @@
.trans { .trans {
background: linear-gradient(#60d0fa50 0%, background: linear-gradient(#60d0fa50 0%,
#60d0fa50 19%, #60d0fa50 19%,
#f5acba50 20% #f5acba50 20% #f5acba50 39%,
#f5acba50 39%,
#FFFFFF50 40%, #FFFFFF50 40%,
#FFFFFF50 59%, #FFFFFF50 59%,
#f5acba50 60%, #f5acba50 60%,
@ -119,7 +118,7 @@ form#user_creation>* {
margin-right: 1.5em; margin-right: 1.5em;
} }
ul.userlist > li a { ul.userlist>li a {
text-decoration: none; text-decoration: none;
} }
@ -135,7 +134,7 @@ ul.userlist {
margin-top: 1em; margin-top: 1em;
} }
.userlist > li > a { .userlist>li>a {
border-radius: 4px; border-radius: 4px;
background-color: var(--b2); background-color: var(--b2);
padding: 1em; padding: 1em;
@ -296,7 +295,12 @@ input:not([type=submit]) {
border-bottom: 1px solid var(--t0); border-bottom: 1px solid var(--t0);
} }
form.disabled input {
filter: opacity(50%);
}
@media print { @media print {
nav, nav,
.container { .container {
display: none; display: none;
@ -350,4 +354,4 @@ input:not([type=submit]) {
form { form {
display: none; display: none;
} }
} }