From 07359752ffc76463374a1cd9d08cac3e0a46b7b5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 29 Jan 2016 21:44:53 +0200 Subject: [PATCH] Improved blocking/unblocking shapes on layers toolbox. --- src/uxbox/data/workspace.cljs | 32 ++++++++++++++++---- src/uxbox/ui/workspace/toolboxes/layers.cljs | 7 +++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 05e62ea7b..a6130f365 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -254,16 +254,36 @@ (assoc-in state [:shapes-by-id sid] (assoc shape :hidden false)) (assoc-in state [:shapes-by-id sid] (assoc shape :hidden true))))))) -(defn toggle-shape-blocking + +(defn block-shape [sid] (reify rs/UpdateEvent (-apply-update [_ state] - (let [shape (get-in state [:shapes-by-id sid]) - blocked? (:blocked shape false)] - (if blocked? - (assoc-in state [:shapes-by-id sid] (assoc shape :blocked false)) - (assoc-in state [:shapes-by-id sid] (assoc shape :blocked true))))))) + (assoc-in state [:shapes-by-id sid :blocked] true)) + + rs/WatchEvent + (-apply-watch [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (if-not (= (:type shape) :builtin/group) + (rx/empty) + (rx/from-coll + (map block-shape (:items shape)))))))) + +(defn unblock-shape + [sid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (assoc-in state [:shapes-by-id sid :blocked] false)) + + rs/WatchEvent + (-apply-watch [_ state] + (let [shape (get-in state [:shapes-by-id sid])] + (if-not (= (:type shape) :builtin/group) + (rx/empty) + (rx/from-coll + (map unblock-shape (:items shape)))))))) (defn toggle-shape-locking [sid] diff --git a/src/uxbox/ui/workspace/toolboxes/layers.cljs b/src/uxbox/ui/workspace/toolboxes/layers.cljs index afa3a3a54..80222b3a3 100644 --- a/src/uxbox/ui/workspace/toolboxes/layers.cljs +++ b/src/uxbox/ui/workspace/toolboxes/layers.cljs @@ -61,8 +61,11 @@ (defn- toggle-blocking [item event] (dom/stop-propagation event) - (let [id (:id item)] - (rs/emit! (dw/toggle-shape-blocking id)))) + (let [id (:id item) + blocked? (:blocked item)] + (if blocked? + (rs/emit! (dw/unblock-shape id)) + (rs/emit! (dw/block-shape id))))) (defn- toggle-locking [item event]