mirror of
https://codeberg.org/metamuffin/abrechenbarkeit.git
synced 2025-01-01 09:14:34 +00:00
refactor and user creating input redirect
This commit is contained in:
parent
e93520702a
commit
5f8b7352cd
3 changed files with 98 additions and 84 deletions
|
@ -60,7 +60,7 @@ local function get_user_theme(username)
|
||||||
if username == "_jeb" then
|
if username == "_jeb" then
|
||||||
c = "html { animation: 2s jeb infinite; }"
|
c = "html { animation: 2s jeb infinite; }"
|
||||||
c = c .. "@keyframes jeb {\n"
|
c = c .. "@keyframes jeb {\n"
|
||||||
for i=0,100 do
|
for i = 0, 100 do
|
||||||
c = c .. string.format("%.02f%% { --hue: %.02f; } \n", i, i / 100 * 360)
|
c = c .. string.format("%.02f%% { --hue: %.02f; } \n", i, i / 100 * 360)
|
||||||
end
|
end
|
||||||
c = c .. "\n}"
|
c = c .. "\n}"
|
||||||
|
@ -71,7 +71,7 @@ local function get_user_theme(username)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function respond(status, title, body)
|
local function respond(status, title, body)
|
||||||
local themecss, themejs = get_user_theme(path and path:sub(2))
|
local themecss, themejs = get_user_theme(path and path:sub(2))
|
||||||
|
|
||||||
print(string.format("Status: %d", status))
|
print(string.format("Status: %d", status))
|
||||||
print("Content-Type: text/html")
|
print("Content-Type: text/html")
|
||||||
|
@ -101,14 +101,14 @@ local function respond(status, title, body)
|
||||||
]],
|
]],
|
||||||
escape(title),
|
escape(title),
|
||||||
stylesheet, -- style.css
|
stylesheet, -- style.css
|
||||||
themecss, -- theme for user
|
themecss, -- theme for user
|
||||||
script, -- script.js
|
script, -- script.js
|
||||||
config.head_extra or ""
|
config.head_extra or ""
|
||||||
))
|
))
|
||||||
body()
|
body()
|
||||||
print(string.format(
|
print(string.format(
|
||||||
"<script>%s</script></body></html>",
|
"<script>%s</script></body></html>",
|
||||||
themejs
|
themejs
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -227,20 +227,20 @@ local function r_user_post(username)
|
||||||
if data.pcode then
|
if data.pcode then
|
||||||
for p_barcode, p_amount, p_name, p_owner in read_products() do
|
for p_barcode, p_amount, p_name, p_owner in read_products() do
|
||||||
if p_barcode == data.pcode then
|
if p_barcode == data.pcode then
|
||||||
powner = p_owner
|
powner = p_owner
|
||||||
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
|
pcount = (tonumber(data.pcount) or 1) * (data.negate_pcount ~= nil and -1 or 1)
|
||||||
pcode = p_barcode
|
pcode = p_barcode
|
||||||
if amount == nil then amount = pcount * p_amount end
|
if amount == nil then amount = pcount * p_amount end
|
||||||
if comment == nil then
|
if comment == nil then
|
||||||
comment = string.format("%s %d %s", pcount < 0 and "Buy" or "Restock",
|
comment = string.format("%s %d %s", pcount < 0 and "Buy" or "Restock",
|
||||||
math.abs(pcount), p_name)
|
math.abs(pcount), p_name)
|
||||||
|
|
||||||
powner_comment = string.format("%s %d %s %s %s",
|
powner_comment = string.format("%s %d %s %s %s",
|
||||||
pcount < 0 and "Sell" or "Restock",
|
pcount < 0 and "Sell" or "Restock",
|
||||||
math.abs(pcount), p_name,
|
math.abs(pcount), p_name,
|
||||||
pcount < 0 and "to" or "by",
|
pcount < 0 and "to" or "by",
|
||||||
username)
|
username)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if amount == nil then
|
if amount == nil then
|
||||||
|
@ -258,12 +258,12 @@ local function r_user_post(username)
|
||||||
return error_box("failed to open log")
|
return error_box("failed to open log")
|
||||||
end
|
end
|
||||||
local time = os.time()
|
local time = os.time()
|
||||||
-- subtract from buyer
|
-- subtract from buyer
|
||||||
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, username, amount, pcode or "", pcount or "", comment))
|
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, username, amount, pcode or "", pcount or "", comment))
|
||||||
-- add to owner
|
-- add to owner
|
||||||
if powner then
|
if powner then
|
||||||
-- count is always zero as doesn't affect stock
|
-- count is always zero as doesn't affect stock
|
||||||
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, powner, -amount, pcode or "", "", powner_comment))
|
log:write(string.format("%d,%s,%d,%s,%s,%s\n", time, powner, -amount, pcode or "", "", powner_comment))
|
||||||
end
|
end
|
||||||
log:flush()
|
log:flush()
|
||||||
log:close()
|
log:close()
|
||||||
|
@ -294,14 +294,14 @@ local function r_user(username)
|
||||||
<div class="notif"><p><i>This user account does not exist yet. It will only be created after the first transaction.</i></p></div>
|
<div class="notif"><p><i>This user account does not exist yet. It will only be created after the first transaction.</i></p></div>
|
||||||
]])
|
]])
|
||||||
else
|
else
|
||||||
print([[<div class="backgroundbox userinfo">]])
|
print([[<div class="backgroundbox userinfo">]])
|
||||||
print(string.format([[
|
print(string.format([[
|
||||||
Current balance:<br><span class="amount-%s balance-value">%.02f€</span><br>
|
Current balance:<br><span class="amount-%s balance-value">%.02f€</span><br>
|
||||||
]], balance >= 0 and "pos" or "neg", balance / 100))
|
]], balance >= 0 and "pos" or "neg", balance / 100))
|
||||||
print(string.format([[
|
print(string.format([[
|
||||||
Last transaction added %s ago. <a href="/%s?log">View user log</a>
|
Last transaction added %s ago. <a href="/%s?log">View user log</a>
|
||||||
]], format_duration(os.time() - last_txn), username))
|
]], format_duration(os.time() - last_txn), username))
|
||||||
print([[</div>]])
|
print([[</div>]])
|
||||||
end
|
end
|
||||||
print([[<div class="transactions container firstchildlarge">]])
|
print([[<div class="transactions container firstchildlarge">]])
|
||||||
print([[<div class="amount-presets backgroundbox">]])
|
print([[<div class="amount-presets backgroundbox">]])
|
||||||
|
@ -403,7 +403,7 @@ end
|
||||||
local function r_index()
|
local function r_index()
|
||||||
return respond(200, "Abrechenbarkeit", function()
|
return respond(200, "Abrechenbarkeit", function()
|
||||||
print([[
|
print([[
|
||||||
<form action="/" method="GET" class="creation">
|
<form action="/" method="GET" id="user_creation">
|
||||||
<h3>User Creation</h3>
|
<h3>User Creation</h3>
|
||||||
<label for="username">Username: </label>
|
<label for="username">Username: </label>
|
||||||
<input type="text" name="create_user" id="username" />
|
<input type="text" name="create_user" id="username" />
|
||||||
|
@ -426,9 +426,9 @@ local function r_index()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function validate_username(username)
|
local function validate_username(username)
|
||||||
-- disallow leading or traling whitespace
|
-- disallow leading or traling whitespace
|
||||||
return username ~= nil
|
return username ~= nil
|
||||||
and username:match("^([%w_ -]+)$") ~= nil
|
and username:match("^([%w_ -]+)$") ~= nil
|
||||||
and username:match("^%s") == nil
|
and username:match("^%s") == nil
|
||||||
and username:match("%s$") == nil
|
and username:match("%s$") == nil
|
||||||
end
|
end
|
||||||
|
@ -517,7 +517,13 @@ local function r_products()
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
]])
|
]])
|
||||||
print([[<table class="productlist"><tr><th>Name</th><th>Price</th><th>Barcode</th><th>Count</th><th>Owner</th></tr>]])
|
print([[<table class="productlist"><tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Price</th>
|
||||||
|
<th>Barcode</th>
|
||||||
|
<th>Count</th>
|
||||||
|
<th>Owner</th>
|
||||||
|
</tr>]])
|
||||||
local pbals = product_balances()
|
local pbals = product_balances()
|
||||||
for barcode, price, name, owner in read_products() do
|
for barcode, price, name, owner in read_products() do
|
||||||
print(string.format([[
|
print(string.format([[
|
||||||
|
|
21
script.js
21
script.js
|
@ -1,10 +1,21 @@
|
||||||
/// <reference lib="dom" />
|
/// <reference lib="dom" />
|
||||||
|
|
||||||
document.addEventListener("keypress", ev => {
|
document.addEventListener("keydown", ev => {
|
||||||
if (!(document.activeElement instanceof HTMLInputElement)) {
|
if (!(document.activeElement instanceof HTMLInputElement)) {
|
||||||
if (ev.code.startsWith("Digit"))
|
if (ev.code.startsWith("Digit")) {
|
||||||
document.forms.buy_product.pcode.value += ev.code.substring(5)
|
if (document.forms.buy_product.pcode)
|
||||||
if (ev.code == "Enter")
|
return document.forms.buy_product.pcode.value += ev.code.substring(5)
|
||||||
document.forms.buy_product.submit()
|
} else if (ev.code == "Enter") {
|
||||||
|
if (document.forms.buy_product)
|
||||||
|
return document.forms.buy_product.submit()
|
||||||
|
if (document.forms.user_creation)
|
||||||
|
return document.forms.user_creation.submit()
|
||||||
|
} else if (ev.code.startsWith("Key") || ev.code == "Space") {
|
||||||
|
if (document.forms.user_creation)
|
||||||
|
return document.forms.user_creation.create_user.value += ev.key
|
||||||
|
} else if (ev.code == "Backspace") {
|
||||||
|
if (document.forms.user_creation)
|
||||||
|
return document.forms.user_creation.create_user.value = ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
103
style.css
103
style.css
|
@ -8,17 +8,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.trans {
|
.trans {
|
||||||
background: linear-gradient(
|
background: linear-gradient(#60d0fa50 0%,
|
||||||
#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%,
|
#f5acba50 79%,
|
||||||
#f5acba50 79%,
|
#60d0fa50 80%);
|
||||||
#60d0fa50 80%
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
@ -86,10 +84,6 @@ nav> :last-child {
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notif > * {
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.notif.error {
|
.notif.error {
|
||||||
background-color: rgb(118, 13, 13);
|
background-color: rgb(118, 13, 13);
|
||||||
}
|
}
|
||||||
|
@ -99,14 +93,14 @@ nav> :last-child {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* landing page */
|
/* landing page */
|
||||||
form.creation {
|
form#user_creation {
|
||||||
background-color: var(--b2);
|
background-color: var(--b2);
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
margin-top: 2em;
|
margin-top: 2em;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
form.creation>h3 {
|
form#user_creation>h3 {
|
||||||
margin: 5px;
|
margin: 5px;
|
||||||
margin-right: 2em;
|
margin-right: 2em;
|
||||||
}
|
}
|
||||||
|
@ -120,7 +114,7 @@ input[type="text"] {
|
||||||
min-width: 10em;
|
min-width: 10em;
|
||||||
}
|
}
|
||||||
|
|
||||||
form.creation>* {
|
form#user_creation>* {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-right: 1.5em;
|
margin-right: 1.5em;
|
||||||
}
|
}
|
||||||
|
@ -170,12 +164,12 @@ li {
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
padding-left: 1rem;
|
padding-left: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.userinfo {
|
.userinfo {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
padding: 1rem;
|
padding: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Amount selector user page */
|
/* Amount selector user page */
|
||||||
|
@ -284,12 +278,12 @@ tr:nth-child(2n) {
|
||||||
background-color: var(--b0);
|
background-color: var(--b0);
|
||||||
}
|
}
|
||||||
|
|
||||||
table.log > tbody {
|
table.log>tbody {
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
table.log > tbody > tr {
|
table.log>tbody>tr {
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
@ -303,39 +297,42 @@ input:not([type=submit]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@media print {
|
@media print {
|
||||||
nav, .container {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1 {
|
nav,
|
||||||
font-size: 2em;
|
.container {
|
||||||
text-decoration: underline;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.log:before {
|
h1 {
|
||||||
content: "Abrechnung";
|
font-size: 2em;
|
||||||
font-size: 2em;
|
text-decoration: underline;
|
||||||
text-decoration: underline;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
div.userlist:before {
|
table.log:before {
|
||||||
content: "User List, is still work in progress :/";
|
content: "Abrechnung";
|
||||||
clear: right;
|
font-size: 2em;
|
||||||
width: 100vw;
|
text-decoration: underline;
|
||||||
font-size: 2em;
|
}
|
||||||
text-decoration: underline;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.userlist a, ul {
|
div.userlist:before {
|
||||||
display: block;
|
content: "User List, is still work in progress :/";
|
||||||
width: 100%;
|
clear: right;
|
||||||
}
|
width: 100vw;
|
||||||
|
font-size: 2em;
|
||||||
|
text-decoration: underline;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
.userlist > li > a {
|
.userlist a,
|
||||||
width: 100%;
|
ul {
|
||||||
display: flex;
|
display: block;
|
||||||
}
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.userlist>li>a {
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
tr :last-child {
|
tr :last-child {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
Loading…
Reference in a new issue