big work on env configs

This commit is contained in:
Sky Johnson 2025-06-04 09:24:33 -05:00
parent 1fc713ee27
commit 54819ec21d
8 changed files with 40 additions and 19 deletions

View File

@ -1,3 +1,3 @@
# Environment variables for Moonshark
# Generated automatically - you can edit this file
# env variables - generated automatically - you can edit this file
game_open=true

Binary file not shown.

View File

@ -1,3 +1,13 @@
<h1>Config</h1>
Hiiiii!
<form action="/admin/config" method="post">
<div>
<h4>Game Open</h4>
<input type="radio" name="game_open" id="open_yes" value="1" {{{ game_open_yes }}}>
<label for="open_yes">Open</label>
<input type="radio" name="game_open" id="open_no" value="0" {{{ game_open_no }}}>
<label for="open_no">Closed</label>
</div>
<button type="submit" class="ui button primary">Save</button>
</form>

View File

@ -37,7 +37,7 @@
</nav>
<section id="main">
{{{ content }}}
{{{ html }}}
</section>
</main>

View File

@ -1,24 +1,23 @@
local m = {}
function m.page(template, title)
local title = "Admin: "..title
if ctx.headers["X-DK-AJAX"] then
return {
html = fs_read("templates/admin/"..template),
title = title
}
function m.page(template, title, ext_data)
if not title then
local title = "Admin"
else
local title = "Admin: "..title
end
return send_html(render(
fs_read("templates/admin/layout.html"),
{
local data = table.merge({
title = title,
content = fs_read("templates/admin/"..template),
version = "v1.0.0",
build = "Moonlight"
}
))
}, ext_data or {})
data.html = render(fs_read("templates/admin/"..template), data)
if ctx.headers["X-DK-AJAX"] then return data end
return send_html(render(fs_read("templates/admin/layout.html"), data))
end
return m

BIN
moonshark

Binary file not shown.

View File

@ -1,2 +1,7 @@
local admin = require("admin")
return admin.page("config.html", "Config")
local game_open = env_get("game_open")
return admin.page("config.html", "Config", {
game_open_yes = game_open and "checked" or "",
game_open_no = not game_open and "checked" or ""
})

View File

@ -0,0 +1,7 @@
if to_bool(ctx.form.game_open) then
env_set("game_open", true)
else
env_set("game_open", false)
end
http_redirect("/admin/config")