Minor code reorganization and wip of colors page.

This commit is contained in:
Andrey Antukh 2015-12-20 20:19:07 +02:00
parent a93c6bfa45
commit 9c2c7f40ba
13 changed files with 221 additions and 56 deletions

View file

@ -0,0 +1,60 @@
(ns uxbox.data.dashboard
(:require [uxbox.rstore :as rs]
[uxbox.router :as r]
[uxbox.state :as st]
[uxbox.schema :as sc]
[uxbox.time :as time]
[bouncer.validators :as v]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn assoc-page
"A reduce function for assoc the page
to the state map."
[state page]
(let [uuid (:id page)]
(update-in state [:pages-by-id] assoc uuid page)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn initialize
[section]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(assoc state :dashboard {:section section
:collection-type :builtin
:collection-id nil}))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.d.d/initialize>"))))
(defn set-collection-type
[type]
{:pre [(contains? #{:builtin :own} type)]}
(reify
rs/UpdateEvent
(-apply-update [_ state]
(as-> state $
(assoc-in $ [:dashboard :collection-type] type)
(assoc-in $ [:dashboard :collection-id] nil)))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.d.d/set-collection-type>"))))
(defn set-collection
[id]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(println "set-collection" id)
(assoc-in state [:dashboard :collection-id] id))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.d.d/set-collection>"))))

View file

@ -119,36 +119,11 @@
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/create-project>")))))
(defn initialize-workspace
[projectid pageid]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(let [s {:project projectid
:toolboxes #{}
:page pageid}]
(assoc state :workspace s)))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/initialize-workspace>"))))
(defn set-dashboard-section
[section]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:dashboard :section] section))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/go-to-project"))))
(defn go-to-project
(defn go-to
"A shortcut event that redirects the user to the
first page of the project."
([projectid]
(go-to-project projectid nil))
(go-to projectid nil))
([projectid pageid]
(reify
rs/EffectEvent
@ -162,4 +137,4 @@
:page-uuid pageid})))))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/go-to-project")))))
(-write writer "#<event:u.s.p/go-to")))))

View file

@ -36,6 +36,18 @@
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/toggle-tool>"))))
(-write writer "#<event:u.s.p/toggle-toolbox>"))))
(defn initialize
[projectid pageid]
(reify
rs/UpdateEvent
(-apply-update [_ state]
(let [s {:project projectid
:toolboxes #{}
:page pageid}]
(assoc state :workspace s)))
IPrintWithWriter
(-pr-writer [mv writer _]
(-write writer "#<event:u.s.p/initialize>"))))