feat(grfn/bbbg): Add an import attendees button to event page
Change-Id: Iab69500f927a3f5a70d294ece3f95891853b63c3 Reviewed-on: https://cl.tvl.fyi/c/depot/+/4572 Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi> Autosubmit: grfn <grfn@gws.fyi>
This commit is contained in:
parent
b2ded921a4
commit
6035a8ea9c
3 changed files with 38 additions and 14 deletions
|
@ -4,13 +4,14 @@
|
|||
[bbbg.db.event :as db.event]
|
||||
[bbbg.event :as event]
|
||||
[bbbg.handlers.core :refer [authenticated? page-response]]
|
||||
[bbbg.meetup.import :refer [import-data!]]
|
||||
[bbbg.util.display :refer [format-date]]
|
||||
[bbbg.util.time :as t]
|
||||
[bbbg.views.flash :as flash]
|
||||
[compojure.coercions :refer [as-uuid]]
|
||||
[compojure.core :refer [context GET POST]]
|
||||
[java-time :refer [local-date]]
|
||||
[ring.util.response :refer [not-found redirect]]
|
||||
[bbbg.util.time :as t]))
|
||||
[ring.util.response :refer [not-found redirect]]))
|
||||
|
||||
(defn events-index [{:keys [events authenticated?]}]
|
||||
[:div
|
||||
|
@ -33,8 +34,19 @@
|
|||
(if (= (t/->LocalDate (::event/date event))
|
||||
(local-date))
|
||||
" Signed In"
|
||||
(str " Attendee" (when-not (= 1 (:num-attendees event)) "s")))]
|
||||
]])
|
||||
(str " Attendee" (when-not (= 1 (:num-attendees event)) "s")))]]
|
||||
[:div
|
||||
[:form {:method :post
|
||||
:action (str "/events/" (::event/id event) "/attendees")
|
||||
:enctype "multipart/form-data"}
|
||||
[:div.form-group
|
||||
[:label "Import Attendee List"
|
||||
[:br]
|
||||
[:input {:type :file
|
||||
:name :attendees}]]]
|
||||
[:div.form-group
|
||||
[:input {:type :submit
|
||||
:value "Import"}]]]]])
|
||||
|
||||
(defn event-form
|
||||
([] (event-form {}))
|
||||
|
@ -58,15 +70,24 @@
|
|||
(events-index {:events events
|
||||
:authenticated? (authenticated? request)}))))
|
||||
|
||||
(GET "/:id" [id :<< as-uuid]
|
||||
(if-let [event (db/fetch db
|
||||
(-> {:select [:event.*]
|
||||
:from [:event]
|
||||
:where [:= :event.id id]}
|
||||
(db.event/with-stats)))]
|
||||
(page-response
|
||||
(event-page {:event event}))
|
||||
(not-found "Event Not Found")))
|
||||
(context "/:id" [id :<< as-uuid]
|
||||
(GET "/" []
|
||||
(if-let [event (db/fetch db
|
||||
(-> {:select [:event.*]
|
||||
:from [:event]
|
||||
:where [:= :event.id id]}
|
||||
(db.event/with-stats)))]
|
||||
(page-response
|
||||
(event-page {:event event}))
|
||||
(not-found "Event Not Found")))
|
||||
|
||||
(POST "/attendees" [attendees]
|
||||
(let [num-imported (import-data! db id (:tempfile attendees))]
|
||||
(-> (redirect (str "/events/" id))
|
||||
(flash/add-flash
|
||||
#:flash{:type :success
|
||||
:message (format "Successfully imported %d attendees"
|
||||
num-imported)})))))
|
||||
|
||||
(GET "/new" [date]
|
||||
(page-response
|
||||
|
|
|
@ -99,7 +99,8 @@
|
|||
(map (partial row->event-attendee
|
||||
{::event/id event-id
|
||||
:meetup-id->attendee-id meetup-id->attendee-id})
|
||||
rows))))
|
||||
rows))
|
||||
(count rows)))
|
||||
|
||||
;;; Spreadsheet columns:
|
||||
;;;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
[org.httpkit.server :as http-kit]
|
||||
[ring.middleware.flash :refer [wrap-flash]]
|
||||
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
|
||||
[ring.middleware.multipart-params :refer [wrap-multipart-params]]
|
||||
[ring.middleware.params :refer [wrap-params]]
|
||||
[ring.middleware.session :refer [wrap-session]]
|
||||
[ring.middleware.session.cookie :refer [cookie-store]]
|
||||
|
@ -88,6 +89,7 @@
|
|||
wrap-dynamic-auth
|
||||
(wrap-discord-auth env)
|
||||
wrap-keyword-params
|
||||
wrap-multipart-params
|
||||
wrap-params
|
||||
wrap-page-flash
|
||||
wrap-flash
|
||||
|
|
Loading…
Reference in a new issue