0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-15 11:38:24 -05:00

Remove some validations.

This commit is contained in:
Andrey Antukh 2016-04-12 22:23:16 +03:00
parent e42b2ed7bf
commit 5624adcedf
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
8 changed files with 75 additions and 146 deletions

View file

@ -64,13 +64,8 @@
(dp/fetch-projects)
(udu/fetch-profile))))))))
(def ^:const ^:private +login-schema+
{:username [sc/required sc/string]
:password [sc/required sc/string]})
(defn login
[params]
(sc/validate! +login-schema+ params)
(map->Login params))
;; --- Logout

View file

@ -12,22 +12,7 @@
[uxbox.schema :as sc]
[uxbox.repo :as rp]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Schemas
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static +color-replace-schema+
{:id [sc/required sc/uuid]
:from [sc/color]
:to [sc/required sc/color]})
(def ^:static +remove-color-schema+
{:id [sc/required sc/uuid]
:color [sc/required sc/color]})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helpers
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; --- Helpers
(defn assoc-page
"A reduce function for assoc the page
@ -36,9 +21,7 @@
(let [uuid (:id page)]
(update-in state [:pages-by-id] assoc uuid page)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; --- Events
(defn merge-if-not-exists
[map & maps]
@ -139,7 +122,6 @@
(defn replace-color
"Add or replace color in a collection."
[{:keys [id from to] :as params}]
(sc/validate! +color-replace-schema+ params)
(reify
rs/UpdateEvent
(-apply-update [_ state]
@ -153,7 +135,6 @@
(defn remove-color
"Remove color in a collection."
[{:keys [id color] :as params}]
(sc/validate! +remove-color-schema+ params)
(reify
rs/UpdateEvent
(-apply-update [_ state]

View file

@ -74,7 +74,7 @@
(rx/mapcat on-created)
(rx/catch on-failed))))))
(def ^:static +create-page-schema+
(def ^:private create-page-schema
{:name [sc/required sc/string]
:layout [sc/required sc/string]
:width [sc/required sc/integer]
@ -83,8 +83,8 @@
(defn create-page
[data]
(sc/validate! +create-page-schema+ data)
(map->CreatePage data))
(-> (sc/validate! data create-page-schema)
(map->CreatePage)))
;; --- Sync Page
@ -171,7 +171,7 @@
(rx/map on-success)
(rx/catch on-failure)))))
(def ^:const +update-page-schema+
(def ^:private update-page-schema
{:name [sc/required sc/string]
:width [sc/required sc/integer]
:height [sc/required sc/integer]
@ -179,8 +179,9 @@
(defn update-page-metadata
[data]
(sc/validate! +update-page-schema+ data)
(map->UpdatePageMetadata (dissoc data :data)))
(-> (sc/validate! data update-page-schema)
(dissoc :data)
(map->UpdatePageMetadata)))
;; --- Delete Page (by id)

View file

@ -70,33 +70,48 @@
[]
(FetchProjects.))
;; --- Project Created
(defrecord ProjectCreated [project]
rs/UpdateEvent
(-apply-update [_ state]
(stpr/assoc-project state project)))
(defn project-created
[data]
(ProjectCreated. data))
;; --- Create Project
(defrecord CreateProject [name width height layout]
rs/WatchEvent
(-apply-watch [this state s]
(letfn [(on-success [project]
(rx/of (rs/swap #(stpr/assoc-project % project))
(udp/create-page (assoc (into {} this)
:project (:id project)
:name "Page 1"
:data nil))))
(letfn [(on-success [{project :payload}]
(rx/of
(project-created project)
(udp/create-page {:width width
:height height
:layout layout
:project (:id project)
:name "Page 1"
:data nil})))
(on-failure [err]
(uum/error (tr "errors.create-project")))]
(uum/error (tr "errors.create-project"))
(rx/empty))]
(->> (rp/req :create/project {:name name})
(rx/mapcat on-success)
(rx/catch on-failure)))))
(rx/catch on-failure)
(rx/mapcat on-success)))))
(def ^:static +project-schema+
(def ^:private create-project-schema
{:name [sc/required sc/string]
:width [sc/required sc/integer]
:height [sc/required sc/integer]
:layout [sc/required sc/string]})
(defn create-project
[{:keys [name width height layout] :as data}]
(sc/validate! +project-schema+ data)
(map->CreateProject data))
[params]
(-> (sc/validate! params create-project-schema)
(map->CreateProject)))
;; --- Delete Project (by id)

View file

@ -19,63 +19,9 @@
[uxbox.util.geom.point :as gpt]
[uxbox.util.data :refer (index-of)]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Schemas
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static +shape-schema+
{:x [sc/integer]
:y [sc/integer]
:width [sc/integer]
:height [sc/integer]
:type [sc/required sc/shape-type]})
(def ^:static +shape-size-schema+
{:width [sc/integer]
:height [sc/integer]
:lock [sc/boolean]})
(def ^:static +shape-fill-attrs-schema+
{:color [sc/color]
:opacity [sc/number]})
(def ^:static +shape-stroke-attrs-schema+
{:color [sc/color]
:width [sc/integer]
:type [sc/keyword]
:opacity [sc/number]})
(def ^:static +shape-line-attrs-schema+
{:x1 [sc/integer]
:y1 [sc/integer]
:x2 [sc/integer]
:y2 [sc/integer]})
(def ^:static +shape-font-attrs-schema+
{:family [sc/string]
:style [sc/string]
:weight [sc/string]
:align [sc/string]
:size [sc/number]
:letter-spacing [sc/number]
:line-height [sc/number]})
(def ^:static +shape-radius-attrs-schema+
{:rx [sc/integer]
:ry [sc/integer]})
(def ^:static +shape-position-schema+
{:x [sc/integer]
:y [sc/integer]})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events (explicit)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn add-shape
"Create and add shape to the current selected page."
[shape]
(sc/validate! +shape-schema+ shape)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -113,7 +59,6 @@
(defn update-line-attrs
[sid {:keys [x1 y1 x2 y2] :as opts}]
(sc/validate! +shape-line-attrs-schema+ opts)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -144,7 +89,6 @@
WARN: only works with shapes that works
with height and width such are ::rect"
[sid {:keys [width height] :as opts}]
(sc/validate! +shape-size-schema+ opts)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -164,7 +108,6 @@
(defn update-position
"Update the start position coordenate of the shape."
[sid {:keys [x y] :as opts}]
(sc/validate! +shape-position-schema+ opts)
(reify
rs/UpdateEvent
(-apply-update [_ state]
@ -182,7 +125,6 @@
(defn update-fill-attrs
[sid {:keys [color opacity] :as opts}]
(sc/validate! +shape-fill-attrs-schema+ opts)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -195,7 +137,6 @@
(defn update-font-attrs
[sid {:keys [family style weight size align
letter-spacing line-height] :as opts}]
(sc/validate! +shape-font-attrs-schema+ opts)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -212,7 +153,6 @@
(defn update-stroke-attrs
[sid {:keys [color opacity type width] :as opts}]
(sc/validate! +shape-stroke-attrs-schema+ opts)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -226,7 +166,6 @@
(defn update-radius-attrs
[sid {:keys [rx ry] :as opts}]
(sc/validate! +shape-radius-attrs-schema+ opts)
(reify
udp/IPageUpdate
rs/UpdateEvent
@ -463,7 +402,6 @@
"Update the fill related attributed on
selected shapes."
[opts]
(sc/validate! +shape-fill-attrs-schema+ opts)
(reify
rs/WatchEvent
(-apply-watch [_ state s]
@ -476,7 +414,6 @@
"Update the fill related attributed on
selected shapes."
[opts]
(sc/validate! +shape-stroke-attrs-schema+ opts)
(reify
rs/WatchEvent
(-apply-watch [_ state s]

View file

@ -94,7 +94,6 @@
(defn update-password
[data]
(let [[errors data] (sc/validate data update-password-schema)]
(println errors)
(if errors
(forms/assign-errors :profile/password errors)
(UpdatePassword. data))))

View file

@ -77,8 +77,10 @@
(defn validate!
[data schema]
(when-let [errors (first (validate schema data))]
(throw (ex-info "Invalid data" errors))))
(let [[errors data] (validate data schema)]
(if errors
(throw (ex-info "Invalid data" errors))
data)))
(defn valid?
[data schema]

View file

@ -187,44 +187,43 @@
;; --- Colors Create / Edit Lightbox
(def ^:const ^:private +color-form-schema+
{:hex [sc/required sc/color]})
(defn- color-lightbox-render
[own {:keys [coll color]}]
(let [local (:rum/local own)]
(letfn [(submit [e]
(if-let [errors (sc/validate +color-form-schema+ @local)]
(swap! local assoc :errors errors)
(let [params {:id (:id coll) :from color
:to (:hex @local)}]
(rs/emit! (dd/replace-color params))
(lightbox/close!))))
(on-change [e]
(let [value (str/trim (dom/event->value e))]
(swap! local assoc :hex value)))]
(html
[:div.lightbox-body
[:h3 "New color"]
[:form
[:div.row-flex
[:input#color-hex.input-text
{:placeholder "#"
:class (form/error-class local :hex)
:on-change on-change
:value (or (:hex @local) color "")
:type "text"}]]
[:div.row-flex.center.color-picker-default
(colorpicker
:value (or (:hex @local) color "#00ccff")
:on-change #(swap! local assoc :hex %))]
(html
[:p "TODO"]))
;; (let [local (:rum/local own)]
;; (letfn [(submit [e]
;; (if-let [errors (sc/validate +color-form-schema+ @local)]
;; (swap! local assoc :errors errors)
;; (let [params {:id (:id coll) :from color
;; :to (:hex @local)}]
;; (rs/emit! (dd/replace-color params))
;; (lightbox/close!))))
;; (on-change [e]
;; (let [value (str/trim (dom/event->value e))]
;; (swap! local assoc :hex value)))]
;; (html
;; [:div.lightbox-body
;; [:h3 "New color"]
;; [:form
;; [:div.row-flex
;; [:input#color-hex.input-text
;; {:placeholder "#"
;; :class (form/error-class local :hex)
;; :on-change on-change
;; :value (or (:hex @local) color "")
;; :type "text"}]]
;; [:div.row-flex.center.color-picker-default
;; (colorpicker
;; :value (or (:hex @local) color "#00ccff")
;; :on-change #(swap! local assoc :hex %))]
[:input#project-btn.btn-primary
{:value "+ Add color"
:on-click submit
:type "button"}]]
[:a.close {:on-click #(lightbox/close!)}
i/close]]))))
;; [:input#project-btn.btn-primary
;; {:value "+ Add color"
;; :on-click submit
;; :type "button"}]]
;; [:a.close {:on-click #(lightbox/close!)}
;; i/close]]))))
(def color-lightbox
(mx/component