Skip to content

Commit

Permalink
Merge pull request #20 from GaiwanTeam/laurence/issue-8
Browse files Browse the repository at this point in the history
Create an Edit form for Session
  • Loading branch information
humorless authored Aug 17, 2024
2 parents 376c9cd + b1de69a commit 5735a33
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
71 changes: 49 additions & 22 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
(when (session/organizing? session user)
;; Only allow the event organizer to edit this event
[:<>
[:button {:hx-get (str "/sessions/" (:db/id session) "/edit")} "Edit"]
[:a {:href (str "/sessions/" (:db/id session) "/edit")}
[:button "Edit"]]
[:button {:hx-delete (str "/sessions/" (:db/id session))} "Delete"]])]
#_[:p.host "Organized by " organized]
#_[:ol (map attendee participants)]
Expand Down Expand Up @@ -265,6 +266,8 @@

;; Create / edit

(def xxx #time/zdt "2024-08-16T10:30+02:00[Europe/Brussels]")

(o/defstyled session-form :div
[#{:label :input} :block]
[:label
Expand All @@ -279,40 +282,54 @@
:flex
:gap-3]]
[:div.date-time :flex :gap-2]
([user]
([user session]
[:<>
[:h2 "Create Activity"]
(if session
[:h2 "Edit Activity"]
[:h2 "Create Activity"])
[:form {:method "POST" :action (url-for :session/save)
:enctype "multipart/form-data"}
[:input {:type "hidden" :name "organizer-id" :value (:db/id user)}]
[:label {:for "title"} "Name of Your Activity"]
[:input {:id "title" :name "title" :type "text"
:required true :min-length 2}]

[:input (cond-> {:id "title" :name "title" :type "text"
:required true :min-length 2}
session
(assoc :value (:session/title session)))]
[:label {:for "subtitle"} "Subtitle (optional)"]
[:input {:id "subtitle" :name "subtitle" :type "text"
:min-length 10}]

[:input (cond-> {:id "subtitle" :name "subtitle" :type "text"
:min-length 10}
session
(assoc :value (:session/subtitle session)))]
[:label {:for "start-time"} "Day and Start Time"]
[:div.date-time
[:input {:id "start-date" :name "start-date" :type "date"
:value (str (java.time.LocalDate/now))}]
[:input {:id "start-time" :name "start-time" :type "time"
:min "06:00" :max "23:00" :required true
:step 60}]]

:value (if session
(str (time/local-date (:session/time session)))
(str (java.time.LocalDate/now)))}]
[:input (cond->
{:id "start-time" :name "start-time" :type "time"
:min "06:00" :max "23:00" :required true
:step 60}
session
(assoc :value
(str (time/local-time (:session/time session)))))]]
[:label {:for "duration-time"} "Duration in minutes"]
[:input
{:id "duration-time" :name "duration-time"
:type "number"
:value 45}]
:value (if session
(session/duration (:session/duration session))
45)}]

[:label {:for "type"} "Type"]
[:select {:id "type" :name "type"}
[:option {:value "activity"} "Activity"]]

[:label {:for "location"} "Location"]
[:select {:id "location" :name "location"}
[:select (cond-> {:id "location" :name "location"}
session
(assoc :value
(name (get-in session [:session/location :db/ident]))))
[:option {:value "depot-main-stage"} "Het Depot - main stage"]
[:option {:value "depot-bar"} "Het Depot - Bar"]
[:option {:value "hal5-zone-a"} "Hal 5 - zone A"]
Expand All @@ -324,24 +341,34 @@
[:option {:value "hal5-long-table"} "Hal 5 - long table"]]

[:label {:for "capacity"} "How many people can you accomodate?"]
[:input {:id "capacity" :name "capacity" :type "number"
:min 2 :value 5 :required true}]
[:input (cond-> {:id "capacity" :name "capacity" :type "number"
:min 2 :value 5 :required true}
session
(assoc :value (:session/capacity session)))]

[:label {:for "description"} "Description (supports Markdown)"]
[:textarea {:id "description" :name "description"}]
[:textarea {:id "description" :name "description"}
(when session
(:session/description session))]

[:label {:for "ticket"}
[:input {:id "ticket" :name "ticket-required?" :type "checkbox"}]
[:input {:id "ticket" :name "ticket-required?" :type "checkbox"
:checked (:session/ticket-required? session)}]
"Requires Ticket?"]

[:label {:for "published"}
[:input {:id "published" :name "published?" :type "checkbox"}]
[:input {:id "published" :name "published?" :type "checkbox"
:checked (:session/published? session)}]
"Published/Visible?"]

(when session
[session-image+guage session user])
[:label {:for "image"} "Activity Image"]
[:input {:id "image" :name "image" :type "file" :accept "image/png, image/jpeg"}]

[:input {:type "submit" :value "Create"}]]]))
[:input {:type "submit" :value (if session
"Save"
"Create")}]]]))

(o/defstyled session-list+filters :div
([{:keys [user sessions filters]}]
Expand Down
9 changes: 7 additions & 2 deletions src/co/gaiwan/compass/model/session.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
;; :my-activities :my-activities,
;; :include-past :include-past}

(defn duration
"Input is like `PT45M`"
[duration-str]
(let [matcher (re-matcher #"\d+" duration-str)
minutes (re-find matcher)]
(parse-long minutes)))

(defmulti apply-filter (fn [_ _ k _] k))

(defmethod apply-filter :default [sessions _ _ _]
Expand Down Expand Up @@ -96,8 +103,6 @@
(< (count participants) capacity))
sessions))



(defn apply-filters [sessions user filters]
(def sessions sessions)
(def f filters)
Expand Down
17 changes: 15 additions & 2 deletions src/co/gaiwan/compass/routes/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@
[java-time.api :as time]))

(defn GET-session-new [req]
{:html/head [:title "Create new session"]
:html/body [session-html/session-form (:identity req)]})
(if-not (:identity req)
{:status 200
:headers {"HX-Trigger" "login-required"}} #_(util/redirect)
{:html/head [:title "Create new session"]
:html/body [session-html/session-form (:identity req)
nil]}))

(defn GET-session-edit [req]
(let [session-eid (parse-long (get-in req [:path-params :id]))]
{:html/body [session-html/session-form
(:identity req)
(db/pull '[* {:session/type [*]
:session/location [*]
:session.type [*]}] session-eid)]}))
(defn GET-session [req]
(let [session-eid (parse-long (get-in req [:path-params :id]))]
{:html/body [session-html/session-detail
Expand Down Expand Up @@ -160,6 +171,8 @@
:get {:handler GET-session}
:delete {:middleware [[response/wrap-requires-auth]]
:handler DELETE-session}}]
["/:id/edit"
{:get {:handler GET-session-edit}}]
["/:id/participate"
{:name :session/participate
:post {:middleware [[response/wrap-requires-auth]]
Expand Down

0 comments on commit 5735a33

Please sign in to comment.