From 6b6aba735883ca85bb2dc0fdc20c4fd54e1ffdd5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 14 Dec 2015 20:31:21 +0200 Subject: [PATCH] WIP --- frontend/uxbox/data/projects.cljs | 94 +++++++++++++++++++++--- frontend/uxbox/router.cljs | 3 +- frontend/uxbox/schema.cljs | 12 ++- frontend/uxbox/state.cljs | 4 +- frontend/uxbox/ui.cljs | 11 ++- frontend/uxbox/ui/dashboard.cljs | 40 +++++----- frontend/uxbox/ui/workspace.cljs | 118 ++++++++++++++++++++++++++++++ frontend/uxbox/util.cljs | 13 +++- 8 files changed, 258 insertions(+), 37 deletions(-) create mode 100644 frontend/uxbox/ui/workspace.cljs diff --git a/frontend/uxbox/data/projects.cljs b/frontend/uxbox/data/projects.cljs index 2dd0f2b30..fd08a0996 100644 --- a/frontend/uxbox/data/projects.cljs +++ b/frontend/uxbox/data/projects.cljs @@ -1,32 +1,104 @@ (ns uxbox.data.projects (:require [uxbox.rstore :as rs] + [uxbox.router :as r] [uxbox.state :as st] [uxbox.schema :as sc] [bouncer.validators :as v])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Schemas +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (def ^:static +project-schema+ {:name [v/required v/string] :width [v/required v/integer] :height [v/required v/integer] - :layout [v/required sc/keyword?]}) + :layout [v/required sc/keyword]}) -(defn create-project - [{:keys [name width height layout] :as data}] - (sc/validate! +project-schema+ data) - (println "create-project") +(def ^:static +page-schema+ + {:name [v/required v/string] + :width [v/required v/integer] + :height [v/required v/integer] + :project [v/required sc/uuid]}) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Events +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defn create-page + [{:keys [name width height project] :as data}] + (sc/validate! +page-schema+ data) (reify rs/UpdateEvent (-apply-update [_ state] (let [uuid (random-uuid) - proj {:id uuid + page {:id uuid + :project project :name name :width width - :height height - :pages []}] + :height height}] (-> state - (update-in [:projects] conj uuid) - (update-in [:projects-by-id] assoc uuid {:name name})))) + (update-in [:pages] conj uuid) + (update-in [:projects-by-id project :pages] conj uuid) + (update-in [:pages-by-id] assoc uuid page)))) IPrintWithWriter (-pr-writer [mv writer _] - (-write writer "#")))) + (-write writer "#")))) + +(defn create-project + [{:keys [name width height layout] :as data}] + (sc/validate! +project-schema+ data) + (let [uuid (random-uuid)] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [proj {:id uuid + :name name + :width width + :height height + :pages []}] + (-> state + (update-in [:projects] conj uuid) + (update-in [:projects-by-id] assoc uuid proj)))) + + rs/EffectEvent + (-apply-effect [_ state] + (rs/emit! (create-page {:name "Page 1" + :width width + :height height + :project uuid}))) + + IPrintWithWriter + (-pr-writer [mv writer _] + (-write writer "#"))))) + +(defn initialize-workspace + [projectid pageid] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (assoc state :workspace {:project projectid :page pageid})) + + IPrintWithWriter + (-pr-writer [mv writer _] + (-write writer "#")))) + +(defn go-to-project + "A shortcut event that redirects the user to the + first page of the project." + ([projectid] + (go-to-project projectid nil)) + ([projectid pageid] + (reify + rs/EffectEvent + (-apply-effect [_ state] + (if pageid + (rs/emit! (r/navigate :main/page {:project-uuid projectid + :page-uuid pageid})) + (let [pages (get-in state [:projects-by-id projectid :pages])] + (rs/emit! (r/navigate :main/page {:project-uuid projectid + :page-uuid (first pages)}))))) + IPrintWithWriter + (-pr-writer [mv writer _] + (-write writer "#" innerHTML "") +;; data (js/Blob. #js [html] #js {:type "application/octet-stream"}) +;; url (.createObjectURL (.-URL js/window) data)] +;; (set! (.-href (.-currentTarget e)) url)))} +;; icons/export]] +;; [:li.tooltip.tooltip-bottom +;; {:alt "Image (Ctrl + I)"} +;; icons/image]] +;; [:ul.options-btn +;; [:li.tooltip.tooltip-bottom +;; {:alt "Ruler (Ctrl + R)"} +;; icons/ruler] +;; [:li.tooltip.tooltip-bottom +;; {:alt "Grid (Ctrl + G)" +;; :class (when (rum/react ws/grid?) "selected") +;; :on-click ws/toggle-grid!} +;; icons/grid] +;; [:li.tooltip.tooltip-bottom +;; {:alt "Align (Ctrl + A)"} +;; icons/alignment] +;; [:li.tooltip.tooltip-bottom +;; {:alt "Organize (Ctrl + O)"} +;; icons/organize]]] +;; (user conn)])) + +;; (def header +;; (util/component +;; {:render header-render +;; :name "header"})) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Header +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(def project-state + (as-> (util/dep-in [:projects-by-id] [:workspace :project]) $ + (l/focus-atom $ s/state))) + +(def page-state + (as-> (util/dep-in [:pages-by-id] [:workspace :page]) $ + (l/focus-atom $ s/state))) + +(defn workspace-render + [own projectid] + (println "workspace-render" @s/state) + (println 22222 @page-state) + (html + [:div "hello world" + ;; (header conn page ws/grid? project-bar-visible?) + ;; [:main.main-content + ;; [:section.workspace-content + ;; ;; Toolbar + ;; (toolbar open-toolboxes) + ;; ;; Project bar + ;; (project-bar conn project page pages @project-bar-visible?) + ;; ;; Rules + ;; (horizontal-rule (rum/react ws/zoom)) + ;; (vertical-rule (rum/react ws/zoom)) + ;; ;; Working area + ;; (working-area conn @open-toolboxes page project shapes (rum/react ws/zoom) (rum/react ws/grid?)) + ;; ;; Aside + ;; (when-not (empty? @open-toolboxes) + ;; (aside conn open-toolboxes page shapes)) + ])) + +(def ^:static workspace + (util/component + {:render workspace-render + :name "workspace" + :mixins [rum/static]})) + diff --git a/frontend/uxbox/util.cljs b/frontend/uxbox/util.cljs index 7f71bf04a..81eccbbb6 100644 --- a/frontend/uxbox/util.cljs +++ b/frontend/uxbox/util.cljs @@ -112,9 +112,20 @@ })) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Lenses Helpers +;; Lenses & Helpers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn dep-in + [where link] + {:pre [(vector? where) (vector? link)]} + (l/lens + (fn [s] + (let [value (get-in s link) + path (conj where value)] + (get-in s path))) + (fn [s f] + (throw (ex-info "Not implemented" {}))))) + (defn derive [a path] (l/focus-atom (l/in path) a))