diff options
author | Tim <contact@bytim.eu> | 2025-05-15 20:39:13 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-05-15 20:39:13 +0200 |
commit | 961b54f93581e2756a7ad6be5f990ccb2e8b2aaf (patch) | |
tree | aa632138b20a3ca6043384e5ec13449f7ae7cb8a | |
parent | bf0b9dacdb96202d563cb508e6c62785aba4eb80 (diff) | |
download | chef-961b54f93581e2756a7ad6be5f990ccb2e8b2aaf.tar.xz chef-961b54f93581e2756a7ad6be5f990ccb2e8b2aaf.zip |
admin page: list categories
-rw-r--r-- | src/chef/pages/admin.clj | 44 |
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..."])) |