lots of admin panel work

This commit is contained in:
Sky Johnson 2025-05-30 17:46:23 -05:00
parent 4b2a14a359
commit 59189689bd
14 changed files with 183 additions and 32 deletions

View File

@ -1,7 +1,8 @@
server = {
port = 3118,
debug = false,
http_logging = true
debug = true,
http_logging = true,
static_prefix = "public"
}
runner = {

Binary file not shown.

View File

@ -0,0 +1,3 @@
<h1>Config</h1>
Hiiiii!

View File

@ -3,33 +3,37 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }} - DK Admin</title>
<link rel="stylesheet" href="/css/admin.css">
<script src="/js/htmx.js"></script>
<title>{{ title }}</title>
<link rel="stylesheet" href="/public/css/buttons.css">
<link rel="stylesheet" href="/public/css/admin.css">
<script src="/public/scripts/jquery.js"></script>
</head>
<body>
<div id="admin-container">
<header>
<h1>Dragon Knight</h1>
<h3>Admin</h3>
<h3 id="subtitle">{{ title }}</h3>
</header>
<main>
<nav>
<a href="/admin" hx-get="/admin" hx-target="#main">Admin Home</a><br>
<a href="/">Game Home</a><br><br>
<div class="group">
<a class="ui button secondary" href="/admin">Dashboard</a>
<a class="ui button secondary" href="/">Back to Game</a>
</div>
<br>
<a href="/admin/main" hx-get="/admin/main" hx-target="#main">Main Settings</a><br>
<a href="/admin/news" hx-get="/admin/news" hx-target="#main">Add News Post</a><br>
<a href="/admin/users" hx-get="/admin/users" hx-target="#main">Edit Users</a><br><br>
<div class="group">
<a class="ui button secondary" href="/admin/config">Config</a>
<a class="ui button secondary" href="/admin/news">News</a>
<a class="ui button secondary" href="/admin/users">Users</a>
</div>
<br>
<a href="/admin/items" hx-get="/admin/items" hx-target="#main">Edit Items</a><br>
<a href="/admin/drops" hx-get="/admin/drops" hx-target="#main">Edit Drops</a><br>
<a href="/admin/towns" hx-get="/admin/towns" hx-target="#main">Edit Towns</a><br>
<a href="/admin/monsters" hx-get="/admin/monsters" hx-target="#main">Edit Monsters</a><br>
<a href="/admin/levels" hx-get="/admin/levels" hx-target="#main">Edit Levels</a><br>
<a href="/admin/spells" hx-get="/admin/spells" hx-target="#main">Edit Spells</a><br>
<div class="group">
<a class="ui button secondary" href="/admin/items">Items</a>
<a class="ui button secondary" href="/admin/drops">Drops</a>
<a class="ui button secondary" href="/admin/towns">Towns</a>
<a class="ui button secondary" href="/admin/monsters">Monsters</a>
<a class="ui button secondary" href="/admin/spells">Spells</a>
</div>
</nav>
<section id="main">
@ -43,5 +47,47 @@
<div>Version {{ version }} {{ build }}</div>
</footer>
</div>
<script>
function setupNavigation() {
const $navLinks = $('nav a')
$navLinks.on('click', function(e) {
e.preventDefault()
const url = this.getAttribute('href')
const $this = $(this)
$navLinks.removeClass('primary').addClass('secondary')
$this.removeClass('secondary').addClass('primary')
$.get({
url: url,
headers: { 'X-DK-AJAX': '1' },
dataType: 'json'
}).done(function(response) {
$('#main').html(response.html)
document.title = response.title
$('#subtitle').text(response.title)
history.pushState(null, '', url)
}).fail(function() {
$this.removeClass('primary').addClass('secondary')
})
})
}
$(document).ready(function() {
const currentPath = window.location.pathname;
const links = $('nav a').get().sort((a, b) => b.getAttribute('href').length - a.getAttribute('href').length)
for (const link of links) {
if (currentPath.startsWith(link.getAttribute('href'))) {
$(link).removeClass('secondary').addClass('primary')
break
}
}
setupNavigation()
})
</script>
</body>
</html>

24
libs/admin.lua Normal file
View File

@ -0,0 +1,24 @@
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
}
end
return send_html(render(
fs_read("templates/admin/layout.html"),
{
title = title,
content = fs_read("templates/admin/"..template),
version = "v1.0.0",
build = "Moonlight"
}
))
end
return m

BIN
moonshark

Binary file not shown.

View File

@ -18,10 +18,7 @@ body {
padding: 2rem;
color: white;
background-color: #121212;
}
h1, h2, h3, h4, h5 {
color: rgb(30, 30, 30);
background-image: url("/public/img/bg/darkstorm.jpg");
}
div#admin-container {
@ -40,10 +37,24 @@ main {
margin-bottom: 2rem;
}
main p:not(:last-of-type) {
margin-bottom: 1rem;
}
main > nav {
flex: 0 0 auto;
}
nav a.ui.button {
display: block;
text-align: left;
&:not(:last-of-type) { margin-bottom: 0.25rem; }
}
nav div.group:not(:last-of-type) {
margin-bottom: 2rem;
}
main > section {
flex: 1;
}

69
public/css/buttons.css Normal file
View File

@ -0,0 +1,69 @@
.ui.button {
cursor: pointer;
display: inline-block;
border: none;
font-size: 1rem;
background: #f7f8fa linear-gradient(rgba(255, 255, 255, 0), rgba(0, 0, 0, 0.1));
box-shadow: 0 1px 0 1px rgba(255, 255, 255, 0.3) inset, 0 0 0 1px #adb2bb inset;
color: #111111;
padding: 0.5rem 1rem 0.5rem;
text-align: center;
border-radius: 3px;
user-select: none;
text-decoration: none;
transition: opacity 0.1s ease, background-color 0.1s ease, color 0.1s ease, background 0.1s ease;
-webkit-tap-highlight-color: transparent;
&:hover {
background-color: #e0e0e0;
background-image: linear-gradient(rgba(255, 255, 255, 0), rgba(0, 0, 0, 0.1));
box-shadow: 0 1px 0 1px rgba(255, 255, 255, 0.3) inset, 0 0 0 1px #adb2bb inset;
color: rgba(0, 0, 0, 0.8);
}
&.badge {
font-size: 10px;
padding: 0.1rem 0.25rem;
}
&.primary {
background-color: #f4cc67;
background-image: linear-gradient(rgba(255, 255, 255, 0.15), rgba(0, 0, 0, 0.1));
box-shadow: 0px 1px 0px 0px rgba(255, 255, 255, 0.2) inset;
color: #111111;
border: 1px solid;
border-color: #C59F43 #AA8326 #957321;
&:hover {
background-color: #fac847;
border-color: #C59F43 #AA8326 #957321;
}
}
&.secondary {
background-color: #444c55;
color: #ffffff;
background-image: linear-gradient(rgba(255, 255, 255, 0.15), rgba(0, 0, 0, 0.1));
border: 1px solid;
border-color: #3D444C #2F353B #2C3137;
box-shadow: 0px 1px 0px 0px rgba(255, 255, 255, 0.2) inset;
&:hover {
background-color: #4e5964;
border-color: #32373E #24282D #212429;
}
}
&.danger {
background-color: #e57373;
background-image: linear-gradient(rgba(255, 255, 255, 0.15), rgba(139, 0, 0, 0.1));
box-shadow: 0px 1px 0px 0px rgba(255, 255, 255, 0.2) inset;
border: 1px solid;
border-color: #d32f2f #c62828 #b71c1c;
&:hover {
background-color: #d95c5c;
border-color: #b71c1c #a52727 #8e1f1f;
}
}
}

BIN
public/img/bg/darkstorm.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

BIN
public/img/bg/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
public/img/bg/snowstorm.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 KiB

2
public/scripts/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,2 @@
local admin = require("admin")
return admin.page("config.html", "Config")

View File

@ -1,9 +1,2 @@
return send_html(render(
fs_read("templates/admin/layout.html"),
{
title = "Home",
content = fs_read("templates/admin/home.html"),
version = "v1.0.0",
build = "Moonlight"
}
))
local admin = require("admin")
return admin.page("home.html", "Home")