summaryrefslogtreecommitdiff
path: root/src/chef/pages/admin.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/chef/pages/admin.clj')
-rw-r--r--src/chef/pages/admin.clj19
1 files changed, 12 insertions, 7 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..."]))