Skip to content

Commit

Permalink
change the details of Edit form of session
Browse files Browse the repository at this point in the history
  • Loading branch information
humorless committed Aug 17, 2024
1 parent 7e64994 commit b1de69a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
66 changes: 46 additions & 20 deletions src/co/gaiwan/compass/html/sessions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -266,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 @@ -282,38 +284,52 @@
[:div.date-time :flex :gap-2]
([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 @@ -325,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

0 comments on commit b1de69a

Please sign in to comment.