2024-06-19 01:08:05 +04:00
|
|
|
package web
|
|
|
|
|
|
|
|
import "net/http"
|
|
|
|
|
|
|
|
import "git.arav.su/Arav/dwelling-home/pkg/mindflow"
|
2024-07-13 19:58:12 +04:00
|
|
|
import "git.arav.su/Arav/dwelling-home/pkg/util"
|
|
|
|
import "strconv"
|
|
|
|
import "time"
|
2024-06-19 01:08:05 +04:00
|
|
|
|
|
|
|
templ MindflowAdmin(posts []mindflow.Post, categories []mindflow.Category, r *http.Request) {
|
2024-07-13 19:58:12 +04:00
|
|
|
@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>
|
|
|
|
}
|
2024-06-19 01:08:05 +04:00
|
|
|
}
|
2024-07-13 19:58:12 +04:00
|
|
|
|
|
|
|
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>
|
|
|
|
}
|