mirror of
https://github.com/mruwnik/chicken-master.git
synced 2025-06-08 21:34:43 +02:00
basic error handling msgs
This commit is contained in:
parent
5110316617
commit
3a340fd801
@ -12,7 +12,7 @@
|
|||||||
(defn add-customer [request] {:body (some-> request :body :name mocks/add-customer)})
|
(defn add-customer [request] {:body (some-> request :body :name mocks/add-customer)})
|
||||||
(defn delete-customer [id] {:body (mocks/delete-customer (edn/read-string id))})
|
(defn delete-customer [id] {:body (mocks/delete-customer (edn/read-string id))})
|
||||||
|
|
||||||
(defn get-products [_] (prn _){:body (mocks/get-all-products)})
|
(defn get-products [_] {:body (mocks/get-all-products)})
|
||||||
(defn save-products [request] {:body (some-> request :body mocks/save-stocks)})
|
(defn save-products [request] {:body (some-> request :body mocks/save-stocks)})
|
||||||
|
|
||||||
(defn get-orders [params] {:body {:orders (mocks/get-orders params)}})
|
(defn get-orders [params] {:body {:orders (mocks/get-orders params)}})
|
||||||
@ -22,7 +22,7 @@
|
|||||||
{:body (mocks/replace-order id body)}))
|
{:body (mocks/replace-order id body)}))
|
||||||
|
|
||||||
(defn delete-order [id] {:body (mocks/delete-order (edn/read-string id))})
|
(defn delete-order [id] {:body (mocks/delete-order (edn/read-string id))})
|
||||||
(defn set-order-state [id status] (prn "asd"){:body (mocks/order-state (edn/read-string id) status)})
|
(defn set-order-state [id status] {:body (mocks/order-state (edn/read-string id) status)})
|
||||||
|
|
||||||
(defn get-stock [params]
|
(defn get-stock [params]
|
||||||
{:body
|
{:body
|
||||||
|
@ -8,10 +8,6 @@
|
|||||||
[chicken-master.time :as time]))
|
[chicken-master.time :as time]))
|
||||||
|
|
||||||
(defn format-raw-order [{:strs [who who-id notes] :as raw-values}]
|
(defn format-raw-order [{:strs [who who-id notes] :as raw-values}]
|
||||||
(prn who who-id)
|
|
||||||
(prn (some->> @(re-frame/subscribe [::subs/available-customers])
|
|
||||||
(filter (comp #{who} :name))
|
|
||||||
first :id))
|
|
||||||
{:who {:name who
|
{:who {:name who
|
||||||
:id (if (prod/num-or-nil who-id)
|
:id (if (prod/num-or-nil who-id)
|
||||||
(prod/num-or-nil who-id)
|
(prod/num-or-nil who-id)
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
(defn- settings [key]
|
(defn- settings [key]
|
||||||
(get @(re-frame/subscribe [::subs/settings]) key))
|
(get @(re-frame/subscribe [::subs/settings]) key))
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::change-setting
|
::change-setting
|
||||||
(fn [{settings :settings :as db} [_ key val]]
|
(fn [{settings :settings :as db} [_ key val]]
|
||||||
@ -49,7 +48,6 @@
|
|||||||
|
|
||||||
(defn change-setting [key val]
|
(defn change-setting [key val]
|
||||||
(set-item! :settings (assoc (get-setting :settings) key val))
|
(set-item! :settings (assoc (get-setting :settings) key val))
|
||||||
(prn (get-setting :settings))
|
|
||||||
(re-frame/dispatch [::change-setting key val]))
|
(re-frame/dispatch [::change-setting key val]))
|
||||||
|
|
||||||
(defn input [id label opts]
|
(defn input [id label opts]
|
||||||
@ -86,7 +84,7 @@
|
|||||||
|
|
||||||
[:h3 "Ustawienia tyłu"]
|
[:h3 "Ustawienia tyłu"]
|
||||||
[:label {:for :http-dispatch} "re-frame http dispatcher"]
|
[:label {:for :http-dispatch} "re-frame http dispatcher"]
|
||||||
[:select {:id :http-dispatch :name :http-dispatch
|
[:select {:id :http-dispatch :name :http-dispatch :value (settings :http-dispatch)
|
||||||
:on-change #(change-setting :http-dispatch (-> % .-target .-value keyword))}
|
:on-change #(change-setting :http-dispatch (-> % .-target .-value keyword))}
|
||||||
[:option {:value :http} "client side mock"]
|
[:option {:value :http} "client side mock"]
|
||||||
[:option {:value :http-xhrio} "re-frame-http-fx"]]
|
[:option {:value :http-xhrio} "re-frame-http-fx"]]
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
(defn http-request [method endpoint & {:keys [params body on-success on-failure]
|
(defn http-request [method endpoint & {:keys [params body on-success on-failure]
|
||||||
:or {on-success ::process-fetched-days
|
:or {on-success ::process-fetched-days
|
||||||
on-failure ::failed-blah}}]
|
on-failure ::failed-request}}]
|
||||||
{:method method
|
{:method method
|
||||||
:uri (str (settings :backend-url) endpoint)
|
:uri (str (settings :backend-url) endpoint)
|
||||||
:headers {"Content-Type" "application/edn"
|
:headers {"Content-Type" "application/edn"
|
||||||
@ -22,7 +22,7 @@
|
|||||||
:params params
|
:params params
|
||||||
:response-format (edn/edn-response-format)
|
:response-format (edn/edn-response-format)
|
||||||
:on-success [on-success]
|
:on-success [on-success]
|
||||||
:on-fail [on-failure]})
|
:on-failure [on-failure]})
|
||||||
|
|
||||||
(defn http-get [endpoint params on-success]
|
(defn http-get [endpoint params on-success]
|
||||||
(http-request :get endpoint :params params :on-success on-success))
|
(http-request :get endpoint :params params :on-success on-success))
|
||||||
@ -55,6 +55,15 @@
|
|||||||
(fn [_ [_ id]]
|
(fn [_ [_ id]]
|
||||||
{(settings :http-dispatch) (http-request :delete (str "orders/" id))}))
|
{(settings :http-dispatch) (http-request :delete (str "orders/" id))}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::failed-request
|
||||||
|
(fn [db [_ response]]
|
||||||
|
(.error js/console (str response))
|
||||||
|
(js/alert "Wystąpił błąd")
|
||||||
|
(assoc db :loading false)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::move-order
|
::move-order
|
||||||
(fn [{{orders :orders start-date :start-date} :db} [_ id day]]
|
(fn [{{orders :orders start-date :start-date} :db} [_ id day]]
|
||||||
@ -171,25 +180,9 @@
|
|||||||
(assoc-if :products products)
|
(assoc-if :products products)
|
||||||
(assoc-if :customers customers)
|
(assoc-if :customers customers)
|
||||||
(assoc-if :orders orders))
|
(assoc-if :orders orders))
|
||||||
:dispatch [::process-fetched-days (group-by :day (vals orders))]
|
:dispatch [::scroll-weeks 0]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::update-product-stock
|
|
||||||
(fn [db [_ product i]]
|
|
||||||
(update-in db [:products product] + i)))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::set-stock-amount
|
|
||||||
(fn [db [_ product i]]
|
|
||||||
(prn i)
|
|
||||||
(assoc-in db [:products product] i)))
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::delete-product
|
|
||||||
(fn [db [_ product]]
|
|
||||||
(update db :products dissoc product)))
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save-stock
|
::save-stock
|
||||||
(fn [_ [_ products]]
|
(fn [_ [_ products]]
|
||||||
|
@ -40,31 +40,30 @@
|
|||||||
[:div {:class :product-item-edit :key (gensym)}
|
[:div {:class :product-item-edit :key (gensym)}
|
||||||
[:div {:class :input-item}
|
[:div {:class :input-item}
|
||||||
;; [:label {:for :product} "co"]
|
;; [:label {:for :product} "co"]
|
||||||
[:select {:name (str "product-" id) :id :product :defaultValue what
|
[:select {:name (str "product-" id) :id :product :defaultValue (some-> what name)
|
||||||
:on-change #(let [prod (-> % .-target .-value keyword)]
|
:on-change #(let [prod (-> % .-target .-value keyword)]
|
||||||
(swap! state assoc prod (+ (@state prod) (@state what)))
|
(if-not (= prod :-)
|
||||||
|
(swap! state assoc prod (+ (@state prod) (@state what))))
|
||||||
(swap! state dissoc what)
|
(swap! state dissoc what)
|
||||||
(if (not (contains? @state nil))
|
|
||||||
(swap! state assoc nil 0))
|
|
||||||
)}
|
)}
|
||||||
[:option {:value ""} "-"]
|
(for [product (-> available (conj what) sort vec (conj nil))]
|
||||||
(for [[product _] available]
|
[:option {:key (gensym) :value product} (if product (name product) "-")])]
|
||||||
[:option {:key (gensym) :value product} (name product)])]
|
|
||||||
]
|
]
|
||||||
(number-input (str "amount-" id) nil (@state what)
|
(number-input (str "amount-" id) nil (@state what)
|
||||||
#(do (swap! state assoc what (-> % .-target .-value num-or-nil))
|
#(swap! state assoc what (-> % .-target .-value num-or-nil)))
|
||||||
(prn @state)))
|
|
||||||
]))
|
]))
|
||||||
|
|
||||||
(defn products-edit [selected-prods & {:keys [available-prods getter-fn]
|
(defn products-edit [selected-prods & {:keys [available-prods getter-fn]
|
||||||
:or {available-prods @(re-frame/subscribe [::subs/available-products])}}]
|
:or {available-prods @(re-frame/subscribe [::subs/available-products])}}]
|
||||||
(let [state (reagent/atom (assoc selected-prods nil 0))]
|
(let [state (reagent/atom (or selected-prods {}))]
|
||||||
(fn []
|
(fn []
|
||||||
(let [products (->> @state
|
(let [available (remove (partial get @state) (keys available-prods))
|
||||||
|
products (->> @state
|
||||||
keys
|
keys
|
||||||
sort
|
sort
|
||||||
(map (partial product-item available-prods state))
|
(map (partial product-item available state))
|
||||||
(into [:div {:class :product-items-edit}]))]
|
(into [:div {:class :product-items-edit}]))
|
||||||
|
products (conj products (product-item available state nil))]
|
||||||
(if getter-fn
|
(if getter-fn
|
||||||
(conj products
|
(conj products
|
||||||
[:button {:type :button
|
[:button {:type :button
|
||||||
|
@ -1,30 +1,33 @@
|
|||||||
(ns chicken-master.stock
|
(ns chicken-master.stock
|
||||||
(:require
|
(:require
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[chicken-master.config :refer [settings]]
|
[reagent.core :as reagent]
|
||||||
[chicken-master.products :as prod]
|
[chicken-master.products :as prod]
|
||||||
[chicken-master.subs :as subs]
|
[chicken-master.subs :as subs]
|
||||||
[chicken-master.html :as html]
|
[chicken-master.html :as html]
|
||||||
[chicken-master.events :as event]))
|
[chicken-master.events :as event]))
|
||||||
|
|
||||||
|
(defn stock-form [stock]
|
||||||
|
(let [state (reagent/atom stock)]
|
||||||
|
(fn []
|
||||||
|
[:div
|
||||||
|
(for [[product amount] @state]
|
||||||
|
[:div {:key (gensym) :class :stock-product}
|
||||||
|
[:span {:class :product-name} product]
|
||||||
|
[:div {:class :stock-product-amount}
|
||||||
|
[:button {:type :button :on-click #(swap! state update product dec)} "-"]
|
||||||
|
(prod/number-input (name product) "" (or amount 0)
|
||||||
|
#(swap! state assoc product (-> % .-target .-value prod/num-or-nil)))
|
||||||
|
[:button {:type :button :on-click #(swap! state update product inc)} "+"]
|
||||||
|
[:button {:type :button :on-click #(swap! state dissoc product)} "x"]]])
|
||||||
|
[prod/item-adder :callback #(swap! state assoc (keyword %) 0) :button "+"]])))
|
||||||
|
|
||||||
(defn show-available []
|
(defn show-available []
|
||||||
(html/modal
|
(html/modal
|
||||||
:stock
|
:stock
|
||||||
[:div {:class :stock-modal}
|
[:div {:class :stock-modal}
|
||||||
[:h2 "Magazyn"]
|
[:h2 "Magazyn"]
|
||||||
(for [[product amount] @(re-frame/subscribe [::subs/available-products])]
|
[stock-form @(re-frame/subscribe [::subs/available-products])]]
|
||||||
[:div {:key (gensym) :class :stock-product}
|
|
||||||
[:span {:class :product-name} product]
|
|
||||||
[:div {:class :stock-product-amount}
|
|
||||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/update-product-stock product -1])} "-"]
|
|
||||||
(prod/number-input (name product) "" (or amount 0)
|
|
||||||
#(re-frame/dispatch [::event/set-stock-amount product (-> % .-target .-value prod/num-or-nil)]))
|
|
||||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/update-product-stock product 1])} "+"]
|
|
||||||
[:button {:type :button :on-click #(re-frame/dispatch [::event/delete-product product])} "x"]
|
|
||||||
]])
|
|
||||||
[prod/item-adder :callback #(re-frame/dispatch [::event/set-stock-amount % 0]) :button "+"]
|
|
||||||
]
|
|
||||||
;; On success
|
;; On success
|
||||||
(fn [form]
|
(fn [form]
|
||||||
(->> form
|
(->> form
|
||||||
|
Loading…
x
Reference in New Issue
Block a user