Move dashboard builtints to library.

This commit is contained in:
Andrey Antukh 2015-12-25 15:33:58 +02:00
parent d8e7087af6
commit 11bb081c7c
3 changed files with 18 additions and 15 deletions

View file

@ -0,0 +1,9 @@
(ns uxbox.library
(:require [uxbox.library.colors :as colors]
[uxbox.util.data :refer (index-by-id)]))
(def ^:static +color-collections+
colors/+collections+)
(def ^:static +color-collections-by-id+
(index-by-id colors/+collections+))

View file

@ -1,6 +1,6 @@
(ns uxbox.ui.dashboard.builtins) (ns uxbox.library.colors)
(def ^:static +color-collections+ (def ^:static +collections+
[{:name "Generic 1" [{:name "Generic 1"
:id 1 :id 1
:builtin true :builtin true
@ -12,8 +12,8 @@
"#7502f1" "#7502f1"
"#ffe705" "#ffe705"
"#00ffab" "#00ffab"
"#f52105" "#f52105"}}
}}
{:name "Generic 2" {:name "Generic 2"
:id 2 :id 2
:builtin true :builtin true
@ -34,10 +34,4 @@
"#3fe720" "#3fe720"
"#30ff20" "#30ff20"
"#352120" "#352120"
"#352140" "#352140"}}])
}}])
(def ^:static +color-collections-by-id+
(let [data (transient {})]
(run! #(assoc! data (:id %) %) +color-collections+)
(persistent! data)))

View file

@ -6,11 +6,11 @@
[uxbox.state :as st] [uxbox.state :as st]
[uxbox.rstore :as rs] [uxbox.rstore :as rs]
[uxbox.schema :as sc] [uxbox.schema :as sc]
[uxbox.library :as library]
[uxbox.data.dashboard :as dd] [uxbox.data.dashboard :as dd]
[uxbox.util.lens :as ul] [uxbox.util.lens :as ul]
[uxbox.ui.icons :as i] [uxbox.ui.icons :as i]
[uxbox.ui.form :as form] [uxbox.ui.form :as form]
[uxbox.ui.dashboard.builtins :as builtins]
[uxbox.ui.lightbox :as lightbox] [uxbox.ui.lightbox :as lightbox]
[uxbox.ui.colorpicker :refer (colorpicker)] [uxbox.ui.colorpicker :refer (colorpicker)]
[uxbox.ui.dom :as dom] [uxbox.ui.dom :as dom]
@ -40,7 +40,7 @@
(defn- get-collection (defn- get-collection
[type id] [type id]
(case type (case type
:builtin (get builtins/+color-collections-by-id+ id) :builtin (get library/+color-collections-by-id+ id)
:own (get-in @st/state [:colors-by-id id]))) :own (get-in @st/state [:colors-by-id id])))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -110,7 +110,7 @@
builtin? (= (:collection-type dashboard) :builtin) builtin? (= (:collection-type dashboard) :builtin)
collections (if own? collections (if own?
(sort-by :id (vals colors)) (sort-by :id (vals colors))
builtins/+color-collections+)] library/+color-collections+)]
(html (html
[:div.library-bar [:div.library-bar
[:div.library-bar-inside [:div.library-bar-inside
@ -152,7 +152,7 @@
coll-id (:collection-id dashboard) coll-id (:collection-id dashboard)
own? (= coll-type :own) own? (= coll-type :own)
coll (case coll-type coll (case coll-type
:builtin (get builtins/+color-collections-by-id+ coll-id) :builtin (get library/+color-collections-by-id+ coll-id)
:own (rum/react collection-state)) :own (rum/react collection-state))
edit-cb #(lightbox/open! :color-form {:coll coll :color %}) edit-cb #(lightbox/open! :color-form {:coll coll :color %})
remove-cb #(rs/emit! (dd/remove-color {:id (:id coll) :color %}))] remove-cb #(rs/emit! (dd/remove-color {:id (:id coll) :color %}))]