From a72255cf308f45b17ae9d3fe69bb8b6d61fe613c Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Thu, 11 Mar 2021 20:20:01 +0100 Subject: [PATCH] configurable date --- frontend/src/chicken_master/calendar.cljs | 8 -------- frontend/src/chicken_master/config.cljs | 22 ++++++++++++++-------- frontend/src/chicken_master/time.cljs | 12 ++++++------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/frontend/src/chicken_master/calendar.cljs b/frontend/src/chicken_master/calendar.cljs index 2b11135..9e232d3 100644 --- a/frontend/src/chicken_master/calendar.cljs +++ b/frontend/src/chicken_master/calendar.cljs @@ -93,15 +93,7 @@ (map (partial prod/format-product settings)) (into [:div {:class :products-sum}]))])]]]) -(defn calendar-header [settings] - (->> (settings :day-names) - cycle (drop (settings :first-day-offset)) - (take 7) - (map (fn [day] [:div {:class :day-header} day])) - (into []))) - (defn calendar [days settings] (->> days (map (partial day settings)) - (concat (when (settings :calendar-heading) (calendar-header settings))) (into [:div {:class [:calendar :full-height]}]))) diff --git a/frontend/src/chicken_master/config.cljs b/frontend/src/chicken_master/config.cljs index 59b9b68..dba4d4c 100644 --- a/frontend/src/chicken_master/config.cljs +++ b/frontend/src/chicken_master/config.cljs @@ -23,9 +23,8 @@ (def default-settings {:first-day-offset (get-setting :first-day-offset 1) ; which is the first day of the week (add the offset to `day-names`) :day-names (get-setting :day-names ["Niedz" "Pon" "Wt" "Śr" "Czw" "Pt" "Sob"]) ; how days should be displayed in the calendar view - :calendar-heading (get-setting :calendar-heading false) ; show a header with the names of days - :show-date (get-setting :show-date true) ; display the date for each day - :show-day-name-with-date (get-setting :show-day-name-with-date true) ; add the day name to each date + :date-format (get-setting :date-format "%D %m/%d") ; the format of the days (D - name, d - day, m - month) + :show-day-add-order (get-setting :show-day-add-order true) ; Show an add order button in each day :show-order-time (get-setting :show-order-time false) ; display the time of each order @@ -51,6 +50,7 @@ (assoc db :settings settings)))) (defn change-setting [key val] + (prn key val) (set-item! :settings (assoc (get-setting :settings) key val)) (re-frame/dispatch [::change-setting key val])) @@ -59,11 +59,17 @@ handlers (condp = (:type opts) :checkbox {:defaultChecked (settings id) :on-change #(change-setting id (-> % .-target .-checked parser))} + :radio {:defaultChecked (settings id) + :on-click #(change-setting id (-> % .-target .-value 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))]])) + (when (and label (not (#{:checkbox :radio} (:type opts)))) + [:label {:for id} label]) + [:input (merge {:name id :id id} handlers (dissoc opts :parser))] + (when (and label (#{:checkbox :radio} (:type opts))) + [:label {:for id} label]) + ])) (defn settings-options [] [:div @@ -72,14 +78,14 @@ (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" + (input :day-names "Nazwy 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 :date-format "Format daty. %D wstawia nazwę dnia, %d dzień a %m miesiąc" {}) + (input :show-day-add-order "Przycisk dodawania zamówienia" {:type :checkbox}) [:h3 "Ustawienia wyglądu zamówien"] diff --git a/frontend/src/chicken_master/time.cljs b/frontend/src/chicken_master/time.cljs index d9f12cb..70b7c14 100644 --- a/frontend/src/chicken_master/time.cljs +++ b/frontend/src/chicken_master/time.cljs @@ -1,4 +1,5 @@ (ns chicken-master.time + (:require [clojure.string :as str]) (:import [goog.date Date Interval])) (def settings (atom settings)) @@ -37,12 +38,11 @@ (defn today? "true when `d1` is today" [d1] (same-day? (js/Date.) d1)) (defn format-date [date] - (when (get @settings :show-date) - (if (get @settings :show-day-name-with-date) - (str - (->> date .getDay (nth (get @settings :day-names))) - " " (inc (.getMonth date)) "/" (.getDate date)) - (str (inc (.getMonth date)) "/" (.getDate date))))) + (reduce (fn [date-str [from to]] (str/replace date-str from to)) + (get @settings :date-format "%D %m/%d") + [["%d" (.getDate date)] + ["%m" (inc (.getMonth date))] + ["%D" (->> date .getDay (nth (get @settings :day-names)))]])) (defn iso-date [date] (.toIsoString ^js/goog.date.Date date true))