about summary refs log tree commit diff
path: root/web/panettone/src/panettone.lisp
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-28T22·29-0400
committerglittershark <grfn@gws.fyi>2020-07-31T02·05+0000
commit94796399e246d395811e33a5f2da50157881386c (patch)
treedd54b668a4405830e7d392ae63cfad1cfb0b0a00 /web/panettone/src/panettone.lisp
parent8e7ba41a3486a53de139486b75d72a349d13c415 (diff)
feat(web/panettone): Display issue history r/1510
Display the history of an issue (which currently is just opening and
closing) inline with the issue's comments on the issue show page

Change-Id: Id167bceef765cb4c24e86983d1dcd6624d0e5956
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1497
Tested-by: BuildkiteCI
Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to '')
-rw-r--r--web/panettone/src/panettone.lisp70
1 files changed, 46 insertions, 24 deletions
diff --git a/web/panettone/src/panettone.lisp b/web/panettone/src/panettone.lisp
index 4dc00db239..6be9cf659b 100644
--- a/web/panettone/src/panettone.lisp
+++ b/web/panettone/src/panettone.lisp
@@ -189,6 +189,36 @@
      (:input :type "submit"
              :value "Comment"))))
 
+(defgeneric render/issue-history-item (item))
+
+(defmethod render/issue-history-item ((comment model:issue-comment))
+  (who:with-html-output (*standard-output*)
+    (who:htm
+     (:li
+      :class "comment"
+      (:p (who:esc (body comment)))
+      (:p
+       :class "comment-info"
+       (:span :class "username"
+              (who:esc (displayname (author comment)))
+              " at "
+              (who:esc (format-dottime (created-at comment)))))))))
+
+(defmethod render/issue-history-item ((event model:issue-event))
+  (when (string= (field event) "STATUS")
+    (who:with-html-output (*standard-output*)
+      (let ((user (find-user-by-dn (acting-user-dn event))))
+        (who:htm
+         (:li
+          :class "event"
+          (who:esc (displayname user))
+          (who:esc
+           (switch ((new-value event) :test #'string=)
+             ("OPEN" " reopened ")
+             ("CLOSED" " closed ")))
+          " this issue at "
+          (who:esc (format-dottime (created-at event)))))))))
+
 (defun render/issue (issue)
   (check-type issue model:issue)
   (let ((issue-id (id issue))
@@ -220,22 +250,18 @@
                                    (:open "Close")
                                    (:closed "Reopen")))))))
        (:p (who:esc (body issue)))
-       (let ((comments (issue-comments issue)))
+       (let* ((comments (issue-comments issue))
+              (events (issue-events issue))
+              (history (merge 'list
+                              comments
+                              events
+                              #'local-time:timestamp<
+                              :key #'created-at)))
          (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)))))))))
+          (:ol
+           :class "issue-history"
+           (dolist (item history)
+             (render/issue-history-item item))
            (when *user*
              (render/new-comment (id issue))))))))))
 
@@ -321,14 +347,10 @@
 (defroute show-issue
     ("/issues/:id" :decorators (@auth-optional @handle-issue-not-found))
     (&path (id 'integer))
-  (handler-case
-      (let* ((issue (model:get-issue id))
-             (*title* (format nil "~A | Panettone"
-                              (subject issue))))
-        (render/issue issue))
-    (issue-not-found (_)
-      (declare (ignore _))
-      (render/not-found "Issue"))))
+  (let* ((issue (model:get-issue id))
+         (*title* (format nil "~A | Panettone"
+                          (subject issue))))
+    (render/issue issue)))
 
 (defroute handle-create-comment
     ("/issues/:id/comments"
@@ -356,7 +378,7 @@
 
 (defroute open-issue
     ("/issues/:id/open" :decorators (@auth)
-                         :method :put)
+                         :method :post)
     (&path (id 'integer))
   (model:set-issue-status id :open)
   (hunchentoot:redirect (format nil "/issues/~A" id)))