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.db.event :as db.event]
|
||||||
[bbbg.event :as event]
|
[bbbg.event :as event]
|
||||||
[bbbg.handlers.core :refer [authenticated? page-response]]
|
[bbbg.handlers.core :refer [authenticated? page-response]]
|
||||||
|
[bbbg.meetup.import :refer [import-data!]]
|
||||||
[bbbg.util.display :refer [format-date]]
|
[bbbg.util.display :refer [format-date]]
|
||||||
|
[bbbg.util.time :as t]
|
||||||
[bbbg.views.flash :as flash]
|
[bbbg.views.flash :as flash]
|
||||||
[compojure.coercions :refer [as-uuid]]
|
[compojure.coercions :refer [as-uuid]]
|
||||||
[compojure.core :refer [context GET POST]]
|
[compojure.core :refer [context GET POST]]
|
||||||
[java-time :refer [local-date]]
|
[java-time :refer [local-date]]
|
||||||
[ring.util.response :refer [not-found redirect]]
|
[ring.util.response :refer [not-found redirect]]))
|
||||||
[bbbg.util.time :as t]))
|
|
||||||
|
|
||||||
(defn events-index [{:keys [events authenticated?]}]
|
(defn events-index [{:keys [events authenticated?]}]
|
||||||
[:div
|
[:div
|
||||||
|
@ -33,8 +34,19 @@
|
||||||
(if (= (t/->LocalDate (::event/date event))
|
(if (= (t/->LocalDate (::event/date event))
|
||||||
(local-date))
|
(local-date))
|
||||||
" Signed In"
|
" 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
|
(defn event-form
|
||||||
([] (event-form {}))
|
([] (event-form {}))
|
||||||
|
@ -58,7 +70,8 @@
|
||||||
(events-index {:events events
|
(events-index {:events events
|
||||||
:authenticated? (authenticated? request)}))))
|
:authenticated? (authenticated? request)}))))
|
||||||
|
|
||||||
(GET "/:id" [id :<< as-uuid]
|
(context "/:id" [id :<< as-uuid]
|
||||||
|
(GET "/" []
|
||||||
(if-let [event (db/fetch db
|
(if-let [event (db/fetch db
|
||||||
(-> {:select [:event.*]
|
(-> {:select [:event.*]
|
||||||
:from [:event]
|
:from [:event]
|
||||||
|
@ -68,6 +81,14 @@
|
||||||
(event-page {:event event}))
|
(event-page {:event event}))
|
||||||
(not-found "Event Not Found")))
|
(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]
|
(GET "/new" [date]
|
||||||
(page-response
|
(page-response
|
||||||
{:title "New Event"}
|
{:title "New Event"}
|
||||||
|
|
|
@ -99,7 +99,8 @@
|
||||||
(map (partial row->event-attendee
|
(map (partial row->event-attendee
|
||||||
{::event/id event-id
|
{::event/id event-id
|
||||||
:meetup-id->attendee-id meetup-id->attendee-id})
|
:meetup-id->attendee-id meetup-id->attendee-id})
|
||||||
rows))))
|
rows))
|
||||||
|
(count rows)))
|
||||||
|
|
||||||
;;; Spreadsheet columns:
|
;;; Spreadsheet columns:
|
||||||
;;;
|
;;;
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
[org.httpkit.server :as http-kit]
|
[org.httpkit.server :as http-kit]
|
||||||
[ring.middleware.flash :refer [wrap-flash]]
|
[ring.middleware.flash :refer [wrap-flash]]
|
||||||
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
|
[ring.middleware.keyword-params :refer [wrap-keyword-params]]
|
||||||
|
[ring.middleware.multipart-params :refer [wrap-multipart-params]]
|
||||||
[ring.middleware.params :refer [wrap-params]]
|
[ring.middleware.params :refer [wrap-params]]
|
||||||
[ring.middleware.session :refer [wrap-session]]
|
[ring.middleware.session :refer [wrap-session]]
|
||||||
[ring.middleware.session.cookie :refer [cookie-store]]
|
[ring.middleware.session.cookie :refer [cookie-store]]
|
||||||
|
@ -88,6 +89,7 @@
|
||||||
wrap-dynamic-auth
|
wrap-dynamic-auth
|
||||||
(wrap-discord-auth env)
|
(wrap-discord-auth env)
|
||||||
wrap-keyword-params
|
wrap-keyword-params
|
||||||
|
wrap-multipart-params
|
||||||
wrap-params
|
wrap-params
|
||||||
wrap-page-flash
|
wrap-page-flash
|
||||||
wrap-flash
|
wrap-flash
|
||||||
|
|
Loading…
Reference in a new issue