src/views/blog-list-posts.lisp
(defpackage murja.views.blog-list-posts
(:use :cl :murja.newui.dispatcher :murja.newui)
(:local-nicknames (:json :com.inuoe.jzon))
(:documentation "This package implements endpoints and components for the admin's post list"))
(in-package :murja.views.blog-list-posts)
(deftab /blog/postadmin (:route "/blog/postadmin"
:require-login t
:title "Manage posts"
:needed-abilities (list "edit-post"))
(let ((titles (postmodern:query "SELECT title, created_at, tags, unlisted, hidden
FROM blog.Post
ORDER BY created_at DESC" :array-hash))) ;; :array-hash due to me not caring enough to model this blog.Post Light as a clos class
(component :div (:class "vertical-flex-container")
(map 'list
(lambda (title)
(c :div (:class "title-flex-container")
(c :span (:class "post-admin-title")
(gethash "title" title)
" - "
(gethash "created_at" title))
(c :div (:class "post-admin-title")
(c :label ()
(if (gethash "hidden" title)
(c :input (:type "checkbox"
:checked t ))
(c :input (:type "checkbox"
:unchecked)))
"Hidden")
(c :label ()
(if (gethash "unlisted" title)
(c :input (:type "checkbox"
:checked t ))
(c :input (:type "checkbox"
:unchecked)))
"Unlisted"))
(c :a (:href "/") "Edit")
(component :div (:class "post-admin-title")
(concatenate 'list
(list (c :h3 () "Tags"))
(map 'list (lambda (tag)
(c :a (:href (format nil "/blog/tags/~a" tag) :style "display: block") tag))
(json:parse (gethash "tags" title)))))))
titles))))