diff --git a/project.clj b/project.clj index d0619dc..10608b0 100644 --- a/project.clj +++ b/project.clj @@ -22,10 +22,13 @@ :plugins [[joshavg/lein-neo4j "0.3.0"] [lein-less "1.7.5"] [lein-ring "0.9.7"] - [lein-ancient "0.6.15"]]} + [lein-ancient "0.6.15"] + [jonase/eastwood "0.2.9"] + [lein-bikeshed "0.5.0"]]} :uberjar {:aot :all}} :ring {:handler wanijo.handler/app} :less {:source-paths ["resources/app/stylesheets"] :target-path "resources/public/css"} - :hiera {:cluster-depth 2}) + :hiera {:cluster-depth 2} + :eastwood {:namespaces [:source-paths]}) diff --git a/src/wanijo/attribute/routes.clj b/src/wanijo/attribute/routes.clj index fcf2414..0a970a2 100644 --- a/src/wanijo/attribute/routes.clj +++ b/src/wanijo/attribute/routes.clj @@ -5,7 +5,8 @@ [wanijo.framework.routing :refer [register! path]] [wanijo.attribute.domain :as domain] [wanijo.schema.view :as view-schema] - [wanijo.schema.domain :as domain-schema])) + [wanijo.schema.domain :as domain-schema] + [wanijo.schema.routes :as routes-schema])) (defn new! [req] (let [schema-uuid (get-in req [:params :schema])] @@ -16,20 +17,14 @@ schema-uuid (get-in req [:session :uuid])) (resp/redirect (path :schema-show {:uuid schema-uuid}))) - (view-schema/show-schema! - (domain-schema/find-by-uuid! schema-uuid) - (domain/find-by-schema! schema-uuid) - req)))) + (routes-schema/view! schema-uuid req)))) (defn edit! [schema-uuid req] (if (form/valid? view-schema/attr-form req) (do (domain/edit! (:params req)) (resp/redirect (path :schema-show {:uuid schema-uuid}))) - (view-schema/show-schema! - (domain-schema/find-by-uuid! schema-uuid) - (domain/find-by-schema! schema-uuid) - req))) + (routes-schema/view! schema-uuid req))) (defn delete! [uuid req] (domain/delete-by-uuid! uuid) diff --git a/src/wanijo/framework/form.clj b/src/wanijo/framework/form.clj index 23405df..5e45723 100644 --- a/src/wanijo/framework/form.clj +++ b/src/wanijo/framework/form.clj @@ -110,7 +110,11 @@ options (if validate? req-value value)))) -(defn render-multiselect [id {:keys [label spec options]} value req-value validate?] +(defn render-multiselect [id + {:keys [label spec options]} + value + req-value + validate?] (list (when (and validate? (not (spec/valid? spec req-value))) (spec-to-errmsg label spec value)) diff --git a/src/wanijo/framework/routing.clj b/src/wanijo/framework/routing.clj index 59f4aff..97bec0f 100644 --- a/src/wanijo/framework/routing.clj +++ b/src/wanijo/framework/routing.clj @@ -9,12 +9,12 @@ assoc id path) path) -(defn check-params [id path params] +(defn check-params [path params] (when (nil? path) (throw (ex-info - (str "Path " id " is not registered") - {:id id + "Path is not registered" + {:path path :params params}))) (let [matcher (re-matcher #":[^/]+" path) matches (take-while some? (repeatedly #(re-find matcher)))] @@ -28,10 +28,10 @@ "' does not exist in parameter map for path " path) {:path path - :params params - :id id})))))) + :params params})))))) (defn parse-path [path params] + (check-params path params) (reduce-kv (fn [new-path param-id param-value] (string/replace @@ -46,5 +46,4 @@ (path id {})) ([id params] (let [path (id @all-routes)] - (check-params id path params) (parse-path path params)))) diff --git a/src/wanijo/schema/routes.clj b/src/wanijo/schema/routes.clj index d07b0fa..3f7d505 100644 --- a/src/wanijo/schema/routes.clj +++ b/src/wanijo/schema/routes.clj @@ -18,17 +18,6 @@ (resp/redirect (path :schema-overview))) (view-schema/overview! req))) -(defn edit! [req] - (let [uuid (get-in req [:params :uuid])] - (if (form/valid? view-schema/form req) - (do - (domain/edit! (:params req)) - (resp/redirect (path :schema-show (:params req)))) - (view-schema/show-schema! - (domain/find-by-uuid! uuid) - (domain-attr/find-by-schema! uuid) - req)))) - (defn delete-schema! [uuid session] (if (domain/can-user-modify? uuid (:uuid session)) (do @@ -46,6 +35,14 @@ (domain-user/all!))) req)) +(defn edit! [req] + (let [uuid (get-in req [:params :uuid])] + (if (form/valid? view-schema/form req) + (do + (domain/edit! (:params req)) + (resp/redirect (path :schema-show (:params req)))) + (view! uuid req)))) + (defn assign! [req] (let [uuid (get-in req [:params :uuid]) users (get-in req [:params :assigned])] @@ -59,8 +56,6 @@ (resp/redirect (path :schema-show (:params req)))) (view! uuid req)))) -;; random change - (defroutes routes (GET (register! :schema-overview "/schema") [] diff --git a/src/wanijo/schema/view.clj b/src/wanijo/schema/view.clj index d02f616..3ae8a8e 100644 --- a/src/wanijo/schema/view.clj +++ b/src/wanijo/schema/view.clj @@ -89,7 +89,8 @@ (anti-forgery-field) (hform/hidden-field "schema" (:uuid schema)) (hform/submit-button {:class "delete-btn"} "Delete!") - [:label "Created at " [:em (prettify-dt (:created_at attr))]])])] + [:label "Created at " + [:em (prettify-dt (:created_at attr))]])])] [:h3 "New attribute"] (hform/form-to [:post (path :attribute-new)] (form/render-widgets attr-form {} req) diff --git a/test/wanijo/framework/routing_test.clj b/test/wanijo/framework/routing_test.clj index acfc5b3..653b1b0 100644 --- a/test/wanijo/framework/routing_test.clj +++ b/test/wanijo/framework/routing_test.clj @@ -14,4 +14,4 @@ (testing "additional params are ignored" (is (= (parse-path ":a" {:a 1 :b 2}) "1"))) (testing "all params are required" - (is (thrown? RuntimeException (parse-path ":a"))))) + (is (thrown? RuntimeException (parse-path ":a" {})))))