parent
9ca73e14ec
commit
cff6e9e965
@ -0,0 +1,62 @@
|
|||||||
|
(ns wanijo.schema.forms
|
||||||
|
(:require [wanijo.attribute.domain :as attr-domain]
|
||||||
|
[clojure.string :refer [capitalize]]
|
||||||
|
[clojure.spec.alpha :as spec]))
|
||||||
|
|
||||||
|
(defn unique-attr-name-in-schema! [req]
|
||||||
|
(let [schema-uuid (get-in req [:params :schema])
|
||||||
|
attr-uuid (get-in req [:params :uuid])
|
||||||
|
name (get-in req [:params :name])
|
||||||
|
duplicates (->> (attr-domain/find-by-schema! schema-uuid)
|
||||||
|
(map #(if (or (and (empty? attr-uuid)
|
||||||
|
(= name (:name %)))
|
||||||
|
(and (not (empty? attr-uuid))
|
||||||
|
(= name (:name %))
|
||||||
|
(not= attr-uuid (:uuid %))))
|
||||||
|
1 0))
|
||||||
|
(apply +))]
|
||||||
|
(not= 0 duplicates)))
|
||||||
|
|
||||||
|
(spec/def ::unique-attr-name-per-schema
|
||||||
|
unique-attr-name-in-schema!)
|
||||||
|
|
||||||
|
(def schema
|
||||||
|
{:fields {:name {:label "Name"
|
||||||
|
:required true
|
||||||
|
:spec :wanijo.schema.domain/name}
|
||||||
|
:uuid {:widget :hidden}}})
|
||||||
|
|
||||||
|
(def attr-form
|
||||||
|
{:fields {:name {:label "Name"
|
||||||
|
:required true
|
||||||
|
:spec ::attr-domain/name
|
||||||
|
}
|
||||||
|
:type {:label "Type"
|
||||||
|
:required true
|
||||||
|
:spec ::attr-domain/type
|
||||||
|
:widget :select
|
||||||
|
:options (map #(vector (capitalize %) %)
|
||||||
|
attr-domain/types)}
|
||||||
|
:required {:label "Required"
|
||||||
|
:required false
|
||||||
|
:spec ::attr-domain/required
|
||||||
|
:widget :checkbox
|
||||||
|
:from-req #(if (some? %) 1 0)}
|
||||||
|
:uuid {:widget :hidden}}
|
||||||
|
:form-specs [::unique-attr-name-per-schema]})
|
||||||
|
|
||||||
|
(def assign-form
|
||||||
|
{:fields {:assigned {:label "Users"
|
||||||
|
:required false
|
||||||
|
:spec :wanijo.schema.domain/assigned-to
|
||||||
|
:widget :mselect
|
||||||
|
:from-req #(if (vector? %) % [%])}
|
||||||
|
:uuid {:widget :hidden}}})
|
||||||
|
|
||||||
|
(def schema-connections-form
|
||||||
|
{:fields {:connections {:label "Schemas"
|
||||||
|
:required false
|
||||||
|
:spec :wanijo.schema.domain/assigned-to
|
||||||
|
:widget :mselect
|
||||||
|
:from-req #(if (vector? %) % [%])}
|
||||||
|
:uuid {:widget :hidden}}})
|
Loading…
Reference in new issue