summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chef/pages/admin.clj44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/chef/pages/admin.clj b/src/chef/pages/admin.clj
index fb6eeee..a35a3a5 100644
--- a/src/chef/pages/admin.clj
+++ b/src/chef/pages/admin.clj
@@ -1,7 +1,32 @@
(ns chef.pages.admin
(:require [chef.utils :as cutils]
[hiccup2.core :as html]
- [ring.util.response :as ruresp]))
+ [ring.util.response :as ruresp]
+ [chef.database :as cdb]
+ [next.jdbc :as jdbc]
+ [honey.sql :as sql]))
+
+(defn- render-category [data children]
+ [:li
+ [:p {:style {:display :inline-block}} (if (some? data)
+ [:input {:type :text :placeholder "Name"
+ :value (:categories/name data)}]
+ "Startseite")]
+ [:p {:style {:display :inline-block
+ :margin-left "1em"
+ :margin-right "1em"}} "->"]
+ [:input {:type :text :placeholder "Frage"
+ :style {:display :inline-block
+ :width :auto}
+ :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-swap "none"}]
+ [:ul
+ (for [child children]
+ (render-category child nil))]])
(defn- render []
(cutils/gen-page "chef - Admin"
@@ -9,19 +34,10 @@
[:h2 "Kategorien"]
;;TODO: add delete icons to non-root categories
[:ul
- [:li
- [:p {:style {:display :inline-block}} "Startseite"]
- [:p {:style {:display :inline-block
- :margin-left "1em"
- :margin-right "1em"}} "->"]
- [:input {:type :text :placeholder "Frage"
- :style {:display :inline-block
- :width :auto}}] ; 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-swap "none"}]]]
+ (render-category nil
+ (->> (sql/format {:select [:*] :from [:categories]})
+ (jdbc/execute! @cdb/db)
+ (filter #(nil? (:categories/parent %)))))]
[:h2 "Rezepte"]
[:i "Coming soon..."]))