summaryrefslogtreecommitdiff
path: root/src/chef
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef')
-rw-r--r--src/chef/pages/admin.clj19
-rw-r--r--src/chef/pages/admin/api.clj7
2 files changed, 17 insertions, 9 deletions
diff --git a/src/chef/pages/admin.clj b/src/chef/pages/admin.clj
index a35a3a5..73cf127 100644
--- a/src/chef/pages/admin.clj
+++ b/src/chef/pages/admin.clj
@@ -9,7 +9,7 @@
(defn- render-category [data children]
[:li
[:p {:style {:display :inline-block}} (if (some? data)
- [:input {:type :text :placeholder "Name"
+ [:input {:type :text :placeholder "Name"
:value (:categories/name data)}]
"Startseite")]
[:p {:style {:display :inline-block
@@ -18,15 +18,19 @@
[:input {:type :text :placeholder "Frage"
:style {:display :inline-block
:width :auto}
- :value (:category/name data)}] ; TODO: only show when category has children
+ :value (:category/name data)}] ; TODO: only show when category has children
[:img {:src "/static/icons/plus.svg" :height "30em"
:style {:vertical-align :middle
:margin-left "1em"}
- :hx-post "/api/admin/create-category"
+ :hx-post (str "/api/admin/create-category"
+ (when (some? data) (str "?parent=" (:categories/id data))))
:hx-swap "none"}]
[:ul
(for [child children]
- (render-category child nil))]])
+ (render-category child (->> (sql/format {:select [:*]
+ :from [:categories]
+ :where [:= :parent (:categories/id child)]})
+ (jdbc/execute! @cdb/db))))]])
(defn- render []
(cutils/gen-page "chef - Admin"
@@ -35,9 +39,10 @@
;;TODO: add delete icons to non-root categories
[:ul
(render-category nil
- (->> (sql/format {:select [:*] :from [:categories]})
- (jdbc/execute! @cdb/db)
- (filter #(nil? (:categories/parent %)))))]
+ (->> (sql/format {:select [:*]
+ :from [:categories]
+ :where [:is :parent :null]})
+ (jdbc/execute! @cdb/db)))]
[:h2 "Rezepte"]
[:i "Coming soon..."]))
diff --git a/src/chef/pages/admin/api.clj b/src/chef/pages/admin/api.clj
index 2eb797b..0d1910a 100644
--- a/src/chef/pages/admin/api.clj
+++ b/src/chef/pages/admin/api.clj
@@ -7,7 +7,10 @@
(defn create-category [req]
(cutils/auth-only req
- (jdbc/execute! @cdb/db (sql/format {:insert-into [:categories]
- :values [{:name "New category"}]}))
+ (jdbc/execute! @cdb/db
+ (sql/format {:insert-into [:categories]
+ :values [(merge {:name "New category"}
+ (when-let [parent (get-in req [:params "parent"])]
+ {:parent parent}))]}))
(-> (ruresp/created "Created.")
(ruresp/header "HX-Refresh" "true"))))