diff --git a/src/uxbox/main/data/icons.cljs b/src/uxbox/main/data/icons.cljs index 3459f2db7..83c239670 100644 --- a/src/uxbox/main/data/icons.cljs +++ b/src/uxbox/main/data/icons.cljs @@ -245,6 +245,33 @@ {:pre [(or (uuid? id) (nil? id))]} (CreateIcons. id files)) +;; --- Icon Updated + +(defrecord IconUpdated [id data] + rs/UpdateEvent + (-apply-update [_ state] + (assoc-in state [:icons-by-id id] data))) + +(defn icon-updated + [{:keys [id] :as data}] + {:pre [(map? data)]} + (IconUpdated. id data)) + +;; --- Update Icon + +(defrecord UpdateIcon [id] + rs/WatchEvent + (-apply-watch [_ state stream] + (let [icon (get-in state [:icons-by-id id])] + (->> (rp/req :update/icon icon) + (rx/map :payload) + (rx/map icon-updated))))) + +(defn update-icon + [id] + {:pre [(uuid? id)]} + (UpdateIcon. id)) + ;; --- Icons Fetched (defrecord IconsFetched [items] @@ -315,11 +342,16 @@ (DeselectIcon. id) (SelectIcon. id)))))) +(defn deselect-icon + [id] + {:pre [(uuid? id)]} + (DeselectIcon. id)) + (defn toggle-icon-selection [id] (ToggleIconSelection. id)) -;; --- Copy Icon +;; --- Copy Selected Icon (defrecord CopySelected [id] rs/WatchEvent @@ -338,6 +370,31 @@ {:pre [(or (uuid? id) (nil? id))]} (CopySelected. id)) +;; --- Move Selected Icon + +(defrecord MoveSelected [id] + rs/UpdateEvent + (-apply-update [_ state] + (let [selected (get-in state [:dashboard :icons :selected])] + (reduce (fn [state icon] + (assoc-in state [:icons-by-id icon :collection] id)) + state + selected))) + + rs/WatchEvent + (-apply-watch [_ state stream] + (let [selected (get-in state [:dashboard :icons :selected])] + (rx/merge + (->> (rx/from-coll selected) + (rx/map update-icon)) + (->> (rx/from-coll selected) + (rx/map deselect-icon)))))) + +(defn move-selected + [id] + {:pre [(or (uuid? id) (nil? id))]} + (MoveSelected. id)) + ;; --- Delete Selected (defrecord DeleteSelected [] diff --git a/src/uxbox/main/repo/icons.cljs b/src/uxbox/main/repo/icons.cljs index 698121ccb..42892b0a7 100644 --- a/src/uxbox/main/repo/icons.cljs +++ b/src/uxbox/main/repo/icons.cljs @@ -63,3 +63,11 @@ [_ id] (let [url (str url "/library/icons/" id)] (send! {:url url :method :delete}))) + +(defmethod request :update/icon + [_ {:keys [id collection] :as body}] + (let [params {:url (str url "/library/icons/" id) + :method :put + :body body}] + (send! params))) + diff --git a/src/uxbox/main/ui/dashboard/icons.cljs b/src/uxbox/main/ui/dashboard/icons.cljs index 36e71426e..49aa135c8 100644 --- a/src/uxbox/main/ui/dashboard/icons.cljs +++ b/src/uxbox/main/ui/dashboard/icons.cljs @@ -211,17 +211,41 @@ (mx/defc grid-options-copy {:mixins [mx/reactive mx/static]} - [colls] + [current-coll] + {:pre [(uuid? current-coll)]} (let [colls (mx/react collections-ref) colls (->> (vals colls) (filter #(= :own (:type %))) + (remove #(= current-coll (:id %))) (sort-by :name colls)) on-select (fn [event id] (dom/prevent-default event) (rs/emit! (di/copy-selected id)))] [:ul.move-list [:li.title "Copy to library"] - [:li [:a {:href "#" :on-click (partial on-select nil)} "Storage"]] + [:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]] + (for [coll colls + :let [id (:id coll) + name (:name coll)]] + [:li {:key (str id)} + [:a {:on-click #(on-select % id)} name]])])) + +(mx/defc grid-options-move + {:mixins [mx/reactive mx/static]} + [current-coll] + {:pre [(uuid? current-coll)]} + (let [colls (mx/react collections-ref) + colls (->> (vals colls) + (filter #(= :own (:type %))) + (remove #(= current-coll (:id %))) + (sort-by :name colls)) + on-select (fn [event id] + (println "on-select" event id) + (dom/prevent-default event) + (rs/emit! (di/move-selected id)))] + [:ul.move-list + [:li.title "Move to library"] + [:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]] (for [coll colls :let [id (:id coll) name (:name coll)]] @@ -230,7 +254,7 @@ (mx/defcs grid-options {:mixins [(mx/local) mx/static]} - [own {:keys [type] :as coll}] + [own {:keys [type id] :as coll}] (let [editable? (or (= type :own) (nil? coll)) local (:rum/local own)] @@ -238,25 +262,28 @@ (rs/emit! (di/delete-selected))) (on-delete [event] (udl/open! :confirm {:on-accept delete})) - (on-toggle [event] - (swap! local update :show-copy-tooltip not) - (println "on-toggle"))] + (on-toggle-copy [event] + (swap! local update :show-copy-tooltip not)) + (on-toggle-move [event] + (swap! local update :show-move-tooltip not))] ;; MULTISELECT OPTIONS BAR [:div.multiselect-bar (if editable? [:div.multiselect-nav - #_[:span.move-item.tooltip.tooltip-top - {:alt "Move to"} - i/organize] + [:span.move-item.tooltip.tooltip-top + {:on-click on-toggle-move} + (when (:show-move-tooltip @local) + (grid-options-move id)) + i/organize] [:span.delete.tooltip.tooltip-top {:alt "Delete" :on-click on-delete} i/trash]] [:div.multiselect-nav [:span.move-item.tooltip.tooltip-top - {:on-click on-toggle} + {:on-click on-toggle-copy} (when (:show-copy-tooltip @local) - (grid-options-copy)) + (grid-options-copy id)) i/organize]])]))) (mx/defc grid-item @@ -267,7 +294,8 @@ (when (kbd/shift? event) (toggle-selection event)))] [:div.grid-item.small-item.project-th - {:on-click toggle-selection-shifted} + {:on-click toggle-selection-shifted + :id (str "grid-item-" id)} [:div.input-checkbox.check-primary [:input {:type "checkbox" :id (:id icon)