1
0

Get categories from a DB.

This commit is contained in:
Alexander Andreev 2023-05-22 21:32:09 +04:00
parent 668075cbe2
commit 3b78aa64e2
Signed by: Arav
GPG Key ID: D22A817D95815393
3 changed files with 27 additions and 10 deletions

View File

@ -1,6 +1,7 @@
package http
import (
"log"
"math"
"net/http"
"strconv"
@ -52,19 +53,32 @@ func (h *Handlers) Mindflow(w http.ResponseWriter, r *http.Request) {
entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n")
}
web.Mindflow("/ Mindflow", posts, r, w)
categories, err := h.mindflowDB.Categories()
if err != nil {
log.Println(err)
return
}
web.Mindflow("/ Mindflow", posts, categories, r, w)
}
func (h *Handlers) MindflowAdmin(w http.ResponseWriter, r *http.Request) {
posts, err := h.mindflowDB.Posts()
if err != nil {
log.Println(err)
return
}
for _, entry := range posts {
entry.Body = strings.ReplaceAll(entry.Body, "\\n", "\n")
}
web.MindflowAdmin("/ Mindflow Administration", posts, r, w)
categories, err := h.mindflowDB.Categories()
if err != nil {
log.Println(err)
return
}
web.MindflowAdmin("/ Mindflow Administration", posts, categories, r, w)
}
func (h *Handlers) About(w http.ResponseWriter, r *http.Request) {

View File

@ -15,14 +15,14 @@ block nav
h1 Mindflow
block content
:go:func Mindflow(title string, posts []mindflow.Post, r *http.Request)
:go:func Mindflow(title string, posts []mindflow.Post, categories []mindflow.Category, r *http.Request)
p.center Here I post updates on websites and infrastructure, my very important opinions and thoughts no one asked for. If you'd like to subscribe to this bullshittery then #[a(href='rss.xml') RSS feed] at your service. :)
section#filter.hidden
p.center
button(name='all') All
button(name='update') Updates
button(name='diary') Diary
each category in categories
button(name=strings.ToLower(category.Name)) #{category.Name}
section
if (len(posts) > 0)
each post in posts

View File

@ -17,17 +17,20 @@ block nav
h1 Mindflow Admin
block content
:go:func MindflowAdmin(title string, posts []mindflow.Post, r *http.Request)
:go:func MindflowAdmin(title string, posts []mindflow.Post, categories []mindflow.Category, r *http.Request)
section
form(id='add' action='/api/mindflow', method='POST')
select(name='category' required='')
option(value='1' selected='') Update
option(value='2') Diary
option(value='0') New category
each category in categories
if (category.ID == 1)
option(value=category.ID selected='') #{category.Name}
else
option(value=category.ID) #{category.Name}
option(value='0') -- New category --
input(type='text', placeholder='New category name' name='new-category')
input(type='text', placeholder='Title' name='title' required='')
textarea(placeholder='Body post' name='body' required='')
textarea(placeholder='Body post' name!='body' required='')
button(type="submit") Add
section
if (len(posts) > 0)