1
0

Ported mindflow admin page to Templ.

This commit is contained in:
Alexander Andreev 2024-07-13 19:58:12 +04:00
parent f59da2a76e
commit 6726a7989c
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34
2 changed files with 72 additions and 67 deletions

View File

@ -3,7 +3,78 @@ package web
import "net/http" import "net/http"
import "git.arav.su/Arav/dwelling-home/pkg/mindflow" import "git.arav.su/Arav/dwelling-home/pkg/mindflow"
import "git.arav.su/Arav/dwelling-home/pkg/util"
import "strconv"
import "time"
templ MindflowAdmin(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) { templ MindflowAdmin(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) {
@base("Mindflow Administration", "", "", "/mindflow/admin", r, nil) @base("Mindflow Administration", "", "", "/mindflow/admin", r, mindflowAdminHead()) {
<section>
<h2>Manage categories</h2>
<form id="manage-categories">
<select name="category" required>
for _, c := range categories {
<option value={ strconv.FormatInt(c.ID, 10) }>{ c.Name }</option>
}
<option value="0">-- New category --</option>
</select>
<input type="text" name="name" placeholder="New category name"/>
<button type="submit" name="add">Add</button>
<button type="submit" name="edit">Edit</button>
<button type="submit" name="delete">Delete</button>
</form>
</section>
<section>
<h2>Create a new post</h2>
<form id="add" action="/api/mindflow" method="POST">
<select name="category" required>
for _, c := range categories {
<option value={ strconv.FormatInt(c.ID, 10) }>{ c.Name }</option>
}
</select>
<input type="text" name="title" placeholder="Title" required/>
<input type="text" name="url" placeholder="URL"/>
<textarea name="body" placeholder="Body post" required></textarea>
<button type="submit">Add</button>
</form>
</section>
<section>
for _, post := range posts {
<article id={ post.PostID() }>
<header>
<a href="#{ templ.SafeURL(post.PostID()) }"><h3>{ post.Category.Name }: { post.Title }</h3></a>
</header>
<form class="edit">
<select name="category" required>
for _, c := range categories {
if c.ID == post.Category.ID {
<option value={ strconv.FormatInt(c.ID, 10) } selected>{ c.Name }</option>
} else {
<option value={ strconv.FormatInt(c.ID, 10) }>{ c.Name }</option>
}
}
</select>
<input type="hidden" name="post-id" value={ strconv.FormatInt(post.ID, 10) }/>
<input type="text" name="title" placeholder="Title" required/>
<input type="text" name="url" placeholder="URL" value={ post.URL }>
<textarea name="body" placeholder="Body post" required>@templ.Raw(post.Body)</textarea>
<button name="edit-post">Edit</button>
<button name="delete-post">Delete</button>
</form>
<footer>
<time datetime={ util.ToClientTimezone(post.Date, r).Format(time.RFC3339) }>{ util.ToClientTimezone(post.Date, r).Format(time.RFC1123) }</time>
</footer>
</article>
}
if len(posts) == 0 {
<p class="center">Nothing? There must be some... Looks like database went down.</p>
}
</section>
}
}
templ mindflowAdminHead() {
<link rel="stylesheet" href="/assets/css/mindflow.css">
<link rel="stylesheet" href="/assets/css/mindflow_admin.css">
<script src="/assets/js/mindflow_admin.js" defer></script>
} }

View File

@ -1,66 +0,0 @@
extends base.pug
block meta_description
meta(name='description' content='Here I will post updates on my infrastructure, my very important opinions and thoughts.')
block append head
link(href='/assets/css/mindflow.css' rel='stylesheet')
link(href='/assets/css/mindflow_admin.css' rel='stylesheet')
script(src='/assets/js/mindflow_admin.js' defer='')
block nav
a(href='/') Home
a(href='/stuff') Stuff
a(href='/mindflow') Mindflow
a(href='/about') About
a(href='/guestbook') Guestbook
h1 Mindflow Admin
block content
:go:func MindflowAdmin(title string, posts []mindflow.Post, categories []mindflow.Category, r *http.Request)
section
h2 Manage categories
form(id='manage-categories')
select(name='category' required='')
each category in categories
option(value=category.ID) #{category.Name}
option(value='0') -- New category --
input(type='text', placeholder='New category name' name='name')
button(type="submit" name="add") Add
button(type="submit" name="edit") Edit
button(type="submit" name="delete") Delete
section
h2 Create a new post
form(id='add' action='/api/mindflow', method='POST')
select(name='category' required='')
each category in categories
option(value=category.ID) #{category.Name}
input(type='text', placeholder='Title' name='title' required='')
input(type='text', placeholder='URL' name='url')
textarea(placeholder='Body post' name='body' required='')
button(type="submit") Add
section
if (len(posts) > 0)
each post in posts
article(id=post.PostID())
header
a(href=`#${post.PostID()}`)
h3= post.Category.Name + ": " + post.Title
form.edit
select(name='category' required='')
each category in categories
if (category.ID == post.Category.ID)
option(value=category.ID selected='') #{category.Name}
else
option(value=category.ID) #{category.Name}
input(type='hidden', name='post-id' value=post.ID)
input(type='text', placeholder='Title' name='title' value=post.Title required='')
input(type='text', placeholder='URL' name='url' value=post.URL)
textarea(placeholder='Body post' name='body' required='')!= post.Body
button(name='edit-post') Edit
button(name='delete-post') Delete
footer
time(datetime=util.ToClientTimezone(post.Date, r))= util.ToClientTimezone(post.Date, r).Format(time.RFC1123)
else
p.center Nothing? There must be some... Looks like database went down.