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])]
|
selected-prods @(re-frame/subscribe [::subs/order-edit-products])]
|
||||||
[:div {}
|
[:div {}
|
||||||
[:label "co"]
|
[:label "co"]
|
||||||
(for [{product :prod amount :amount} selected-prods]
|
(for [[i {product :prod amount :amount}] (map-indexed vector selected-prods)]
|
||||||
(prod/product-item product amount available-prods))])
|
(prod/product-item product amount available-prods i))])
|
||||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/add-product])} "+"]]
|
[:button {:type :button :on-click #(re-frame/dispatch [::event/add-product])} "+"]]
|
||||||
js/console.log))
|
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)}
|
[:li {:class :order :key (gensym)}
|
||||||
[:div {:class :actions}
|
[:div {:class :actions}
|
||||||
[:button "O"]
|
[: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 "-"]]
|
[:button "-"]]
|
||||||
[:div {:class :who} who]
|
[:div {:class :who} who]
|
||||||
(if (settings :show-order-time)
|
(if (settings :show-order-time)
|
||||||
[:div {:class :when} (str (.getHours when) ":" (.getMinutes when))])
|
[:div {:class :when} hour])
|
||||||
(->> products
|
(->> products
|
||||||
(map prod/format-product)
|
(map prod/format-product)
|
||||||
(into [:ul {:class :products}]))])
|
(into [:ul {:class :products}]))])
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
:products [{:prod :eggs :amount 2}
|
:products [{:prod :eggs :amount 2}
|
||||||
{:prod :milk :amount 5}
|
{:prod :milk :amount 5}
|
||||||
{}]}
|
{}]}
|
||||||
:customers {1 {:who "mr.blobby (649 234 234)" :day "2020-10-10" :hour "02:12" :products {:eggs 2 :milk 3}}
|
:customers {1 {:id 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}}
|
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 {:who "johnny" :day "2020-10-10" :hour "02:12" :products {:eggs 5}}}
|
3 {:id 3 :who "johnny" :day "2020-10-10" :hour "02:12" :products {:eggs 5}}}
|
||||||
:days {"2020-09-05" [1 2 3]
|
:days {"2020-09-05" [1 2 3]
|
||||||
"2020-09-06" [1 2 3]
|
"2020-09-06" [1 2 3]
|
||||||
"2020-09-07" [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 ::hide-modal (fn [db _] (assoc db :order-edit {})))
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::edit-order
|
::edit-order
|
||||||
(fn [{customers :customers :as db} [_ date id]]
|
(fn [{customers :customers :as db} [_ day id]]
|
||||||
(assoc db :order-edit (merge (get customers id)
|
(assoc db :order-edit
|
||||||
{:show true :day date}))))
|
(-> 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 ::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]
|
(defn get-day [{:keys [days customers]} date]
|
||||||
{:date date
|
{:date date
|
||||||
:customers (->> (.toIsoString ^js/goog.date.Date date true)
|
:customers (->> date
|
||||||
|
time/iso-date
|
||||||
(get days)
|
(get days)
|
||||||
(map customers))})
|
(map customers))})
|
||||||
|
|
||||||
|
@ -4,15 +4,18 @@
|
|||||||
[chicken-master.html :as html]
|
[chicken-master.html :as html]
|
||||||
[chicken-master.events :as event]))
|
[chicken-master.events :as event]))
|
||||||
|
|
||||||
(defn product-item [what amount available]
|
(defn product-item [what amount available product-no]
|
||||||
[:div {:key (gensym)}
|
[:div {:key (gensym)}
|
||||||
[:div {:class :input-item}
|
[:div {:class :input-item}
|
||||||
[:label {:for :product} "co"]
|
[: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} "-"]
|
[:option {:value nil} "-"]
|
||||||
(for [product available]
|
(for [product available]
|
||||||
[:option {:key (gensym) :value product} (name product)])]]
|
[: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]]
|
(defn format-product [[product amount]]
|
||||||
[:li {:key (gensym) :class :product}
|
[:li {:key (gensym) :class :product}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
(re-frame/reg-sub ::available-products (fn [db] (-> db :products keys)))
|
(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 ::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-when (fn [db] (-> db :order-edit :hour)))
|
||||||
(re-frame/reg-sub ::order-edit-products (fn [db] (-> db :order-edit :products)))
|
(re-frame/reg-sub ::order-edit-products (fn [db] (-> db :order-edit :products)))
|
||||||
|
|
||||||
|
@ -32,3 +32,5 @@
|
|||||||
(str
|
(str
|
||||||
(->> date .getDay (nth (settings :day-names)))
|
(->> date .getDay (nth (settings :day-names)))
|
||||||
" " (.getMonth date) "/" (.getDate date)))
|
" " (.getMonth date) "/" (.getDate date)))
|
||||||
|
|
||||||
|
(defn iso-date [date] (.toIsoString ^js/goog.date.Date date true))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user