diff --git a/backend/resources/migrations/0007.remove_version.sql b/backend/resources/migrations/0007.remove_version.sql new file mode 100644 index 0000000000..0f11855814 --- /dev/null +++ b/backend/resources/migrations/0007.remove_version.sql @@ -0,0 +1,2 @@ +ALTER TABLE page + DROP COLUMN version; diff --git a/backend/src/uxbox/fixtures.clj b/backend/src/uxbox/fixtures.clj index 2de33e0f4b..a8a0e070ca 100644 --- a/backend/src/uxbox/fixtures.clj +++ b/backend/src/uxbox/fixtures.clj @@ -116,7 +116,6 @@ {:id id :file-id file-id :name name - :version version :ordering ordering :data data}))) diff --git a/backend/src/uxbox/migrations.clj b/backend/src/uxbox/migrations.clj index b0b3cf65c2..ea1d09225a 100644 --- a/backend/src/uxbox/migrations.clj +++ b/backend/src/uxbox/migrations.clj @@ -32,7 +32,10 @@ :fn (mg/resource "migrations/0005.libraries.sql")} {:desc "Initial presence tables" :name "0006-presence" - :fn (mg/resource "migrations/0006.presence.sql")}]}) + :fn (mg/resource "migrations/0006.presence.sql")} + {:desc "Remove version" + :name "0007.remove_version" + :fn (mg/resource "migrations/0007.remove_version.sql")}]}) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Entry point diff --git a/backend/src/uxbox/services/mutations/pages.clj b/backend/src/uxbox/services/mutations/pages.clj index 382c731c76..75fbdef383 100644 --- a/backend/src/uxbox/services/mutations/pages.clj +++ b/backend/src/uxbox/services/mutations/pages.clj @@ -13,6 +13,7 @@ [uxbox.common.data :as d] [uxbox.common.exceptions :as ex] [uxbox.common.pages :as cp] + [uxbox.common.migrations :as mg] [uxbox.common.spec :as us] [uxbox.common.uuid :as uuid] [uxbox.config :as cfg] @@ -178,15 +179,14 @@ (let [sid (:session-id params) changes (->> (:changes params) (mapv #(assoc % :session-id sid))) - data (-> (:data page) - (blob/decode) - (cp/process-changes changes) - (blob/encode)) - page (assoc page - :data data - :revn (inc (:revn page)) - :changes (blob/encode changes)) + page (-> page + (update :data blob/decode) + (update :data mg/migrate-data) + (update :data cp/process-changes changes) + (update :data blob/encode) + (update :revn inc) + (assoc :changes (blob/encode changes))) chng (insert-page-change! conn page) msg {:type :page-change @@ -201,7 +201,7 @@ (db/update! conn :page {:revn (:revn page) - :data data} + :data (:data page)} {:id (:id page)}) (retrieve-lagged-changes conn chng params))) diff --git a/backend/src/uxbox/services/queries/pages.clj b/backend/src/uxbox/services/queries/pages.clj index 345d492de0..07ced67b79 100644 --- a/backend/src/uxbox/services/queries/pages.clj +++ b/backend/src/uxbox/services/queries/pages.clj @@ -13,6 +13,7 @@ [promesa.core :as p] [uxbox.common.spec :as us] [uxbox.common.exceptions :as ex] + [uxbox.common.migrations :as mg] [uxbox.db :as db] [uxbox.services.queries :as sq] [uxbox.services.queries.files :as files] @@ -38,7 +39,8 @@ [{:keys [profile-id file-id] :as params}] (db/with-atomic [conn db/pool] (files/check-edition-permissions! conn profile-id file-id) - (retrieve-pages conn params))) + (->> (retrieve-pages conn params) + (mapv #(update % :data mg/migrate-data))))) (def ^:private sql:pages "select p.* @@ -64,7 +66,8 @@ (with-open [conn (db/open)] (let [page (retrieve-page conn id)] (files/check-edition-permissions! conn profile-id (:file-id page)) - page))) + (-> page + (update :data mg/migrate-data))))) (def ^:private sql:page "select p.* from page as p where id=?") diff --git a/backend/src/uxbox/util/transit.clj b/backend/src/uxbox/util/transit.clj index be46994568..c1f5618f74 100644 --- a/backend/src/uxbox/util/transit.clj +++ b/backend/src/uxbox/util/transit.clj @@ -9,11 +9,15 @@ [cognitect.transit :as t] [clojure.java.io :as io] [uxbox.util.time :as dt] - [uxbox.util.data :as data]) + [uxbox.util.data :as data] + [uxbox.common.geom.point :as gpt] + [uxbox.common.geom.matrix :as gmt]) (:import java.io.ByteArrayInputStream java.io.ByteArrayOutputStream - java.io.File)) + java.io.File + uxbox.common.geom.point.Point + uxbox.common.geom.matrix.Matrix)) ;; --- Handlers @@ -22,10 +26,36 @@ (constantly "file") (fn [v] (str v)))) -(def +read-handlers+ dt/+read-handlers+) +(def point-write-handler + (t/write-handler + (constantly "point") + (fn [v] (into {} v)))) + +(def point-read-handler + (t/read-handler + (fn [value] + (gpt/map->Point value)))) + +(def matrix-write-handler + (t/write-handler + (constantly "matrix") + (fn [v] (into {} v)))) + +(def matrix-read-handler + (t/read-handler + (fn [value] + (gmt/map->Matrix value)))) + +(def +read-handlers+ + (assoc dt/+read-handlers+ + "matrix" matrix-read-handler + "point" point-read-handler)) + (def +write-handlers+ (assoc dt/+write-handlers+ - File file-write-handler)) + File file-write-handler + Matrix matrix-write-handler + Point point-write-handler)) ;; --- Low-Level Api diff --git a/backend/tests/uxbox/tests/test_services_pages.clj b/backend/tests/uxbox/tests/test_services_pages.clj index 8643bccee5..5275c443eb 100644 --- a/backend/tests/uxbox/tests/test_services_pages.clj +++ b/backend/tests/uxbox/tests/test_services_pages.clj @@ -40,7 +40,6 @@ (t/is (= (:name data) (:name result))) (t/is (= (:data data) (:data result))) (t/is (nil? (:share-token result))) - (t/is (= 0 (:version result))) (t/is (= 0 (:revn result)))))) (t/testing "generate share token" diff --git a/common/uxbox/common/geom/shapes.cljc b/common/uxbox/common/geom/shapes.cljc index 4c0976578e..1cf3e2bcf6 100644 --- a/common/uxbox/common/geom/shapes.cljc +++ b/common/uxbox/common/geom/shapes.cljc @@ -241,10 +241,10 @@ (defn shapes->rect-shape [shapes] (let [shapes (mapv shape->rect-shape shapes) - minx (transduce (map :x1) min shapes) - miny (transduce (map :y1) min shapes) - maxx (transduce (map :x2) max shapes) - maxy (transduce (map :y2) max shapes)] + minx (transduce (map :x1) min ##Inf shapes) + miny (transduce (map :y1) min ##Inf shapes) + maxx (transduce (map :x2) max ##-Inf shapes) + maxy (transduce (map :y2) max ##-Inf shapes)] {:x1 minx :y1 miny :x2 maxx @@ -270,10 +270,10 @@ (mapv #(transform-shape-point % shape (:transform shape (gmt/matrix))) points))) (defn points->selrect [points] - (let [minx (transduce (map :x) min points) - miny (transduce (map :y) min points) - maxx (transduce (map :x) max points) - maxy (transduce (map :y) max points)] + (let [minx (transduce (map :x) min ##Inf points) + miny (transduce (map :y) min ##Inf points) + maxx (transduce (map :x) max ##-Inf points) + maxy (transduce (map :y) max ##-Inf points)] {:x1 minx :y1 miny :x2 maxx @@ -396,10 +396,10 @@ [shapes] (let [xf-resolve-shape (map :selrect) shapes (into [] xf-resolve-shape shapes) - minx (transduce (map :x1) min shapes) - miny (transduce (map :y1) min shapes) - maxx (transduce (map :x2) max shapes) - maxy (transduce (map :y2) max shapes)] + minx (transduce (map :x1) min ##Inf shapes) + miny (transduce (map :y1) min ##Inf shapes) + maxx (transduce (map :x2) max ##-Inf shapes) + maxy (transduce (map :y2) max ##-Inf shapes)] {:x1 minx :y1 miny :x2 maxx diff --git a/common/uxbox/common/migrations.cljc b/common/uxbox/common/migrations.cljc index feda32aa93..4cb4451508 100644 --- a/common/uxbox/common/migrations.cljc +++ b/common/uxbox/common/migrations.cljc @@ -9,24 +9,28 @@ (defmulti migrate :version) -(defn migrate-page - ([page from-version to-version] - (-> page +(defn migrate-data + ([data from-version to-version] + (-> data (assoc :version to-version) (migrate))) - ([{:keys [version] :as page}] - (reduce #(migrate-page % (:version %1) %2) - page - (range version (inc p/page-version))))) + ([data] + (try + (reduce #(migrate-data %1 %2 (inc %2)) + data + (range (:version data 0) p/page-version)) + + ;; If an error is thrown, we log the error and return the data without migrations + #?(:clj (catch Exception e (.printStackTrace e) data) + :cljs (catch :default e (.error js/console e) data))))) ;; Default handler, noop -(defmethod migrate :default [page] page) +(defmethod migrate :default [data] data) ;; -- MIGRATIONS -- -(defmethod migrate 4 [page] - (prn "Migrate " (:id page)) +(defmethod migrate 4 [data] ;; We changed the internal model of the shapes so they have their selection rect ;; and the vertices @@ -48,16 +52,13 @@ (if (= (:id shape) uuid/zero) shape (assoc shape :selrect (gsh/points->selrect (:points shape))))))))] - (-> page - - ;; We only store the version in the page data - (update :data dissoc :version ) + (-> data ;; Adds vertices to shapes - (update-in [:data :objects] calculate-shape-points) + (update :objects calculate-shape-points) ;; Creates selection rects for shapes - (update-in [:data :objects] calculate-shape-selrects)))) + (update :objects calculate-shape-selrects)))) diff --git a/common/uxbox/common/pages.cljc b/common/uxbox/common/pages.cljc index b289743e05..673c8d6bee 100644 --- a/common/uxbox/common/pages.cljc +++ b/common/uxbox/common/pages.cljc @@ -248,8 +248,8 @@ (s/map-of uuid? ::shape)) (s/def ::data - (s/keys :req-un [::options - ::version + (s/keys :req-un [::version + ::options ::objects])) (s/def ::attr keyword?) @@ -302,7 +302,8 @@ (def default-page-data "A reference value of the empty page data." - {:options {} + {:version page-version + :options {} :objects {root {:id root diff --git a/frontend/src/uxbox/main/data/workspace.cljs b/frontend/src/uxbox/main/data/workspace.cljs index fbd42075aa..32cf0b4134 100644 --- a/frontend/src/uxbox/main/data/workspace.cljs +++ b/frontend/src/uxbox/main/data/workspace.cljs @@ -17,7 +17,6 @@ [uxbox.common.data :as d] [uxbox.common.exceptions :as ex] [uxbox.common.pages :as cp] - [uxbox.common.migrations :as mg] [uxbox.common.spec :as us] [uxbox.common.uuid :as uuid] [uxbox.config :as cfg] @@ -151,7 +150,6 @@ ptk/UpdateEvent (update [_ state] (let [page (get-in state [:workspace-pages page-id]) - page (mg/migrate-page page) local (get-in state [:workspace-cache page-id] workspace-default)] (-> state (assoc :current-page-id page-id ; mainly used by events diff --git a/frontend/src/uxbox/main/data/workspace/persistence.cljs b/frontend/src/uxbox/main/data/workspace/persistence.cljs index ccaf6a1516..9a54ccd3d4 100644 --- a/frontend/src/uxbox/main/data/workspace/persistence.cljs +++ b/frontend/src/uxbox/main/data/workspace/persistence.cljs @@ -210,8 +210,7 @@ params {:name name :file-id file-id :ordering ordering - :data cp/default-page-data - :version cp/page-version}] + :data cp/default-page-data}] (->> (rp/mutation :create-page params) (rx/map page-created)))))) diff --git a/frontend/src/uxbox/main/data/workspace/transforms.cljs b/frontend/src/uxbox/main/data/workspace/transforms.cljs index c2e8895eba..107bdb5a52 100644 --- a/frontend/src/uxbox/main/data/workspace/transforms.cljs +++ b/frontend/src/uxbox/main/data/workspace/transforms.cljs @@ -131,15 +131,13 @@ ptk/WatchEvent (watch [_ state stream] - (let [;;shape (gsh/shape->rect-shape shape) - initial @ms/mouse-position + (let [initial @ms/mouse-position stoper (rx/filter ms/mouse-up? stream) page-id (get state :current-page-id) resizing-shapes (map #(get-in state [:workspace-data page-id :objects %]) ids) layout (get state :workspace-layout)] (rx/concat (->> ms/mouse-position - ;; (rx/mapcat apply-grid-alignment) (rx/with-latest vector ms/mouse-position-ctrl) (rx/map normalize-proportion-lock) (rx/switch-map (fn [[point :as current]] diff --git a/frontend/src/uxbox/main/ui/workspace/shapes/bounding_box.cljs b/frontend/src/uxbox/main/ui/workspace/shapes/bounding_box.cljs index f3ac9059fe..c2a2db2ff2 100644 --- a/frontend/src/uxbox/main/ui/workspace/shapes/bounding_box.cljs +++ b/frontend/src/uxbox/main/ui/workspace/shapes/bounding_box.cljs @@ -21,16 +21,16 @@ (when num (.toFixed num 2))) (mf/defc cross-point [{:keys [point zoom color]}] - (let [width (/ 10 zoom)] + (let [width (/ 5 zoom)] [:g.point - [:line {:x1 (- (:x point) 10) :y1 (- (:y point) 10) - :x2 (+ (:x point) 10) :y2 (+ (:y point) 10) + [:line {:x1 (- (:x point) width) :y1 (- (:y point) width) + :x2 (+ (:x point) width) :y2 (+ (:y point) width) :stroke color :stroke-width "1px" :stroke-opacity 0.5}] - [:line {:x1 (+ (:x point) 10) :y1 (- (:y point) 10) - :x2 (- (:x point) 10) :y2 (+ (:y point) 10) + [:line {:x1 (+ (:x point) width) :y1 (- (:y point) width) + :x2 (- (:x point) width) :y2 (+ (:y point) width) :stroke color :stroke-width "1px" :stroke-opacity 0.5}]])) diff --git a/frontend/src/uxbox/util/debug.cljs b/frontend/src/uxbox/util/debug.cljs index 3f0712f2f4..a6eae4df48 100644 --- a/frontend/src/uxbox/util/debug.cljs +++ b/frontend/src/uxbox/util/debug.cljs @@ -3,7 +3,7 @@ (def debug-options #{:bounding-boxes :group :events :rotation-handler :resize-handler :selection-center #_:simple-selection }) -(defonce ^:dynamic *debug* (atom #{:bounding-boxes})) +(defonce ^:dynamic *debug* (atom #{})) (defn debug-all! [] (reset! *debug* debug-options)) (defn debug-none! [] (reset! *debug* #{}))