feat(web/panettone): Add support for comments

Add a new-comment form and list all issue comments on the issue page

Change-Id: Ia74083484614ba0ca0f2879276f717f709d0f42f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1351
Tested-by: BuildkiteCI
Reviewed-by: eta <eta@theta.eu.org>
This commit is contained in:
Griffin Smith 2020-07-22 21:43:30 -04:00 committed by glittershark
parent d445136140
commit a107d8e335
2 changed files with 78 additions and 7 deletions

View file

@ -57,7 +57,28 @@
:outline "none"
(.issue-subject
:color ,color/primary)))))
:color ,color/primary)))
(.comment-count
:color ,color/gray)))
(defparameter comment-styles
`((.issue-comments
:border-top "1px" "solid" ,color/gray
:padding-top "1rem"
:padding-left "2rem"
(.comment-info
:color ,color/gray
:margin 0
:padding-top "1rem")
(.comment
:padding-top "1rem"
:padding-bottom "1rem"
:border-bottom "1px" "solid" ,color/gray
(p :margin 0)))))
(defparameter form-styles
`(((:or (:and input (:or (:= type "text")
@ -85,6 +106,7 @@
(defparameter styles
`(,@form-styles
,@issue-list-styles
,@comment-styles
(body
:font-family "sans-serif"

View file

@ -8,7 +8,8 @@
(defclass/std issue-comment ()
((body :type string)
(author-dn :type string)
(created-at :type local-time:timestamp)))
(created-at :type local-time:timestamp
:std (local-time:now))))
(defclass/std issue (cl-prevalence:object-with-id)
((subject body :type string :std "")
@ -234,7 +235,14 @@ updated issue"
(:span :class "issue-number"
(who:esc (format nil "#~A" issue-id)))
" - "
(created-by-at issue))))))))))
(created-by-at issue)
(let ((num-comments (length (issue-comments issue))))
(unless (zerop num-comments)
(who:htm
(:span :class "comment-count"
" - "
(who:esc
(format nil "~A comment~:p" num-comments)))))))))))))))
(defun render/new-issue ()
(render
@ -258,9 +266,18 @@ updated issue"
(:input :type "submit"
:value "Create Issue")))))
(comment
(format nil "foo: ~A" "foo")
)
(defun render/new-comment (issue-id)
(who:with-html-output (*standard-output*)
(:form
:class "new-comment"
:method "post"
:action (format nil "/issues/~A/comments" issue-id)
(:div
(:textarea :name "body"
:placeholder "Leave a comment"
:rows 5))
(:input :type "submit"
:value "Comment"))))
(defun render/issue (issue)
(check-type issue issue)
@ -271,7 +288,24 @@ updated issue"
(who:esc (format nil "#~A" (get-id issue)))))
(:main
(:p (created-by-at issue))
(:p (who:esc (body issue))))))
(:p (who:esc (body issue)))
(let ((comments (issue-comments issue)))
(who:htm
(:div
:class "issue-comments"
(dolist (comment comments)
(let ((author (author comment)))
(who:htm
(:div
:class "comment"
(:p (who:esc (body comment)))
(:p
:class "comment-info"
(:span :class "username"
(who:esc (displayname author))
" at "
(who:esc (format-dottime (created-at comment)))))))))
(render/new-comment (get-id issue))))))))
(defun render/not-found (entity-type)
(render
@ -326,6 +360,21 @@ updated issue"
(issue-not-found (_)
(render/not-found "Issue"))))
(defroute handle-create-comment
("/issues/:id/comments" :decorators (@auth)
:method :post)
(&path (id 'integer) &post body)
(handler-case
(progn
(cl-prevalence:execute-transaction
(add-comment *p-system* id
:body body
:author-dn (dn *user*)))
(cl-prevalence:snapshot *p-system*)
(hunchentoot:redirect (format nil "/issues/~A" id)))
(issue-not-found (_)
(render/not-found "Issue"))))
(defroute styles ("/main.css") ()
(setf (hunchentoot:content-type*) "text/css")
(apply #'lass:compile-and-write panettone.css:styles))