diff options
author | Tim <contact@bytim.eu> | 2025-06-14 11:49:28 +0200 |
---|---|---|
committer | Tim <contact@bytim.eu> | 2025-06-14 11:49:28 +0200 |
commit | 8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e (patch) | |
tree | c0f5b6587b6f9f0b591b395c69ad7da08717a30b /src/chef/pages/admin.clj | |
parent | 229299146376a2b847f4fe3f331efbd26c0abc70 (diff) | |
download | chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.tar.xz chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.zip |
Refactor project structure
Diffstat (limited to 'src/chef/pages/admin.clj')
-rw-r--r-- | src/chef/pages/admin.clj | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/chef/pages/admin.clj b/src/chef/pages/admin.clj deleted file mode 100644 index ea19cc3..0000000 --- a/src/chef/pages/admin.clj +++ /dev/null @@ -1,118 +0,0 @@ -(ns chef.pages.admin - (:require [chef.utils :as cutils] - [hiccup2.core :as html] - [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 (pos? (:categories/id data)) - [:input {:type :text :placeholder "Name" - :value (:categories/name data) - :name "name" - :hx-post (str "/api/admin/edit-category/" (:categories/id data)) - :hx-trigger "change"}] - "Startseite")] - (when (or (neg? (:categories/id data)) - (->> (sql/format {:select [:*] - :from [:categories] - :where [:= :parent (:categories/id data)]}) - (jdbc/execute! @cdb/db) - count - pos?)) - (list [:p {:style {:display :inline-block - :margin-left "1em" - :margin-right "1em"}} "->"] - [:input {:type :text :placeholder "Frage" - :style {:display :inline-block - :width :auto} - :value (:categories/question data) - :name "question" - :hx-post (str "/api/admin/edit-category/" (:categories/id data)) - :hx-trigger "change"}])) - [:img {:src "/static/icons/plus.svg" :height "30em" - :style {:vertical-align :middle - :margin-left "1em"} - :hx-post (str "/api/admin/create-category" - (when (pos? (:categories/id data)) (str "?parent=" (:categories/id data)))) - :hx-swap "none"}] - (when (pos? (:categories/id data)) - [:img {:src "/static/icons/trash.svg" :height "30em" - :style {:vertical-align :middle - :margin-left "1em"} - :hx-delete (str "/api/admin/delete-category/" (:categories/id data)) - :hx-swap "none"}]) - [:ul - (for [child children] - (render-category child (->> (sql/format {:select [:*] - :from [:categories] - :where [:= :parent (:categories/id child)]}) - (jdbc/execute! @cdb/db))))]]) - -(defn- render-recipe-table-row [recipe] - (let [tr-id (str "recipe-" (:recipes/id recipe))] - [:tr {:id tr-id} - [:td - [:p (:recipes/title recipe)]] - [:td - (let [category (->> (sql/format {:select [:*] - :from [:categories] - :where [:= :id (:recipes/category recipe)]}) - (jdbc/execute! @cdb/db) - first)] - [:p (cutils/category-path category)])] - [:td - [:div - [:button {:class ["button" "primary"] - :onclick (str "window.open(\"/admin/recipe-editor/" - (:recipes/id recipe) - "\", \"\", \"width=900,height=900\")")} - "Bearbeiten"] - [:button {:class ["button error"] - :hx-trigger "click" - :hx-swap :none - :hx-delete (str "/api/admin/delete-recipe/" (:recipes/id recipe))} - "Löschen"]]]])) - -(defn- render [] - (cutils/gen-page "chef - Admin" - [:div {:style {:margin-left "1em"}} - [:h1 "chef - Admin"] - [:h2 "Kategorien"] - [:ul - (render-category (first (->> (sql/format {:select [:*] - :from [:categories] - :where [:= :id -1]}) - (jdbc/execute! @cdb/db))) - (->> (sql/format {:select [:*] - :from [:categories] - :where [:= :parent -1]}) - (jdbc/execute! @cdb/db)))] - [:h2 "Rezepte"] - [:table - [:tr - [:th "Titel"] - [:th "Kategorie"] - [:th "Aktionen"]] - (for [recipe (jdbc/execute! @cdb/db - (sql/format {:select [:*] - :from [:recipes]}))] - (render-recipe-table-row recipe))] - [:button {:class "button primary" - :hx-trigger "click" - :hx-swap :none - :hx-post "/api/admin/create-recipe"} - "Rezept erstellen"]])) - -(defn handler [req] - (let [access-token (get-in req [:oauth2/access-tokens :auth]) - resp (-> (render) - html/html - str - ruresp/response)] - (if (some? access-token) - (assoc resp :session (assoc (:session req) :oauth-token access-token)) - (cutils/auth-only req resp)))) |