mirror of
https://github.com/mruwnik/chicken-master.git
synced 2025-06-08 21:34:43 +02:00
settings view
This commit is contained in:
parent
0f21522a90
commit
17037abdb3
@ -1,7 +1,6 @@
|
|||||||
(ns chicken-master.calendar
|
(ns chicken-master.calendar
|
||||||
(:require
|
(:require
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[chicken-master.config :refer [settings]]
|
|
||||||
[chicken-master.subs :as subs]
|
[chicken-master.subs :as subs]
|
||||||
[chicken-master.html :as html]
|
[chicken-master.html :as html]
|
||||||
[chicken-master.products :as prod]
|
[chicken-master.products :as prod]
|
||||||
@ -27,7 +26,7 @@
|
|||||||
;; On success
|
;; On success
|
||||||
(fn [form] (re-frame/dispatch [::event/save-order (format-raw-order form)]))))
|
(fn [form] (re-frame/dispatch [::event/save-order (format-raw-order form)]))))
|
||||||
|
|
||||||
(defn format-order [{:keys [id who day hour notes products state]}]
|
(defn format-order [settings {:keys [id who day hour notes products state]}]
|
||||||
[:div {:class [:order state] :key (gensym)
|
[:div {:class [:order state] :key (gensym)
|
||||||
:draggable true
|
:draggable true
|
||||||
:on-drag-start #(-> % .-dataTransfer (.setData "text" id))}
|
:on-drag-start #(-> % .-dataTransfer (.setData "text" id))}
|
||||||
@ -48,10 +47,10 @@
|
|||||||
(if (and (settings :show-order-notes) notes)
|
(if (and (settings :show-order-notes) notes)
|
||||||
[:div {:class :notes} notes])
|
[:div {:class :notes} notes])
|
||||||
(->> products
|
(->> products
|
||||||
(map prod/format-product)
|
(map (partial prod/format-product settings))
|
||||||
(into [:div {:class :products}]))])
|
(into [:div {:class :products}]))])
|
||||||
|
|
||||||
(defn day [[date orders]]
|
(defn day [settings [date orders]]
|
||||||
[:div {:class [:day (when (-> date time/parse-date time/today?) :today)]
|
[:div {:class [:day (when (-> date time/parse-date time/today?) :today)]
|
||||||
:on-drag-over #(.preventDefault %)
|
:on-drag-over #(.preventDefault %)
|
||||||
:on-drop #(let [id (-> % .-dataTransfer (.getData "text") prod/num-or-nil)]
|
:on-drop #(let [id (-> % .-dataTransfer (.getData "text") prod/num-or-nil)]
|
||||||
@ -61,8 +60,8 @@
|
|||||||
[:div
|
[:div
|
||||||
[:div {:class :orders}
|
[:div {:class :orders}
|
||||||
(if (settings :hide-fulfilled-orders)
|
(if (settings :hide-fulfilled-orders)
|
||||||
(->> orders (remove (comp #{:fulfilled} :state)) (map format-order))
|
(->> orders (remove (comp #{:fulfilled} :state)) (map (partial format-order settings)))
|
||||||
(map format-order orders))
|
(map (partial format-order settings) orders))
|
||||||
(when (settings :show-day-add-order)
|
(when (settings :show-day-add-order)
|
||||||
[:button {:type :button
|
[:button {:type :button
|
||||||
:on-click #(re-frame/dispatch [::event/edit-order date])} "+"])
|
:on-click #(re-frame/dispatch [::event/edit-order date])} "+"])
|
||||||
@ -74,18 +73,19 @@
|
|||||||
(map :products)
|
(map :products)
|
||||||
(apply merge-with +)
|
(apply merge-with +)
|
||||||
(sort-by first)
|
(sort-by first)
|
||||||
(map prod/format-product)
|
(map (partial prod/format-product settings))
|
||||||
(into [:div {:class :products-sum}]))])]]])
|
(into [:div {:class :products-sum}]))])]]])
|
||||||
|
|
||||||
(defn calendar-header []
|
(defn calendar-header [settings]
|
||||||
(->> (:day-names settings)
|
(->> (settings :day-names)
|
||||||
cycle (drop (:first-day-offset settings))
|
cycle (drop (settings :first-day-offset))
|
||||||
(take 7)
|
(take 7)
|
||||||
(map (fn [day] [:div {:class :day-header} day]))
|
(map (fn [day] [:div {:class :day-header} day]))
|
||||||
(into [])))
|
(into [])))
|
||||||
|
|
||||||
(defn calendar [days]
|
(defn calendar [days settings]
|
||||||
|
(html/modal :settings [:div "asd"])
|
||||||
(->> days
|
(->> days
|
||||||
(map day)
|
(map (partial day settings))
|
||||||
(concat (when (settings :calendar-heading) (calendar-header)))
|
(concat (when (settings :calendar-heading) (calendar-header settings)))
|
||||||
(into [:div {:class [:calendar :full-height]}])))
|
(into [:div {:class [:calendar :full-height]}])))
|
||||||
|
@ -1,20 +1,78 @@
|
|||||||
(ns chicken-master.config)
|
(ns chicken-master.config
|
||||||
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[chicken-master.time :as time]
|
||||||
|
[chicken-master.subs :as subs]))
|
||||||
|
|
||||||
(def debug?
|
(def debug?
|
||||||
^boolean goog.DEBUG)
|
^boolean goog.DEBUG)
|
||||||
|
|
||||||
(def settings {:first-day-offset 1 ; which is the first day of the week (add the offset to `day-names`)
|
(def default-settings {:first-day-offset 1 ; which is the first day of the week (add the offset to `day-names`)
|
||||||
:day-names ["Niedz" "Pon" "Wt" "Śr" "Czw" "Pt" "Sob"] ; how day should be displayed in the calendar view
|
:day-names ["Niedz" "Pon" "Wt" "Śr" "Czw" "Pt" "Sob"] ; how days should be displayed in the calendar view
|
||||||
:calendar-heading false ; show a header with the names of days
|
:calendar-heading false ; show a header with the names of days
|
||||||
:show-date true ; display the date for each day
|
:show-date true ; display the date for each day
|
||||||
:show-day-name-with-date true ; add the day name to each date
|
:show-day-name-with-date true ; add the day name to each date
|
||||||
:show-day-add-order false ; Show an add order button in each day
|
:show-day-add-order false ; Show an add order button in each day
|
||||||
|
|
||||||
:show-order-time false ; display the time of each order
|
:show-order-time false ; display the time of each order
|
||||||
:show-order-notes true ; display notes
|
:show-order-notes true ; display notes
|
||||||
:editable-number-inputs false ; only allow number modifications in the edit modal
|
:editable-number-inputs false ; only allow number modifications in the edit modal
|
||||||
:hide-fulfilled-orders false
|
:hide-fulfilled-orders false
|
||||||
|
|
||||||
:http-dispatch :http;-xhrio
|
:http-dispatch :http;-xhrio
|
||||||
:backend-url "http://localhost:3000/"
|
:backend-url "http://localhost:3000/"
|
||||||
})
|
})
|
||||||
|
|
||||||
|
(defn- settings [key]
|
||||||
|
(get @(re-frame/subscribe [::subs/settings]) key))
|
||||||
|
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::change-setting
|
||||||
|
(fn [{settings :settings :as db} [_ key val]]
|
||||||
|
(let [settings (assoc settings key val)]
|
||||||
|
(time/update-settings settings)
|
||||||
|
(assoc db :settings settings))))
|
||||||
|
|
||||||
|
(defn change-setting [key val]
|
||||||
|
(re-frame/dispatch [::change-setting key val]))
|
||||||
|
|
||||||
|
(defn input [id label opts]
|
||||||
|
(let [parser (or (:parser opts) identity)
|
||||||
|
handlers (condp = (:type opts)
|
||||||
|
:checkbox {:defaultChecked (settings id)
|
||||||
|
:on-change #(change-setting id (-> % .-target .-checked parser))}
|
||||||
|
{:defaultValue (settings id)
|
||||||
|
:on-change #(change-setting id (-> % .-target .-value parser))})]
|
||||||
|
[:div {:class :input-item}
|
||||||
|
[:label {:for id} label]
|
||||||
|
[:input (merge {:name id :id id} handlers (dissoc opts :parser))]]))
|
||||||
|
|
||||||
|
(defn settings-options []
|
||||||
|
[:div
|
||||||
|
[:h3 "Ustawienia wyglądu kalendarza"]
|
||||||
|
(input :first-day-offset "o ile dni przesunąć niedziele w lewo"
|
||||||
|
{:type :number :max 7 :min 0 :parser #(js/parseInt %)})
|
||||||
|
(input :day-names "skróty nazw dni tygodnia"
|
||||||
|
{:default (clojure.string/join ", " (settings :day-names))
|
||||||
|
:parser #(clojure.string/split % #"\s*,\s*")})
|
||||||
|
(input :calendar-heading "Pokaż nagłówek z dniami tygodnia" {:type :checkbox})
|
||||||
|
|
||||||
|
[:h3 "Ustawienia wyglądu poszczególnych dni"]
|
||||||
|
(input :show-date "Pokaż date" {:type :checkbox})
|
||||||
|
(input :show-day-name-with-date "Pokaż nazwę dnia" {:type :checkbox})
|
||||||
|
(input :show-day-add-order "Przycisk dodawania zamówienia" {:type :checkbox})
|
||||||
|
|
||||||
|
[:h3 "Ustawienia wyglądu zamówien"]
|
||||||
|
(input :show-order-time "pokaż czas zamówienia" {:type :checkbox})
|
||||||
|
(input :show-order-notes "pokaż notki w zamówieniu" {:type :checkbox})
|
||||||
|
(input :editable-number-inputs "możliwość bezposredniej edycji" {:type :checkbox})
|
||||||
|
(input :hide-fulfilled-orders "ukryj wydane zamówienia" {:type :checkbox})
|
||||||
|
|
||||||
|
[:h3 "Ustawienia tyłu"]
|
||||||
|
[:label {:for :http-dispatch} "re-frame http dispatcher"]
|
||||||
|
[:select {:id :http-dispatch :name :http-dispatch
|
||||||
|
:on-change #(change-setting :http-dispatch (-> % .-target .-value keyword))}
|
||||||
|
[:option {:value :http} "client side mock"]
|
||||||
|
[:option {:value :http-xhrio} "re-frame-http-fx"]]
|
||||||
|
|
||||||
|
(input :backend-url "backend URL" {})])
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[chicken-master.db :as db]
|
[chicken-master.db :as db]
|
||||||
[chicken-master.time :as time]
|
[chicken-master.time :as time]
|
||||||
[chicken-master.config :refer [settings]]
|
[chicken-master.config :refer [settings default-settings]]
|
||||||
[day8.re-frame.http-fx]
|
[day8.re-frame.http-fx]
|
||||||
[ajax.edn :as edn]
|
[ajax.edn :as edn]
|
||||||
|
|
||||||
@ -33,7 +33,8 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::initialize-db
|
::initialize-db
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
{:db db/default-db
|
(time/update-settings default-settings)
|
||||||
|
{:db (assoc db/default-db :settings default-settings)
|
||||||
:fx [[:dispatch [::show-from-date (time/iso-date (time/today))]]
|
:fx [[:dispatch [::show-from-date (time/iso-date (time/today))]]
|
||||||
[:dispatch [::fetch-stock]]
|
[:dispatch [::fetch-stock]]
|
||||||
[:dispatch [::fetch-orders]]]}))
|
[:dispatch [::fetch-orders]]]}))
|
||||||
@ -99,7 +100,7 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::scroll-weeks
|
::scroll-weeks
|
||||||
(fn [{db :db} [_ offset]]
|
(fn [{db :db} [_ offset]]
|
||||||
{:fx [[:dispatch [::fetch-stock]]
|
{:fx [;[:dispatch [::fetch-stock]]
|
||||||
[:dispatch [::show-from-date (-> db
|
[:dispatch [::show-from-date (-> db
|
||||||
:start-date
|
:start-date
|
||||||
time/parse-date
|
time/parse-date
|
||||||
@ -111,10 +112,10 @@
|
|||||||
(fn [{:keys [start-date orders] :as db} [_ day]]
|
(fn [{:keys [start-date orders] :as db} [_ day]]
|
||||||
(let [day (or day start-date)
|
(let [day (or day start-date)
|
||||||
days (into #{} (time/get-weeks day 2))
|
days (into #{} (time/get-weeks day 2))
|
||||||
filtered-orders (->> orders vals (filter days))]
|
filtered-orders (->> orders vals (filter (comp days :day)) (group-by :day))]
|
||||||
(assoc db
|
(assoc db
|
||||||
:start-date day
|
:start-date day
|
||||||
:current-days (map #(vector % (get filtered-orders %)) days)))))
|
:current-days (map #(vector % (get filtered-orders %)) (sort days))))))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::fetch-orders
|
::fetch-orders
|
||||||
@ -152,7 +153,6 @@
|
|||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::process-stock
|
::process-stock
|
||||||
(fn [{db :db} [_ {:keys [products customers orders]}]]
|
(fn [{db :db} [_ {:keys [products customers orders]}]]
|
||||||
(prn products customers orders)
|
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc-if :products products)
|
(assoc-if :products products)
|
||||||
(assoc-if :customers customers)
|
(assoc-if :customers customers)
|
||||||
@ -182,6 +182,14 @@
|
|||||||
{:dispatch [::hide-modal :stock]
|
{:dispatch [::hide-modal :stock]
|
||||||
(settings :http-dispatch) (http-request :post "products" :body products :on-sucess ::process-stock)}))
|
(settings :http-dispatch) (http-request :post "products" :body products :on-sucess ::process-stock)}))
|
||||||
|
|
||||||
|
;; Settings
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::show-settings
|
||||||
|
(fn [{db :db} _]
|
||||||
|
{:db (assoc-in db [:settings :show] true)}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[chicken-master.config :refer [settings]]
|
|
||||||
[chicken-master.html :as html]
|
[chicken-master.html :as html]
|
||||||
[chicken-master.subs :as subs]
|
[chicken-master.subs :as subs]
|
||||||
[chicken-master.events :as event]))
|
[chicken-master.events :as event]))
|
||||||
@ -72,7 +71,7 @@
|
|||||||
products
|
products
|
||||||
)))))
|
)))))
|
||||||
|
|
||||||
(defn format-product [[product amount]]
|
(defn format-product [settings [product amount]]
|
||||||
[:div {:key (gensym) :class :product}
|
[:div {:key (gensym) :class :product}
|
||||||
[:span {:class :product-name} product]
|
[:span {:class :product-name} product]
|
||||||
(if (settings :editable-number-inputs)
|
(if (settings :editable-number-inputs)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
(:require [re-frame.core :as re-frame]))
|
(:require [re-frame.core :as re-frame]))
|
||||||
|
|
||||||
(re-frame/reg-sub ::name (fn [db] (:name db)))
|
(re-frame/reg-sub ::name (fn [db] (:name db)))
|
||||||
|
(re-frame/reg-sub ::settings (fn [db] (:settings db)))
|
||||||
|
|
||||||
(re-frame/reg-sub ::available-products (fn [db] (:products db)))
|
(re-frame/reg-sub ::available-products (fn [db] (:products db)))
|
||||||
(re-frame/reg-sub ::available-customers (fn [db] (:customers db)))
|
(re-frame/reg-sub ::available-customers (fn [db] (:customers db)))
|
||||||
(re-frame/reg-sub ::orders (fn [db] (:orders db)))
|
(re-frame/reg-sub ::orders (fn [db] (:orders db)))
|
||||||
@ -9,6 +11,7 @@
|
|||||||
(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 ::show-stock-modal (fn [db] (-> db :stock :show)))
|
(re-frame/reg-sub ::show-stock-modal (fn [db] (-> db :stock :show)))
|
||||||
(re-frame/reg-sub ::show-customers-modal (fn [db] (-> db :clients :show)))
|
(re-frame/reg-sub ::show-customers-modal (fn [db] (-> db :clients :show)))
|
||||||
|
(re-frame/reg-sub ::show-settings-modal (fn [db] (-> db :settings :show)))
|
||||||
|
|
||||||
(re-frame/reg-sub ::order-edit-who (fn [db] (-> db :order-edit :who)))
|
(re-frame/reg-sub ::order-edit-who (fn [db] (-> db :order-edit :who)))
|
||||||
(re-frame/reg-sub ::order-edit-notes (fn [db] (-> db :order-edit :notes)))
|
(re-frame/reg-sub ::order-edit-notes (fn [db] (-> db :order-edit :notes)))
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
(ns chicken-master.time
|
(ns chicken-master.time
|
||||||
(:require [chicken-master.config :refer [settings]])
|
|
||||||
(:import [goog.date DateTime Date Interval]))
|
(:import [goog.date DateTime Date Interval]))
|
||||||
|
|
||||||
|
(def settings (atom settings))
|
||||||
|
(defn update-settings [new-settings] (reset! settings new-settings))
|
||||||
|
|
||||||
(defn today [] (new Date))
|
(defn today [] (new Date))
|
||||||
|
|
||||||
(defn parse-date [date] (new Date (js/Date. date)))
|
(defn parse-date [date] (new Date (js/Date. date)))
|
||||||
@ -16,7 +18,7 @@
|
|||||||
(defn start-of-week
|
(defn start-of-week
|
||||||
"Get the start of the week for the given `date"
|
"Get the start of the week for the given `date"
|
||||||
[date]
|
[date]
|
||||||
(let [offset (mod (+ 7 (.getDay date) (- (settings :first-day-offset))) 7)]
|
(let [offset (mod (+ 7 (.getDay date) (- (get @settings :first-day-offset 0))) 7)]
|
||||||
(date-offset date (- offset))))
|
(date-offset date (- offset))))
|
||||||
|
|
||||||
(defn days-range
|
(defn days-range
|
||||||
@ -35,10 +37,10 @@
|
|||||||
(defn today? "true when `d1` is today" [d1] (same-day? (js/Date.) d1))
|
(defn today? "true when `d1` is today" [d1] (same-day? (js/Date.) d1))
|
||||||
|
|
||||||
(defn format-date [date]
|
(defn format-date [date]
|
||||||
(when (settings :show-date)
|
(when (get @settings :show-date)
|
||||||
(if (settings :show-day-name-with-date)
|
(if (get @settings :show-day-name-with-date)
|
||||||
(str
|
(str
|
||||||
(->> date .getDay (nth (settings :day-names)))
|
(->> date .getDay (nth (get @settings :day-names)))
|
||||||
" " (inc (.getMonth date)) "/" (.getDate date))
|
" " (inc (.getMonth date)) "/" (.getDate date))
|
||||||
(str (inc (.getMonth date)) "/" (.getDate date)))))
|
(str (inc (.getMonth date)) "/" (.getDate date)))))
|
||||||
|
|
||||||
|
@ -5,18 +5,25 @@
|
|||||||
[chicken-master.stock :as stock]
|
[chicken-master.stock :as stock]
|
||||||
[chicken-master.customers :as cust]
|
[chicken-master.customers :as cust]
|
||||||
[chicken-master.calendar :as cal]
|
[chicken-master.calendar :as cal]
|
||||||
[chicken-master.events :as event]))
|
[chicken-master.events :as event]
|
||||||
|
[chicken-master.html :as html]
|
||||||
|
[chicken-master.config :refer [settings-options]]))
|
||||||
|
|
||||||
|
(defn show-settings []
|
||||||
|
(html/modal :settings (settings-options)))
|
||||||
|
|
||||||
(defn main-panel []
|
(defn main-panel []
|
||||||
[:div {:class :full-height}
|
[:div {:class :full-height}
|
||||||
(cond
|
(cond
|
||||||
@(re-frame/subscribe [::subs/show-stock-modal]) (stock/show-available)
|
@(re-frame/subscribe [::subs/show-stock-modal]) (stock/show-available)
|
||||||
|
@(re-frame/subscribe [::subs/show-settings-modal]) (show-settings)
|
||||||
@(re-frame/subscribe [::subs/show-customers-modal]) (cust/show-customers)
|
@(re-frame/subscribe [::subs/show-customers-modal]) (cust/show-customers)
|
||||||
@(re-frame/subscribe [::subs/show-edit-modal]) (cal/edit-order))
|
@(re-frame/subscribe [::subs/show-edit-modal]) (cal/edit-order))
|
||||||
|
|
||||||
[:button {:id :show-stock-button :class :menu-button :on-click #(re-frame/dispatch [::event/show-stock])} "Magazyn"]
|
[:button {:id :show-stock-button :class :menu-button :on-click #(re-frame/dispatch [::event/show-stock])} "Magazyn"]
|
||||||
[:button {:id :show-clients-button :class :menu-button :on-click #(re-frame/dispatch [::event/show-customers])} "Klienci"]
|
[:button {:id :show-clients-button :class :menu-button :on-click #(re-frame/dispatch [::event/show-customers])} "Klienci"]
|
||||||
|
[:button {:id :show-clients-button :class :menu-button :on-click #(re-frame/dispatch [::event/show-settings])} "Ustawienia"]
|
||||||
|
;; (re-frame/dispatch [::event/show-settings])
|
||||||
|
|
||||||
[:button {:id :scroll-up-button :class [:menu-button :scroll-button] :on-click #(re-frame/dispatch [::event/scroll-weeks -2])} "^"]
|
[:button {:id :scroll-up-button :class [:menu-button :scroll-button] :on-click #(re-frame/dispatch [::event/scroll-weeks -2])} "^"]
|
||||||
|
|
||||||
@ -24,6 +31,6 @@
|
|||||||
[:button {:id :scroll-up :on-click #(re-frame/dispatch [::event/scroll-weeks -2])} "^"]
|
[:button {:id :scroll-up :on-click #(re-frame/dispatch [::event/scroll-weeks -2])} "^"]
|
||||||
[:button {:id :scroll-down :on-click #(re-frame/dispatch [::event/scroll-weeks 2])} "v"]]
|
[:button {:id :scroll-down :on-click #(re-frame/dispatch [::event/scroll-weeks 2])} "v"]]
|
||||||
|
|
||||||
(cal/calendar @(re-frame/subscribe [::subs/current-days]))
|
(cal/calendar @(re-frame/subscribe [::subs/current-days]) @(re-frame/subscribe [::subs/settings]))
|
||||||
[:button {:id :scroll-down-button :class [:menu-button :scroll-button] :on-click #(re-frame/dispatch [::event/scroll-weeks 2])} "v"]
|
[:button {:id :scroll-down-button :class [:menu-button :scroll-button] :on-click #(re-frame/dispatch [::event/scroll-weeks 2])} "v"]
|
||||||
])
|
])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user