From 39df77e6eda40220e2c2b01b35dcd93adad306e7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 16 Apr 2016 20:42:41 +0300 Subject: [PATCH] Integreate new history version dialog in workspace. --- src/uxbox/data/history.cljs | 21 +++++---- src/uxbox/ui/workspace.cljs | 12 ++---- src/uxbox/ui/workspace/sidebar/history.cljs | 47 ++++++++++++++------- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/uxbox/data/history.cljs b/src/uxbox/data/history.cljs index 7aa1a5f9d3..61af4bdc97 100644 --- a/src/uxbox/data/history.cljs +++ b/src/uxbox/data/history.cljs @@ -159,19 +159,24 @@ [id] (ApplySelectedHistory. id)) -;; --- Discard Selected History +;; --- Deselect Page History -(defrecord DiscardSelectedHistory [id] +(defrecord DeselectPageHistory [id] rs/UpdateEvent (-apply-update [_ state] (let [packed (get-in state [:pagedata-by-id id])] - (-> state - (stpr/unpack-page packed) - (assoc-in [:workspace :history :selected] nil))))) + (-> (stpr/unpack-page state packed) + (assoc-in [:workspace :history :deselecting] true) + (assoc-in [:workspace :history :selected] nil)))) -(defn discard-selected-history + rs/WatchEvent + (-apply-watch [_ state s] + (->> (rx/of #(assoc-in % [:workspace :history :deselecting] false)) + (rx/delay 500)))) + +(defn deselect-page-history [id] - (DiscardSelectedHistory. id)) + (DeselectPageHistory. id)) ;; --- History Item Updated @@ -238,7 +243,7 @@ (rx/of (select-page-history (inc version))) (> (inc version) (:max-version history)) - (rx/of (discard-selected-history (:page workspace))) + (rx/of (deselect-page-history (:page workspace))) :else (rx/empty))))) diff --git a/src/uxbox/ui/workspace.cljs b/src/uxbox/ui/workspace.cljs index 97614a8fa2..7538794c3c 100644 --- a/src/uxbox/ui/workspace.cljs +++ b/src/uxbox/ui/workspace.cljs @@ -26,6 +26,7 @@ [uxbox.ui.workspace.shortcuts :refer (shortcuts-mixin)] [uxbox.ui.workspace.header :refer (header)] [uxbox.ui.workspace.rules :refer (horizontal-rule vertical-rule)] + [uxbox.ui.workspace.sidebar.history :refer (history-dialog)] [uxbox.ui.workspace.sidebar :refer (left-sidebar right-sidebar)] [uxbox.ui.workspace.colorpalette :refer (colorpalette)] [uxbox.ui.workspace.canvas :refer (viewport)])) @@ -99,7 +100,7 @@ (defn- workspace-render [own projectid] - (let [{:keys [flags zoom] :as workspace} (rum/react wb/workspace-l) + (let [{:keys [flags zoom page] :as workspace} (rum/react wb/workspace-l) left-sidebar? (not (empty? (keep flags [:layers :sitemap :document-history]))) right-sidebar? (not (empty? (keep flags [:icons :drawtools @@ -122,13 +123,8 @@ :on-scroll on-scroll :on-wheel (partial on-wheel own)} - ;; WIP message version - #_[:div.message-version - [:span "Continue working with version 22?"] - [:div.message-action - [:a.btn-transparent "Accept"] - [:a.btn-transparent "Cancel"] - ]] + + (history-dialog page) ;; Rules (horizontal-rule zoom) diff --git a/src/uxbox/ui/workspace/sidebar/history.cljs b/src/uxbox/ui/workspace/sidebar/history.cljs index 934772782e..c4ead997d2 100644 --- a/src/uxbox/ui/workspace/sidebar/history.cljs +++ b/src/uxbox/ui/workspace/sidebar/history.cljs @@ -32,7 +32,7 @@ (as-> (l/in [:workspace :history]) $ (l/focus-atom $ st/state))) -;; --- Components +;; --- History Item (Component) (defn history-item-render [own item selected] @@ -61,11 +61,13 @@ :name "history-item" :mixins [mx/static]})) +;; --- History List (Component) + (defn history-list-render [own page history] (letfn [(on-select [event] (dom/prevent-default event) - (rs/emit! (udh/discard-selected-history (:id page)))) + (rs/emit! (udh/deselect-page-history (:id page)))) (on-load-more [event] (dom/prevent-default event) @@ -90,25 +92,14 @@ [:a.btn-primary.btn-small "view more"]])])))) -(defn history-list-will-update - [own] - (let [[page history] (:rum/props own)] - (if-let [version (:selected history)] - (let [selected (get-in history [:by-version version])] - (udm/dialog! - (tr "history.alert-message" version) - :on-accept #(rs/emit! (udh/apply-selected-history (:id page))) - :on-cancel #(rs/emit! (udh/discard-selected-history (:id page))))) - (udm/close!)) - own)) - (def history-list (mx/component {:render history-list-render - :will-update history-list-will-update :name "history-list" :mixins [mx/static]})) +;; --- History Pinned List (Component) + (defn history-pinned-list-render [own history] (html @@ -124,6 +115,8 @@ :name "history-pinned-list" :mixins [mx/static]})) +;; --- History Toolbox (Component) + (defn history-toolbox-render [own] (let [local (:rum/local own) @@ -158,3 +151,27 @@ {:render history-toolbox-render :name "document-history-toolbox" :mixins [mx/static rum/reactive (mx/local)]})) + +;; --- History Dialog + +(defn history-dialog-render + [own page] + (let [history (rum/react history-l) + version (:selected history) + on-accept #(rs/emit! (udh/apply-selected-history page)) + on-cancel #(rs/emit! (udh/deselect-page-history page))] + (when (or version (:deselecting history)) + (html + [: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} "Accept"] + [:a.btn-transparent {:on-click on-cancel} "Cancel"]]]])))) + +(def history-dialog + (mx/component + {:render history-dialog-render + :name "history-dialog" + :mixins [mx/static rum/reactive]})) +