From 92060878d78a38980e403cea0a3161b417b33674 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 15 Mar 2016 22:26:15 +0200 Subject: [PATCH] Integrate basic page update with backend. --- src/uxbox/data/projects.cljs | 49 ++++++++++++++------- src/uxbox/ui/workspace.cljs | 3 +- src/uxbox/ui/workspace/sidebar/sitemap.cljs | 1 - 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/uxbox/data/projects.cljs b/src/uxbox/data/projects.cljs index 2187f9ff2..90c31421e 100644 --- a/src/uxbox/data/projects.cljs +++ b/src/uxbox/data/projects.cljs @@ -11,11 +11,13 @@ [beicon.core :as rx] [uxbox.rstore :as rs] [uxbox.router :as r] - [uxbox.state :as st] - [uxbox.schema :as sc] [uxbox.repo :as rp] - [uxbox.util.datetime :as dt] + [uxbox.locales :refer (tr)] + [uxbox.schema :as sc] + [uxbox.state :as st] [uxbox.state.project :as stpr] + [uxbox.ui.messages :as uum] + [uxbox.util.datetime :as dt] [uxbox.util.data :refer (without-keys)])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -103,18 +105,24 @@ (defn create-page [{:keys [name width height project layout] :as data}] (sc/validate! +create-page-schema+ data) - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [page {:id (random-uuid) - :project project - :created (dt/now) - :layout layout - :shapes [] - :name name - :width width - :height height}] - (stpr/assoc-page state page))))) + (letfn [(create [] + (rp/do :create/page {:project project + :layout layout + :data [] + :name name + :width width + :height height})) + (on-created [page] + #(stpr/assoc-page % page)) + + (on-failed [page] + (uum/error (tr "errors.auth")))] + (reify + rs/WatchEvent + (-apply-watch [_ state] + (-> (create) + (p/then on-created) + (p/catch on-failed)))))) (defn update-page [{:keys [id name width height layout] :as data}] @@ -126,7 +134,15 @@ (when width {:width width}) (when height {:height height}) (when name {:name name}))] - (assoc-in state [:pages-by-id id] page))))) + (assoc-in state [:pages-by-id id] page))) + + rs/WatchEvent + (-apply-watch [_ state] + (let [page (get-in state [:pages-by-id id]) + on-success (fn [{:keys [version]}] + #(assoc-in % [:pages-by-id id :version] version))] + (-> (rp/do :update/page page) + (p/then on-success)))))) (defn delete-page [pageid] @@ -171,7 +187,6 @@ (reify rs/WatchEvent (-apply-watch [_ state] - (println "go-to" projectid) (let [pages (stpr/project-pages state projectid) pageid (:id (first pages)) params {:project-uuid projectid diff --git a/src/uxbox/ui/workspace.cljs b/src/uxbox/ui/workspace.cljs index ec70df988..cc90df4c4 100644 --- a/src/uxbox/ui/workspace.cljs +++ b/src/uxbox/ui/workspace.cljs @@ -34,7 +34,8 @@ (defn- workspace-render [own projectid] (let [{:keys [flags] :as workspace} (rum/react uuwb/workspace-l) - left-sidebar? (not (empty? (keep flags [:layers :sitemap :document-history]))) + left-sidebar? (not (empty? (keep flags [:layers :sitemap + :document-history]))) right-sidebar? (not (empty? (keep flags [:icons :drawtools :element-options]))) local (:rum/local own) diff --git a/src/uxbox/ui/workspace/sidebar/sitemap.cljs b/src/uxbox/ui/workspace/sidebar/sitemap.cljs index 9df0a03a1..d9c84a251 100644 --- a/src/uxbox/ui/workspace/sidebar/sitemap.cljs +++ b/src/uxbox/ui/workspace/sidebar/sitemap.cljs @@ -113,7 +113,6 @@ [own local page] (let [edition? (:id page) page (merge page @local) - ;; {:keys [name width height] :or {name ""} :as page} (merge page @local) valid? (and (not (str/empty? (str/trim (:name page "")))) (pos? (:width page)) (pos? (:height page)))]