feat(web/panettone): Add a Log Out link to the footer
Generalize the rendering of the footer nav, and add a Log Out button to the right. Change-Id: I107e2370fd8f12949218ecacb611649a48abd738 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1413 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
This commit is contained in:
parent
156c68698b
commit
3e033637b4
2 changed files with 53 additions and 18 deletions
|
|
@ -103,7 +103,18 @@
|
||||||
:border "none"
|
:border "none"
|
||||||
:cursor "pointer")
|
:cursor "pointer")
|
||||||
|
|
||||||
,@(button '(:and input (:= type "submit")))))
|
,@(button '(:and input (:= type "submit")))
|
||||||
|
|
||||||
|
(.form-link
|
||||||
|
((:and input (:= type "submit"))
|
||||||
|
:background-color "initial"
|
||||||
|
:color "inherit"
|
||||||
|
:padding 0
|
||||||
|
:text-decoration "underline")
|
||||||
|
|
||||||
|
((:and input (:= type "submit")
|
||||||
|
(:or :hover :active :focus))
|
||||||
|
:box-shadow 0 0 0 0))))
|
||||||
|
|
||||||
(defparameter issue-styles
|
(defparameter issue-styles
|
||||||
`((.issue-info
|
`((.issue-info
|
||||||
|
|
@ -145,13 +156,14 @@
|
||||||
:font-size "1.5rem"))
|
:font-size "1.5rem"))
|
||||||
|
|
||||||
(nav
|
(nav
|
||||||
:display :flex
|
:display "flex"
|
||||||
:color ,color/gray)
|
:color ,color/gray
|
||||||
|
:justify-content "space-between")
|
||||||
|
|
||||||
(footer
|
(footer
|
||||||
:border-top "1px" "solid" ,color/gray
|
:border-top "1px" "solid" ,color/gray
|
||||||
:padding-top "1rem"
|
:padding-top "1rem"
|
||||||
:margin-top "2rem"
|
:margin-top "1rem"
|
||||||
:color ,color/gray)
|
:color ,color/gray)
|
||||||
|
|
||||||
,@(button '.new-issue)
|
,@(button '.new-issue)
|
||||||
|
|
|
||||||
|
|
@ -174,16 +174,39 @@ updated issue"
|
||||||
|
|
||||||
(defvar *title* "Panettone")
|
(defvar *title* "Panettone")
|
||||||
|
|
||||||
|
(defvar *user* nil)
|
||||||
|
|
||||||
(setf (who:html-mode) :HTML5)
|
(setf (who:html-mode) :HTML5)
|
||||||
|
|
||||||
(defmacro render (&body body)
|
(defun render/footer-nav (&rest extra)
|
||||||
|
(who:with-html-output (*standard-output*)
|
||||||
|
(:footer
|
||||||
|
(:nav
|
||||||
|
(if (find (hunchentoot:request-uri*)
|
||||||
|
(list "/" "/issues/closed")
|
||||||
|
:test #'string=)
|
||||||
|
(who:htm (:span :class "placeholder"))
|
||||||
|
(who:htm (:a :href "/" "All Issues")))
|
||||||
|
(if *user*
|
||||||
|
(who:htm
|
||||||
|
(:form :class "form-link log-out"
|
||||||
|
:method "post"
|
||||||
|
:action "/logout"
|
||||||
|
(:input :type "submit" :value "Log Out")))
|
||||||
|
(who:htm
|
||||||
|
(:a :href "/login" "Log In")))))))
|
||||||
|
|
||||||
|
(defmacro render ((&key (footer t)) &body body)
|
||||||
`(who:with-html-output-to-string (*standard-output* nil :prologue t)
|
`(who:with-html-output-to-string (*standard-output* nil :prologue t)
|
||||||
(:head
|
(:head
|
||||||
(:title (who:esc *title*))
|
(:title (who:esc *title*))
|
||||||
(:link :rel "stylesheet" :type "text/css" :href "/main.css"))
|
(:link :rel "stylesheet" :type "text/css" :href "/main.css"))
|
||||||
(:body
|
(:body
|
||||||
(:div :class "content"
|
(:div
|
||||||
,@body))))
|
:class "content"
|
||||||
|
,@body
|
||||||
|
(when ,footer
|
||||||
|
(render/footer-nav))))))
|
||||||
|
|
||||||
(defun render/alert (message)
|
(defun render/alert (message)
|
||||||
"Render an alert box for MESSAGE, if non-null"
|
"Render an alert box for MESSAGE, if non-null"
|
||||||
|
|
@ -193,7 +216,7 @@ updated issue"
|
||||||
(who:htm (:div :class "alert" (who:esc message))))))
|
(who:htm (:div :class "alert" (who:esc message))))))
|
||||||
|
|
||||||
(defun render/login (&key message (original-uri "/"))
|
(defun render/login (&key message (original-uri "/"))
|
||||||
(render
|
(render (:footer nil)
|
||||||
(:div
|
(:div
|
||||||
:class "login-form"
|
:class "login-form"
|
||||||
(:header
|
(:header
|
||||||
|
|
@ -262,7 +285,7 @@ updated issue"
|
||||||
(format nil "~A comment~:p" num-comments))))))))))))))
|
(format nil "~A comment~:p" num-comments))))))))))))))
|
||||||
|
|
||||||
(defun render/index (&key issues)
|
(defun render/index (&key issues)
|
||||||
(render
|
(render ()
|
||||||
(:header
|
(:header
|
||||||
(:h1 "Issues")
|
(:h1 "Issues")
|
||||||
(:a
|
(:a
|
||||||
|
|
@ -275,7 +298,7 @@ updated issue"
|
||||||
(render/issue-list :issues issues))))
|
(render/issue-list :issues issues))))
|
||||||
|
|
||||||
(defun render/closed-issues (&key issues)
|
(defun render/closed-issues (&key issues)
|
||||||
(render
|
(render ()
|
||||||
(:header
|
(:header
|
||||||
(:h1 "Closed issues"))
|
(:h1 "Closed issues"))
|
||||||
(:main
|
(:main
|
||||||
|
|
@ -285,7 +308,7 @@ updated issue"
|
||||||
(render/issue-list :issues issues))))
|
(render/issue-list :issues issues))))
|
||||||
|
|
||||||
(defun render/new-issue (&optional message)
|
(defun render/new-issue (&optional message)
|
||||||
(render
|
(render ()
|
||||||
(:header
|
(:header
|
||||||
(:h1 "New Issue"))
|
(:h1 "New Issue"))
|
||||||
(:main
|
(:main
|
||||||
|
|
@ -324,7 +347,7 @@ updated issue"
|
||||||
(check-type issue issue)
|
(check-type issue issue)
|
||||||
(let ((issue-id (get-id issue))
|
(let ((issue-id (get-id issue))
|
||||||
(issue-status (status issue)))
|
(issue-status (status issue)))
|
||||||
(render
|
(render ()
|
||||||
(:header
|
(:header
|
||||||
(:h1 (who:esc (subject issue)))
|
(:h1 (who:esc (subject issue)))
|
||||||
(:div :class "issue-number"
|
(:div :class "issue-number"
|
||||||
|
|
@ -365,20 +388,16 @@ updated issue"
|
||||||
(who:esc (displayname author))
|
(who:esc (displayname author))
|
||||||
" at "
|
" at "
|
||||||
(who:esc (format-dottime (created-at comment)))))))))
|
(who:esc (format-dottime (created-at comment)))))))))
|
||||||
(render/new-comment (get-id issue))))))
|
(render/new-comment (get-id issue)))))))))
|
||||||
(:footer
|
|
||||||
(:nav (:a :href "/" "All Issues"))))))
|
|
||||||
|
|
||||||
(defun render/not-found (entity-type)
|
(defun render/not-found (entity-type)
|
||||||
(render
|
(render ()
|
||||||
(:h1 (who:esc entity-type) "Not Found")))
|
(:h1 (who:esc entity-type) "Not Found")))
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; HTTP handlers
|
;;; HTTP handlers
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
(defvar *user* nil)
|
|
||||||
|
|
||||||
(defun @auth (next)
|
(defun @auth (next)
|
||||||
(if-let ((*user* (hunchentoot:session-value 'user)))
|
(if-let ((*user* (hunchentoot:session-value 'user)))
|
||||||
(funcall next)
|
(funcall next)
|
||||||
|
|
@ -402,6 +421,10 @@ updated issue"
|
||||||
(hunchentoot:redirect (or original-uri "/")))
|
(hunchentoot:redirect (or original-uri "/")))
|
||||||
(render/login :message "Invalid credentials")))
|
(render/login :message "Invalid credentials")))
|
||||||
|
|
||||||
|
(defroute logout ("/logout" :method :post) ()
|
||||||
|
(hunchentoot:delete-session-value 'user)
|
||||||
|
(hunchentoot:redirect "/"))
|
||||||
|
|
||||||
(defroute index ("/" :decorators (@auth)) ()
|
(defroute index ("/" :decorators (@auth)) ()
|
||||||
(let ((issues (open-issues *p-system*)))
|
(let ((issues (open-issues *p-system*)))
|
||||||
(render/index :issues issues)))
|
(render/index :issues issues)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue