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>
{+appname}
</a>
<a href="/?log">{+log}</a>
<a href="/?users">{+users}</a>
<a href="/?spus">{+spus}</a>
<a href="/?products">{+products}</a>
<a href="/?log">{+log}</a>
<a href="/?about">{+about}</a>
</nav>
]], {
@ -211,7 +213,13 @@ local function respond(status, title, body)
script = script,
head_extra = config.head_extra or ""
}))
if config.header ~= nil then
print(config.header)
end
body()
if config.footer ~= nil then
print(config.footer)
end
print("</body></html>")
end
@ -344,7 +352,7 @@ local function r_transaction_post()
return error_box("unknown product")
end
end
user_src = user_src or "@global"
user_src = user_src or "@Potential"
if amount == nil then
return error_box("amount invalid")
end
@ -383,12 +391,17 @@ local function r_user(username)
notif = r_transaction_post()
end
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 last_txn = last_txns()[username]
local new_user = balance == nil
balance = balance or 0
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
print(format([[<div class="notif"><p><i>{+user.lazy_creation}</i></p></div>]]))
else
@ -404,7 +417,7 @@ local function r_user(username)
for _, type in ipairs({ 1, -1 }) do
for _, amount in ipairs({ 50, 100, 150, 200, 500, 1000 }) do
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="number" name="amount" value="{a_raw}" hidden />
<input type="text" name="comment" value="" hidden />
@ -413,13 +426,14 @@ local function r_user(username)
username = username,
a_raw = 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
print("</div>")
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>
<input type="text" name="user_dst" value="{!username}" hidden />
<label for="amount">Amount (ct): </label>
@ -428,7 +442,7 @@ local function r_user(username)
<input type="text" name="comment" id="comment" />
<input type="submit" value="{+user.form.transaction.submit}" class="amount-ntr button" />
</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>
<input type="text" name="user_dst" value="{!username}" 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 class="amount-neg button" type="submit" value="{+user.form.buy.submit}" />
</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>
<input type="text" name="user_dst" value="{!username}" hidden />
<label for="pcount">{+field.count}: </label>
@ -449,7 +463,7 @@ local function r_user(username)
<input type="text" name="pcode" id="pcode" />
<input type="submit" value="{+user.form.restock.submit}" class="button amount-pos" />
</form>
]], { username = username }))
]], { username = username, disable_class = is_special and "disabled" or "" }))
print("</div>")
end)
end
@ -520,7 +534,7 @@ local function r_log(filter)
end)
end
local function r_index()
local function r_users(show_special)
return respond(200, "Abrechenbarkeit", function()
print(format([[
<form action="/" method="GET" id="user_creation">
@ -533,7 +547,8 @@ local function r_index()
print([[<div class="userlist"></div>]]) -- for printing
print([[<ul class="userlist">]])
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>
<a href="/{username_url}">
<span class="name">{!username}</span>
@ -541,7 +556,7 @@ local function r_index()
</a>
</li>]], {
username_url = urlencode(user.name),
username = user.name,
username = user.name:gsub("@", ""),
balance = format_amount(user.balance, "span")
}))
end
@ -696,8 +711,12 @@ if path == "/" then
return r_log()
elseif query.create_user then
return r_create_user()
elseif query.spus then
return r_users(true)
elseif query.users then
return r_users(false)
else
return r_index()
return r_users(false)
end
else
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.view_log=View user log
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 {
background: linear-gradient(#60d0fa50 0%,
#60d0fa50 19%,
#f5acba50 20%
#f5acba50 39%,
#f5acba50 20% #f5acba50 39%,
#FFFFFF50 40%,
#FFFFFF50 59%,
#f5acba50 60%,
@ -119,7 +118,7 @@ form#user_creation>* {
margin-right: 1.5em;
}
ul.userlist > li a {
ul.userlist>li a {
text-decoration: none;
}
@ -135,7 +134,7 @@ ul.userlist {
margin-top: 1em;
}
.userlist > li > a {
.userlist>li>a {
border-radius: 4px;
background-color: var(--b2);
padding: 1em;
@ -296,7 +295,12 @@ input:not([type=submit]) {
border-bottom: 1px solid var(--t0);
}
form.disabled input {
filter: opacity(50%);
}
@media print {
nav,
.container {
display: none;
@ -350,4 +354,4 @@ input:not([type=submit]) {
form {
display: none;
}
}
}