1
0
dwelling-home/web/mindflow_admin.templ

80 lines
2.9 KiB
Plaintext

package web
import "net/http"
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) {
@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>
}