feat(panettone): Add nav to the top of the page as well

The absence of the navbar containing the "all issues" and "log out"
links from the top of the page has been a common complaint - initially I
disagreed, but after some time thinking about it I've come around. This
adds the same nav - with the "All Issues" link and the "Log Out" link -
to the top of every page, and also fixes a bug where query params would
prevent the "All Issues" link from being hidden on the "All Issues"
page, which looked especially weird when they were right next to each other.

Change-Id: I1d07175fa07aee057ddd140a6864d01342fbb7ef
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1868
Reviewed-by: kanepyork <rikingcoding@gmail.com>
Tested-by: BuildkiteCI
This commit is contained in:
Griffin Smith 2020-08-28 18:10:27 -04:00 committed by glittershark
parent 74a8c3d359
commit de851ec08b
3 changed files with 33 additions and 24 deletions

View file

@ -5,6 +5,7 @@ depot.nix.buildLisp.program {
deps = with depot.third_party.lisp; [ deps = with depot.third_party.lisp; [
cl-json cl-json
cl-ppcre
cl-who cl-who
drakma drakma
defclass-std defclass-std

View file

@ -41,6 +41,7 @@
:panettone.authentication) :panettone.authentication)
(:import-from :defclass-std :defclass/std) (:import-from :defclass-std :defclass/std)
(:import-from :alexandria :if-let :when-let :switch :alist-hash-table) (:import-from :alexandria :if-let :when-let :switch :alist-hash-table)
(:import-from :cl-ppcre :split)
(:import-from (:import-from
:panettone.model :panettone.model
:id :subject :body :author-dn :issue-id :status :created-at :id :subject :body :author-dn :issue-id :status :created-at

View file

@ -65,33 +65,35 @@
(setf (who:html-mode) :html5) (setf (who:html-mode) :html5)
(defun render/footer-nav () (defun render/nav ()
(who:with-html-output (*standard-output*) (who:with-html-output (*standard-output*)
(:footer (:nav
(:nav (if (find (car (split "\\?" (hunchentoot:request-uri*) :limit 2))
(if (find (hunchentoot:request-uri*) (list "/" "/issues/closed")
(list "/" "/issues/closed") :test #'string=)
:test #'string=) (who:htm (:span :class "placeholder"))
(who:htm (:span :class "placeholder")) (who:htm (:a :href "/" "All Issues")))
(who:htm (:a :href "/" "All Issues"))) (if *user*
(if *user* (who:htm
(who:htm (:form :class "form-link log-out"
(:form :class "form-link log-out" :method "post"
:method "post" :action "/logout"
:action "/logout" (:input :type "submit" :value "Log Out")))
(:input :type "submit" :value "Log Out"))) (who:htm
(who:htm (:a :href
(:a :href (format nil
(format nil "/login?original-uri=~A"
"/login?original-uri=~A" (drakma:url-encode (hunchentoot:request-uri*)
(drakma:url-encode (hunchentoot:request-uri*) :utf-8))
:utf-8)) "Log In"))))))
"Log In")))))))
(defun author (object) (defun author (object)
(find-user-by-dn (author-dn object))) (find-user-by-dn (author-dn object)))
(defmacro render ((&key (footer t)) &body body) (defmacro render ((&key
(footer t)
(header 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)
(:html (:html
:lang "en" :lang "en"
@ -103,9 +105,14 @@
(:body (:body
(:div (:div
:class "content" :class "content"
(when ,header
(who:htm
(render/nav)))
,@body ,@body
(when ,footer (when ,footer
(render/footer-nav))))))) (who:htm
(:footer
(render/nav)))))))))
(defun form-button (&key (defun form-button (&key
class class
@ -129,7 +136,7 @@
(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 (:footer nil) (render (:footer nil :header nil)
(:div (:div
:class "login-form" :class "login-form"
(:header (:header