mirror of
https://github.com/mruwnik/chicken-master.git
synced 2025-06-08 21:34:43 +02:00
State on product update
This commit is contained in:
parent
4d566514a9
commit
fa69a0ed98
@ -22,20 +22,20 @@
|
||||
selected-prods @(re-frame/subscribe [::subs/order-edit-products])]
|
||||
[:div {}
|
||||
[:label "co"]
|
||||
(for [{product :prod amount :amount} selected-prods]
|
||||
(prod/product-item product amount available-prods))])
|
||||
(for [[i {product :prod amount :amount}] (map-indexed vector selected-prods)]
|
||||
(prod/product-item product amount available-prods i))])
|
||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/add-product])} "+"]]
|
||||
js/console.log))
|
||||
|
||||
(defn format-order [{:keys [id who when products]}]
|
||||
(defn format-order [{:keys [id who day hour products]}]
|
||||
[:li {:class :order :key (gensym)}
|
||||
[:div {:class :actions}
|
||||
[:button "O"]
|
||||
[:button {:on-click #(re-frame/dispatch [::event/edit-order when id])} "E"]
|
||||
[:button {:on-click #(re-frame/dispatch [::event/edit-order day id])} "E"]
|
||||
[:button "-"]]
|
||||
[:div {:class :who} who]
|
||||
(if (settings :show-order-time)
|
||||
[:div {:class :when} (str (.getHours when) ":" (.getMinutes when))])
|
||||
[:div {:class :when} hour])
|
||||
(->> products
|
||||
(map prod/format-product)
|
||||
(into [:ul {:class :products}]))])
|
||||
|
@ -8,9 +8,9 @@
|
||||
:products [{:prod :eggs :amount 2}
|
||||
{:prod :milk :amount 5}
|
||||
{}]}
|
||||
:customers {1 {:who "mr.blobby (649 234 234)" :day "2020-10-10" :hour "02:12" :products {:eggs 2 :milk 3}}
|
||||
2 {:who "da police (0118 999 881 999 119 725 123123 12 3123 123 )" :day "2020-10-10" :hour "02:12" :products {:eggs 12}}
|
||||
3 {:who "johnny" :day "2020-10-10" :hour "02:12" :products {:eggs 5}}}
|
||||
:customers {1 {:id 1 :who "mr.blobby (649 234 234)" :day "2020-10-10" :hour "02:12" :products {:eggs 2 :milk 3}}
|
||||
2 {:id 2 :who "da police (0118 999 881 999 119 725 123123 12 3123 123 )" :day "2020-10-10" :hour "02:12" :products {:eggs 12}}
|
||||
3 {:id 3 :who "johnny" :day "2020-10-10" :hour "02:12" :products {:eggs 5}}}
|
||||
:days {"2020-09-05" [1 2 3]
|
||||
"2020-09-06" [1 2 3]
|
||||
"2020-09-07" [1 2 3]
|
||||
|
@ -9,16 +9,28 @@
|
||||
(re-frame/reg-event-db ::hide-modal (fn [db _] (assoc db :order-edit {})))
|
||||
(re-frame/reg-event-db
|
||||
::edit-order
|
||||
(fn [{customers :customers :as db} [_ date id]]
|
||||
(assoc db :order-edit (merge (get customers id)
|
||||
{:show true :day date}))))
|
||||
(fn [{customers :customers :as db} [_ day id]]
|
||||
(assoc db :order-edit
|
||||
(-> customers
|
||||
(get id)
|
||||
(update :products (comp vec (partial map (partial zipmap [:prod :amount]))))
|
||||
(merge {:show true :day day})))))
|
||||
|
||||
(re-frame/reg-event-db ::add-product (fn [db _] (update-in db [:order-edit :products] conj {})))
|
||||
(re-frame/reg-event-db
|
||||
::selected-product
|
||||
(fn [db [_ product product-no]]
|
||||
(assoc-in db [:order-edit :products product-no :prod] product)))
|
||||
(re-frame/reg-event-db
|
||||
::changed-amount
|
||||
(fn [db [_ amount product-no]]
|
||||
(assoc-in db [:order-edit :products product-no :amount] amount)))
|
||||
|
||||
|
||||
(defn get-day [{:keys [days customers]} date]
|
||||
{:date date
|
||||
:customers (->> (.toIsoString ^js/goog.date.Date date true)
|
||||
:customers (->> date
|
||||
time/iso-date
|
||||
(get days)
|
||||
(map customers))})
|
||||
|
||||
|
@ -4,15 +4,18 @@
|
||||
[chicken-master.html :as html]
|
||||
[chicken-master.events :as event]))
|
||||
|
||||
(defn product-item [what amount available]
|
||||
(defn product-item [what amount available product-no]
|
||||
[:div {:key (gensym)}
|
||||
[:div {:class :input-item}
|
||||
[:label {:for :product} "co"]
|
||||
[:select {:name :product :id :product :defaultValue what}
|
||||
[:select {:name :product :id :product :defaultValue what
|
||||
:on-change #(re-frame/dispatch [::event/selected-product (-> % .-target .-value) product-no])}
|
||||
[:option {:value nil} "-"]
|
||||
(for [product available]
|
||||
[:option {:key (gensym) :value product} (name product)])]]
|
||||
(html/input :amount "ile" {:type :number :default amount :min 0})])
|
||||
(html/input :amount "ile"
|
||||
{:type :number :default amount :min 0
|
||||
:on-blur #(re-frame/dispatch [::event/changed-amount (-> % .-target .-value) product-no])})])
|
||||
|
||||
(defn format-product [[product amount]]
|
||||
[:li {:key (gensym) :class :product}
|
||||
|
@ -7,7 +7,7 @@
|
||||
(re-frame/reg-sub ::available-products (fn [db] (-> db :products keys)))
|
||||
|
||||
(re-frame/reg-sub ::show-edit-modal (fn [db] (-> db :order-edit :show)))
|
||||
(re-frame/reg-sub ::order-edit-who (fn [db] (-> db :order-edit :who)))
|
||||
(re-frame/reg-sub ::order-edit-who (fn [db] (println (:order-edit db)) (-> db :order-edit :who)))
|
||||
(re-frame/reg-sub ::order-edit-when (fn [db] (-> db :order-edit :hour)))
|
||||
(re-frame/reg-sub ::order-edit-products (fn [db] (-> db :order-edit :products)))
|
||||
|
||||
|
@ -32,3 +32,5 @@
|
||||
(str
|
||||
(->> date .getDay (nth (settings :day-names)))
|
||||
" " (.getMonth date) "/" (.getDate date)))
|
||||
|
||||
(defn iso-date [date] (.toIsoString ^js/goog.date.Date date true))
|
||||
|
Loading…
x
Reference in New Issue
Block a user