diff --git a/frontend/src/uxbox/main/data/history.cljs b/frontend/src/uxbox/main/data/history.cljs index 866440d7ca..5c246c6dc5 100644 --- a/frontend/src/uxbox/main/data/history.cljs +++ b/frontend/src/uxbox/main/data/history.cljs @@ -2,127 +2,155 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2016-2017 Andrey Antukh +;; Copyright (c) 2016-2019 Andrey Antukh (ns uxbox.main.data.history - (:require [beicon.core :as rx] - [potok.core :as ptk] - [uxbox.main.data.pages :as udp] - [uxbox.main.repo :as rp] - [uxbox.util.data :refer [replace-by-id - index-by]])) + (:require + [beicon.core :as rx] + [cljs.spec.alpha :as s] + [potok.core :as ptk] + [uxbox.main.data.pages :as udp] + [uxbox.main.repo :as rp] + [uxbox.util.data :refer [replace-by-id index-by]] + [uxbox.util.spec :as us])) -;; TODO: this need refactor (completely broken) +;; --- Schema + +(s/def ::pinned ::us/bool) +(s/def ::id ::us/uuid) +(s/def ::label ::us/string) +(s/def ::project ::us/uuid) +(s/def ::created-at ::us/inst) +(s/def ::modified-at ::us/inst) +(s/def ::version ::us/number) +(s/def ::user ::us/uuid) + +(s/def ::shapes + (s/every ::udp/minimal-shape :kind vector?)) + +(s/def ::data + (s/keys :req-un [::shapes])) + +(s/def ::history-entry + (s/keys :req-un [::id + ::pinned + ::label + ::project + ::created-at + ::modified-at + ::version + ::user + ::data])) + +(s/def ::history-entries + (s/every ::history-entry)) ;; --- Initialize History State (declare fetch-history) (declare fetch-pinned-history) -(deftype Initialize [page-id] - ptk/UpdateEvent - (update [_ state] - (let [data {:section :main - :selected nil - :pinned #{} - :items #{} - :byver {}}] - (assoc-in state [:workspace :history] data))) - - ptk/WatchEvent - (watch [_ state stream] - (let [page-id (get-in state [:workspace :page]) - stopper (->> stream - (rx/filter #(= % ::stop-changes-watcher)) - (rx/take 1))] - (rx/merge - (->> stream - (rx/take-until stopper) - (rx/filter udp/page-persisted?) - (rx/flat-map #(rx/of (fetch-history page-id) - (fetch-pinned-history page-id)))) - (rx/of (fetch-history page-id) - (fetch-pinned-history page-id)))))) - (defn initialize - [page-id] - {:pre [(uuid? page-id)]} - (Initialize. page-id)) + [id] + (s/assert ::us/uuid id) + (ptk/reify ::initialize + ptk/UpdateEvent + (update [_ state] + (update-in state [:workspace id] + assoc :history {:selected nil + :pinned #{} + :items #{} + :byver {}})) + + ptk/WatchEvent + (watch [_ state stream] + (rx/of (fetch-history id) + (fetch-pinned-history id))))) + +;; --- Watch Page Changes + +(defn watch-page-changes + [id] + (s/assert ::us/uuid id) + (reify + ptk/WatchEvent + (watch [_ state stream] + (let [stopper (rx/filter #(= % ::stop-page-watcher) stream)] + (->> stream + (rx/filter udp/page-persisted?) + (rx/debounce 1000) + (rx/flat-map #(rx/of (fetch-history id) + (fetch-pinned-history id))) + (rx/take-until stopper)))))) ;; --- Pinned Page History Fetched -(deftype PinnedPageHistoryFetched [items] - ptk/UpdateEvent - (update [_ state] - (let [items-map (index-by :version items) - items-set (into #{} items)] - (update-in state [:workspace :history] - (fn [history] - (-> history - (assoc :pinned items-set) - (update :byver merge items-map))))))) - -(defn pinned-page-history-fetched +(defn pinned-history-fetched [items] - (PinnedPageHistoryFetched. items)) + (s/assert ::history-entries items) + (ptk/reify ::pinned-history-fetched + ptk/UpdateEvent + (update [_ state] + (let [pid (get-in state [:workspace :current]) + items-map (index-by :version items) + items-set (into #{} items)] + (update-in state [:workspace pid :history] + (fn [history] + (-> history + (assoc :pinned items-set) + (update :byver merge items-map)))))))) ;; --- Fetch Pinned Page History -(deftype FetchPinnedPageHistory [id] - ptk/WatchEvent - (watch [_ state s] - (let [params {:page id :pinned true}] - (->> (rp/req :fetch/page-history params) - (rx/map :payload) - (rx/map pinned-page-history-fetched))))) - (defn fetch-pinned-history [id] - {:pre [(uuid? id)]} - (FetchPinnedPageHistory. id)) + (s/assert ::us/uuid id) + (ptk/reify ::fetch-pinned-history + ptk/WatchEvent + (watch [_ state s] + (let [params {:page id :pinned true}] + (->> (rp/req :fetch/page-history params) + (rx/map :payload) + (rx/map pinned-history-fetched)))))) ;; --- Page History Fetched -(deftype PageHistoryFetched [items] - ptk/UpdateEvent - (update [_ state] - (let [versions (into #{} (map :version) items) - items-map (index-by items :version) - min-version (apply min versions) - max-version (apply max versions)] - (update-in state [:workspace :history] - (fn [history] - (-> history - (assoc :min-version min-version) - (assoc :max-version max-version) - (update :byver merge items-map) - (update :items #(reduce conj % items)))))))) - -;; TODO: add spec to history items - -(defn page-history-fetched +(defn history-fetched [items] - (PageHistoryFetched. items)) + (s/assert ::history-entries items) + (ptk/reify ::history-fetched + ptk/UpdateEvent + (update [_ state] + (let [pid (get-in state [:workspace :current]) + versions (into #{} (map :version) items) + items-map (index-by :version items) + min-version (apply min versions) + max-version (apply max versions)] + (update-in state [:workspace pid :history] + (fn [history] + (-> history + (assoc :min-version min-version) + (assoc :max-version max-version) + (update :byver merge items-map) + (update :items #(reduce conj % items))))))))) ;; --- Fetch Page History -(deftype FetchPageHistory [page-id since max] - ptk/WatchEvent - (watch [_ state s] - (let [params (merge {:page page-id - :max (or max 15)} - (when since - {:since since}))] - (->> (rp/req :fetch/page-history params) - (rx/map :payload) - (rx/map page-history-fetched))))) - (defn fetch-history ([id] (fetch-history id nil)) ([id {:keys [since max]}] - {:pre [(uuid? id)]} - (FetchPageHistory. id since max))) + (s/assert ::us/uuid id) + (ptk/reify ::fetch-history + ptk/WatchEvent + (watch [_ state s] + (let [params (merge {:page id + :max (or max 5)} + (when since + {:since since}))] + (->> (rp/req :fetch/page-history params) + (rx/map :payload) + (rx/map history-fetched))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Context Aware Events @@ -142,186 +170,101 @@ ;; --- Load More -(deftype LoadMore [] - ptk/WatchEvent - (watch [_ state stream] - (let [page-id (get-in state [:workspace :page]) - since (get-in state [:workspace :history :min-version])] - (rx/of (fetch-history page-id {:since since}))))) - -(defn load-more - [] - (LoadMore.)) +(def load-more + (ptk/reify ::load-more + ptk/WatchEvent + (watch [_ state stream] + (let [pid (get-in state [:workspace :current]) + since (get-in state [:workspace pid :history :min-version])] + (rx/of (fetch-history pid {:since since})))))) ;; --- Select Page History -(deftype SelectPageHistory [version] - ptk/UpdateEvent - (update [_ state] - (let [history (get-in state [:workspace :history]) - item (get-in history [:byver version]) - page (get-in state [:pages (:page item)]) - - page (-> (get-in state [:pages (:page item)]) - (assoc :history true - :data (:data item)))] - (-> state - (udp/unpack-page page) - (assoc-in [:workspace :history :selected] version))))) - -(defn select-page-history +(defn select [version] - {:pre [(integer? version)]} - (SelectPageHistory. version)) + (s/assert int? version) + (ptk/reify ::select + ptk/UpdateEvent + (update [_ state] + (let [pid (get-in state [:workspace :current]) + item (get-in state [:workspace pid :history :byver version]) + page (-> (get-in state [:pages pid]) + (assoc :history true + :data (:data item)))] + (-> state + (udp/unpack-page page) + (assoc-in [:workspace pid :history :selected] version)))))) ;; --- Apply Selected History -(deftype ApplySelectedHistory [] - ptk/UpdateEvent - (update [_ state] - (let [page-id (get-in state [:workspace :page])] - (-> state - (update-in [:pages page-id] dissoc :history) - (assoc-in [:workspace :history :selected] nil)))) +(def apply-selected + (ptk/reify ::apply-selected + ptk/UpdateEvent + (update [_ state] + (let [pid (get-in state [:workspace :current])] + (-> state + (update-in [:pages pid] dissoc :history) + (assoc-in [:workspace pid :history :selected] nil)))) - ptk/WatchEvent - (watch [_ state s] - (let [page-id (get-in state [:workspace :page])] - (rx/of (udp/persist-page page-id))))) - -(defn apply-selected-history - [] - (ApplySelectedHistory.)) + ptk/WatchEvent + (watch [_ state s] + (let [pid (get-in state [:workspace :current])] + (rx/of (udp/persist-page pid)))))) ;; --- Deselect Page History -(deftype DeselectPageHistory [^:mutable noop] - ptk/UpdateEvent - (update [_ state] - (let [page-id (get-in state [:workspace :page]) - selected (get-in state [:workspace :history :selected])] - (if (nil? selected) - (do - (set! noop true) - state) - (let [packed (get-in state [:packed-pages page-id])] - (-> (udp/unpack-page state packed) - (assoc-in [:workspace :history :deselecting] true) - (assoc-in [:workspace :history :selected] nil)))))) - - ptk/WatchEvent - (watch [_ state s] - (if noop - (rx/empty) - (->> (rx/of #(assoc-in % [:workspace :history :deselecting] false)) - (rx/delay 500))))) - -(defn deselect-page-history - [] - (DeselectPageHistory. false)) +(def deselect + (ptk/reify ::deselect + ptk/UpdateEvent + (update [_ state] + (let [pid (get-in state [:workspace :current]) + packed (get-in state [:packed-pages pid])] + (-> (udp/unpack-page state packed) + (assoc-in [:workspace pid :history :selected] nil)))))) ;; --- Refresh Page History -(deftype RefreshHistory [] - ptk/WatchEvent - (watch [_ state stream] - (let [page-id (get-in state [:workspace :page]) - history (get-in state [:workspace :history]) - maxitems (count (:items history))] - (rx/of (fetch-history page-id {:max maxitems}) - (fetch-pinned-history page-id))))) - -(defn refres-history - [] - (RefreshHistory.)) +(def refres-history + (ptk/reify ::refresh-history + ptk/WatchEvent + (watch [_ state stream] + (let [pid (get-in state [:workspace :current]) + history (get-in state [:workspace pid :history]) + maxitems (count (:items history))] + (rx/of (fetch-history pid {:max maxitems}) + (fetch-pinned-history pid)))))) ;; --- History Item Updated -(deftype HistoryItemUpdated [item] - ptk/UpdateEvent - (update [_ state] - (update-in state [:workspace :history] - (fn [history] - (-> history - (update :items #(into #{} (replace-by-id item) %)) - (update :pinned #(into #{} (replace-by-id item) %)) - (assoc-in [:byver (:id item)] item)))))) - -(defn history-updated? - [item] - (instance? HistoryItemUpdated item)) - (defn history-updated [item] - (HistoryItemUpdated. item)) + (s/assert ::history-entry item) + (ptk/reify ::history-item-updated + ptk/UpdateEvent + (update [_ state] + (let [pid (get-in state [:workspace :current])] + (update-in state [:workspace pid :history] + (fn [history] + (-> history + (update :items #(into #{} (replace-by-id item) %)) + (update :pinned #(into #{} (replace-by-id item) %)) + (assoc-in [:byver (:version item)] item)))))))) + +(defn history-updated? + [v] + (= ::history-item-updated (ptk/type v))) ;; --- Update History Item -(deftype UpdateHistoryItem [item] - ptk/WatchEvent - (watch [_ state stream] - (rx/concat - (->> (rp/req :update/page-history item) - (rx/map :payload) - (rx/map history-updated)) - (->> (rx/filter history-updated? stream) - (rx/take 1) - (rx/map refres-history))))) - (defn update-history-item [item] - (UpdateHistoryItem. item)) - -;; --- Forward to Next Version - -(deftype ForwardToNextVersion [] - ptk/WatchEvent - (watch [_ state s] - (let [workspace (:workspace state) - history (:history workspace) - version (:selected history)] - (cond - (nil? version) - (rx/empty) - - (>= (:max-version history) (inc version)) - (rx/of (select-page-history (inc version))) - - (> (inc version) (:max-version history)) - (rx/of (deselect-page-history)) - - :else - (rx/empty))))) - -(defn forward-to-next-version - [] - (ForwardToNextVersion.)) - -;; --- Backwards to Previous Version - -(deftype BackwardsToPreviousVersion [] - ptk/WatchEvent - (watch [_ state s] - (let [workspace (:workspace state) - history (:history workspace) - version (:selected history)] - (cond - (nil? version) - (let [maxv (:max-version history)] - (rx/of (select-page-history maxv))) - - (pos? (dec version)) - (if (contains? (:by-version history) (dec version)) - (rx/of (select-page-history (dec version))) - (let [since (:min-version history) - page (:page workspace) - params {:since since}] - (rx/of (fetch-history page params) - (select-page-history (dec version))))) - - :else - (rx/empty))))) - -(defn backwards-to-previous-version - [] - (BackwardsToPreviousVersion.)) + (ptk/reify ::update-history-item + ptk/WatchEvent + (watch [_ state stream] + (rx/concat + (->> (rp/req :update/page-history item) + (rx/map :payload) + (rx/map history-updated)) + (->> (rx/filter history-updated? stream) + (rx/take 1) + (rx/map (constantly refres-history))))))) diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index db3f7cf5e3..6fc1d9d854 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -57,6 +57,7 @@ (update [_ state] (let [default-flags #{:sitemap :drawtools :layers :element-options :rules} initial-workspace {:project-id project-id + :initialized true :page-id page-id :zoom 1 :flags default-flags @@ -65,7 +66,11 @@ :drawing-tool nil :tooltip nil}] (-> state - (update-in [:workspace page-id] #(if (nil? %) initial-workspace %)) + (update-in [:workspace page-id] + (fn [wsp] + (if (:initialized wsp) + wsp + (merge wsp initial-workspace)))) (assoc-in [:workspace :current] page-id)))) ptk/WatchEvent diff --git a/frontend/src/uxbox/main/ui/workspace.cljs b/frontend/src/uxbox/main/ui/workspace.cljs index 72df61866b..05aed4b445 100644 --- a/frontend/src/uxbox/main/ui/workspace.cljs +++ b/frontend/src/uxbox/main/ui/workspace.cljs @@ -29,7 +29,7 @@ [uxbox.main.ui.workspace.scroll :as scroll] [uxbox.main.ui.workspace.shortcuts :as shortcuts] [uxbox.main.ui.workspace.sidebar :refer [left-sidebar right-sidebar]] - ;; [uxbox.main.ui.workspace.sidebar.history :refer [history-dialog]] + [uxbox.main.ui.workspace.sidebar.history :refer [history-dialog]] [uxbox.main.ui.workspace.streams :as uws] [uxbox.util.data :refer [classnames]] [uxbox.util.dom :as dom] @@ -61,12 +61,14 @@ (defn- subscribe [canvas page] - ;; (scroll/scroll-to-page-center (mf/ref-node canvas) page) (st/emit! (udp/watch-page-changes (:id page)) (udu/watch-page-changes (:id page)) + (udh/initialize (:id page)) + (udh/watch-page-changes (:id page)) (dw/start-shapes-watcher (:id page))) (let [sub (shortcuts/init)] #(do (st/emit! ::udp/stop-page-watcher + ::udh/stop-page-watcher ::dw/stop-shapes-watcher) (rx/cancel! sub)))) @@ -74,7 +76,6 @@ [{:keys [page] :as props}] (let [flags (or (mf/deref refs/flags) #{}) canvas (mf/use-ref nil) - left-sidebar? (not (empty? (keep flags [:layers :sitemap :document-history]))) right-sidebar? (not (empty? (keep flags [:icons :drawtools @@ -101,7 +102,7 @@ :on-scroll on-scroll :on-wheel #(on-wheel % canvas)} - ;; (history-dialog) + [:& history-dialog] ;; Rules (when (contains? flags :rules) diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar.cljs index eb0e75f5d9..4a3bfbcbaa 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar.cljs @@ -9,7 +9,7 @@ (:require [rumext.alpha :as mf] [uxbox.main.ui.workspace.sidebar.drawtools :refer [draw-toolbox]] - ;; [uxbox.main.ui.workspace.sidebar.history :refer [history-toolbox]] + [uxbox.main.ui.workspace.sidebar.history :refer [history-toolbox]] [uxbox.main.ui.workspace.sidebar.icons :refer [icons-toolbox]] [uxbox.main.ui.workspace.sidebar.layers :refer [layers-toolbox]] [uxbox.main.ui.workspace.sidebar.options :refer [options-toolbox]] @@ -27,8 +27,8 @@ [:& sitemap-toolbox {:project-id (:project page) :current-page-id (:id page) :page page}]) - #_(when (contains? flags :document-history) - (history-toolbox page-id)) + (when (contains? flags :document-history) + [:& history-toolbox]) (when (contains? flags :layers) [:& layers-toolbox {:page page}])]]) diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/history.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/history.cljs index 9e9b92e3b0..87aeb78a9c 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/history.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/history.cljs @@ -2,134 +2,115 @@ ;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; -;; Copyright (c) 2015-2017 Andrey Antukh +;; Copyright (c) 2015-2019 Andrey Antukh ;; Copyright (c) 2015-2017 Juan de la Cruz (ns uxbox.main.ui.workspace.sidebar.history - (:require [uxbox.builtins.icons :as i] - [uxbox.main.refs :as refs] - [uxbox.main.store :as st] - [uxbox.main.data.history :as udh] - [uxbox.main.data.pages :as udp] - [uxbox.main.data.workspace :as dw] - [uxbox.util.data :refer [read-string]] - [uxbox.util.dom :as dom] - [uxbox.util.i18n :refer (tr)] - [rumext.alpha :as mf] - [uxbox.util.router :as r] - [uxbox.util.time :as dt])) + (:require + [rumext.alpha :as mf] + [uxbox.builtins.icons :as i] + [uxbox.main.data.history :as udh] + [uxbox.main.data.pages :as udp] + [uxbox.main.data.workspace :as dw] + [uxbox.main.refs :as refs] + [uxbox.main.store :as st] + [uxbox.util.data :refer [read-string]] + [uxbox.util.dom :as dom] + [uxbox.util.i18n :refer (tr)] + [uxbox.util.router :as r] + [uxbox.util.time :as dt])) ;; --- History Item (Component) -;; (mf/def history-item -;; :mixins [mf/memo] -;; :key-fn :id -;; :render -;; (fn [own {:keys [::selected] :as item}] -;; (letfn [(on-select [event] -;; (dom/prevent-default event) -;; (st/emit! (udh/select-page-history (:version item)))) -;; (on-pinned [event] -;; (dom/prevent-default event) -;; (dom/stop-propagation event) -;; (let [item (assoc item -;; :label "no label" -;; :pinned (not (:pinned item)))] -;; (st/emit! (udh/update-history-item item))))] -;; [:li {:class (when (= selected (:version item)) "current") -;; :on-click on-select} -;; [:div.pin-icon {:on-click on-pinned -;; :class (when (:pinned item) "selected")} -;; i/pin] -;; [:span (str "Version " (:version item) -;; " (" (dt/timeago (:created-at item)) ")")]]))) +(mf/defc history-item + [{:keys [item selected?] :as props}] + (letfn [(on-select [event] + (dom/prevent-default event) + (st/emit! (udh/select (:version item)))) + (on-pinned [event] + (dom/prevent-default event) + (dom/stop-propagation event) + (let [item (assoc item + :label "no label" + :pinned (not (:pinned item)))] + (st/emit! (udh/update-history-item item))))] + [:li {:class (when selected? "current") + :on-click on-select} + [:div.pin-icon {:on-click on-pinned + :class (when (:pinned item) "selected")} + i/pin] + [:span (str "Version " (:version item) + " (" (dt/timeago (:created-at item)) ")")]])) -;; ;; --- History List (Component) +;; --- History List (Component) -;; (mf/def history-list -;; :mixins [mf/memo mf/reactive] -;; :render -;; (fn [own {:keys [selected items min-version] :as history}] -;; (let [items (reverse (sort-by :version items)) -;; page (mf/react refs/selected-page) -;; show-more? (pos? min-version) -;; load-more #(st/emit! (udh/load-more))] -;; [:ul.history-content -;; (for [item items] -;; (history-item (assoc item ::selectd selected))) -;; (when show-more? -;; [:li {:on-click load-more} -;; [:a.btn-primary.btn-small -;; "view more"]])]))) +(mf/defc history-list + [{:keys [history] :as props}] + (let [items (reverse (sort-by :version (:items history))) + show-more? (pos? (:min-version history)) + load-more #(st/emit! udh/load-more)] + [:ul.history-content + (for [item items] + [:& history-item {:item item + :key (:id item) + :selected? (= (:selected history) + (:version item))}]) + (when show-more? + [:li {:on-click load-more} + [:a.btn-primary.btn-small "view more"]])])) -;; ;; --- History Pinned List (Component) +;; --- History Pinned List (Component) -;; (mf/def history-pinned-list -;; :mixins [mf/memo] -;; :render -;; (fn [own {:keys [pinned selected] :as history}] -;; [:ul.history-content -;; (for [item (reverse (sort-by :version pinned))] -;; (let [selected (= (:version item) selected)] -;; (history-item (assoc item ::selected selected))))])) +(mf/defc history-pinned-list + [{:keys [history] :as props}] + [:ul.history-content + (for [item (reverse (sort-by :version (:pinned history)))] + [:& history-item {:item item + :key (:id item) + :selected? (= (:selected history) + (:version item))}])]) -;; ;; --- History Toolbox (Component) +;; --- History Toolbox (Component) -;; (mf/def history-toolbox -;; :mixins [mf/memo mf/reactive] +(mf/defc history-toolbox + [props] + (let [history (mf/deref refs/history) + section (mf/use-state :main) + close #(st/emit! (dw/toggle-flag :history)) + main? (= @section :main) + pinned? (= @section :pinned) + show-main #(st/emit! (udh/select-section :main)) + show-pinned #(st/emit! (udh/select-section :pinned))] + [:div.document-history.tool-window + [:div.tool-window-bar + [:div.tool-window-icon i/undo-history] + [:span (tr "ds.settings.document-history")] + [:div.tool-window-close {:on-click close} i/close]] + [:div.tool-window-content + [:ul.history-tabs + [:li {:on-click #(reset! section :main) + :class (when main? "selected")} + (tr "ds.history.versions")] + [:li {:on-click #(reset! section :pinned) + :class (when pinned? "selected")} + (tr "ds.history.pinned")]] + (if (= @section :pinned) + [:& history-pinned-list {:history history}] + [:& history-list {:history history}])]])) -;; :init -;; (fn [own page-id] -;; (st/emit! (udh/initialize page-id)) -;; own) +;; --- History Dialog -;; :will-unmount -;; (fn [own] -;; (st/emit! ::udh/stop-changes-watcher) -;; own) +(mf/defc history-dialog + [props] + (let [history (mf/deref refs/history) + version (:selected history) + on-accept #(st/emit! udh/apply-selected) + on-cancel #(st/emit! udh/deselect)] + (when (or version (:deselecting history)) + [:div.message-version + {:class (when (:deselecting history) "hide-message")} + [:span (tr "history.alert-message" (or version "00")) + [:div.message-action + [:a.btn-transparent {:on-click on-accept} (tr "ds.accept")] + [:a.btn-transparent {:on-click on-cancel} (tr "ds.cancel")]]]]))) -;; :render -;; (fn [own page-id] -;; (let [history (mf/react refs/history) -;; section (:section history :main) - -;; close #(st/emit! (dw/toggle-flag :document-history)) -;; main? (= section :main) -;; pinned? (= section :pinned) - -;; show-main #(st/emit! (udh/select-section :main)) -;; show-pinned #(st/emit! (udh/select-section :pinned))] -;; [:div.document-history.tool-window {} -;; [:div.tool-window-bar {} -;; [:div.tool-window-icon {} i/undo-history] -;; [:span {} (tr "ds.settings.document-history")] -;; [:div.tool-window-close {:on-click close} i/close]] -;; [:div.tool-window-content {} -;; [:ul.history-tabs {} -;; [:li {:on-click show-main -;; :class (when main? "selected")} -;; (tr "ds.history.versions")] -;; [:li {:on-click show-pinned -;; :class (when pinned? "selected")} -;; (tr "ds.history.pinned")]] -;; (if (= section :pinned) -;; (history-pinned-list history) -;; (history-list history))]]))) - -;; ;; --- History Dialog - -;; (mf/def history-dialog -;; :mixins [mf/memo mf/reactive] -;; :render -;; (fn [own] -;; (let [history (mf/react refs/history) -;; version (:selected history) -;; on-accept #(st/emit! (udh/apply-selected-history)) -;; on-cancel #(st/emit! (udh/deselect-page-history))] -;; (when (or version (:deselecting history)) -;; [:div.message-version -;; {:class (when (:deselecting history) "hide-message")} -;; [:span {} (tr "history.alert-message" (or version "00")) -;; [:div.message-action {} -;; [:a.btn-transparent {:on-click on-accept} (tr "ds.accept")] -;; [:a.btn-transparent {:on-click on-cancel} (tr "ds.cancel")]]]])))) diff --git a/frontend/src/uxbox/util/spec.cljs b/frontend/src/uxbox/util/spec.cljs index 8c8cd80f8a..0a4e98eb88 100644 --- a/frontend/src/uxbox/util/spec.cljs +++ b/frontend/src/uxbox/util/spec.cljs @@ -45,6 +45,7 @@ ;; --- Default Specs +(s/def ::bool boolean?) (s/def ::uuid uuid?) (s/def ::email email?) (s/def ::color color?)