configurable date

This commit is contained in:
Daniel O'Connell 2021-03-11 20:20:01 +01:00
parent c9c0b5f4bd
commit a72255cf30
3 changed files with 20 additions and 22 deletions

View File

@ -93,15 +93,7 @@
(map (partial prod/format-product settings)) (map (partial prod/format-product settings))
(into [:div {:class :products-sum}]))])]]]) (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] (defn calendar [days settings]
(->> days (->> days
(map (partial day settings)) (map (partial day settings))
(concat (when (settings :calendar-heading) (calendar-header settings)))
(into [:div {:class [:calendar :full-height]}]))) (into [:div {:class [:calendar :full-height]}])))

View File

@ -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`) (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 :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 :date-format (get-setting :date-format "%D %m/%d") ; the format of the days (D - name, d - day, m - month)
: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
:show-day-add-order (get-setting :show-day-add-order true) ; Show an add order button in each day :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 :show-order-time (get-setting :show-order-time false) ; display the time of each order
@ -51,6 +50,7 @@
(assoc db :settings settings)))) (assoc db :settings settings))))
(defn change-setting [key val] (defn change-setting [key val]
(prn key val)
(set-item! :settings (assoc (get-setting :settings) key val)) (set-item! :settings (assoc (get-setting :settings) key val))
(re-frame/dispatch [::change-setting key val])) (re-frame/dispatch [::change-setting key val]))
@ -59,11 +59,17 @@
handlers (condp = (:type opts) handlers (condp = (:type opts)
:checkbox {:defaultChecked (settings id) :checkbox {:defaultChecked (settings id)
:on-change #(change-setting id (-> % .-target .-checked parser))} :on-change #(change-setting id (-> % .-target .-checked parser))}
:radio {:defaultChecked (settings id)
:on-click #(change-setting id (-> % .-target .-value parser))}
{:defaultValue (settings id) {:defaultValue (settings id)
:on-change #(change-setting id (-> % .-target .-value parser))})] :on-change #(change-setting id (-> % .-target .-value parser))})]
[:div {:class :input-item} [:div {:class :input-item}
[:label {:for id} label] (when (and label (not (#{:checkbox :radio} (:type opts))))
[:input (merge {:name id :id id} handlers (dissoc opts :parser))]])) [: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 [] (defn settings-options []
[:div [:div
@ -72,14 +78,14 @@
(input :first-day-offset "o ile dni przesunąć niedziele w lewo" (input :first-day-offset "o ile dni przesunąć niedziele w lewo"
{:type :number :max 7 :min 0 :parser #(js/parseInt %)}) {: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)) {:default (clojure.string/join ", " (settings :day-names))
:parser #(clojure.string/split % #"\s*,\s*")}) :parser #(clojure.string/split % #"\s*,\s*")})
(input :calendar-heading "Pokaż nagłówek z dniami tygodnia" {:type :checkbox}) (input :calendar-heading "Pokaż nagłówek z dniami tygodnia" {:type :checkbox})
[:h3 "Ustawienia wyglądu poszczególnych dni"] [:h3 "Ustawienia wyglądu poszczególnych dni"]
(input :show-date "Pokaż date" {:type :checkbox}) (input :date-format "Format daty. %D wstawia nazwę dnia, %d dzień a %m miesiąc" {})
(input :show-day-name-with-date "Pokaż nazwę dnia" {:type :checkbox})
(input :show-day-add-order "Przycisk dodawania zamówienia" {:type :checkbox}) (input :show-day-add-order "Przycisk dodawania zamówienia" {:type :checkbox})
[:h3 "Ustawienia wyglądu zamówien"] [:h3 "Ustawienia wyglądu zamówien"]

View File

@ -1,4 +1,5 @@
(ns chicken-master.time (ns chicken-master.time
(:require [clojure.string :as str])
(:import [goog.date Date Interval])) (:import [goog.date Date Interval]))
(def settings (atom settings)) (def settings (atom settings))
@ -37,12 +38,11 @@
(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 (get @settings :show-date) (reduce (fn [date-str [from to]] (str/replace date-str from to))
(if (get @settings :show-day-name-with-date) (get @settings :date-format "%D %m/%d")
(str [["%d" (.getDate date)]
(->> date .getDay (nth (get @settings :day-names))) ["%m" (inc (.getMonth date))]
" " (inc (.getMonth date)) "/" (.getDate date)) ["%D" (->> date .getDay (nth (get @settings :day-names)))]]))
(str (inc (.getMonth date)) "/" (.getDate date)))))
(defn iso-date [date] (.toIsoString ^js/goog.date.Date date true)) (defn iso-date [date] (.toIsoString ^js/goog.date.Date date true))