summaryrefslogtreecommitdiff
path: root/src/chef/frontend/admin/recipe_editor.clj
diff options
context:
space:
mode:
authorTim <contact@bytim.eu>2025-06-14 11:49:28 +0200
committerTim <contact@bytim.eu>2025-06-14 11:49:28 +0200
commit8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e (patch)
treec0f5b6587b6f9f0b591b395c69ad7da08717a30b /src/chef/frontend/admin/recipe_editor.clj
parent229299146376a2b847f4fe3f331efbd26c0abc70 (diff)
downloadchef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.tar.xz
chef-8e23d9dade945f87f5fc7fb15042a53a7eeb9a9e.zip
Refactor project structure
Diffstat (limited to 'src/chef/frontend/admin/recipe_editor.clj')
-rw-r--r--src/chef/frontend/admin/recipe_editor.clj63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/chef/frontend/admin/recipe_editor.clj b/src/chef/frontend/admin/recipe_editor.clj
new file mode 100644
index 0000000..69c84ba
--- /dev/null
+++ b/src/chef/frontend/admin/recipe_editor.clj
@@ -0,0 +1,63 @@
+(ns chef.frontend.admin.recipe-editor
+ (:require [hiccup2.core :as html]
+ [hiccup.util :as hutil]
+ [ring.util.response :as ruresp]
+ [chef.utils :as cutils]
+
+ [chef.logic.categories :as clcategories]
+ [chef.logic.recipes :as clrecipes]))
+
+(defn render [recipe]
+ (cutils/gen-page "chef - Rezept bearbeiten"
+ [:div {:style {:margin-left "1em"}}
+ [:h1 "Rezept bearbeiten"]
+ [:form {:style {:width "50%"}
+ :hx-post (str "/api/admin/recipe/" (:recipes/id recipe))
+ :hx-swap "none"
+ :enctype "multipart/form-data"}
+ [:input {:type :text :name "title" :placeholder "Titel"
+ :value (:recipes/title recipe)}]
+ [:div {:style {:display :flex}}
+ [:p {:style {:margin-right "0.5em"}} "Thumbnail: "]
+ [:input {:type :file :name "thumbnail"
+ :style {:height :fit-content
+ :padding "0.3em"}}]]
+ [:button {:class ["button" "error"]
+ :hx-trigger "click"
+ :hx-delete (str "/api/admin/recipe/" (:recipes/id recipe) "/thumbnail/")
+ :hx-swap :none}
+ "Thumbnail entfernen"]
+ [:h2 "Kategorie"]
+ [:select {:name "category"}
+ (for [category (clcategories/get-all-categories)]
+ [:option {:value (:categories/id category)
+ :selected (= (:categories/id category) (:recipes/category recipe))}
+ (clcategories/generate-path category)])]
+ [:h2 "Zutaten"]
+ [:div {:style {:display :flex}}
+ [:p {:style {:margin-right "0.5em"}} "Pro"]
+ [:select {:name "ingredients-unit"
+ :style {:height :fit-content
+ :padding "0.3em"}}
+ [:option {:value 0 :selected (= (:recipes/unit recipe) 0)} "Portion"]
+ [:option {:value 1 :selected (= (:recipes/unit recipe) 1)} "Person"]]
+ [:p ":"]]
+ [:textarea {:name "ingredients"}
+ (:recipes/ingredients recipe)]
+ [:p "(Je Zeile eine Zutat, in dem Format " [:code "[Beschreibung der Zutat]=[Menge als Zahl][Einheit der Menge]"] ".)"]
+ [:h2 "Zubereitung"]
+ [:textarea {:name "preparation"}
+ (:recipes/preparation recipe)]
+ [:button {:type :submit
+ :style {:margin-top "1em"}} "Speichern"]]]
+ [:script (hutil/raw-string "window.addEventListener(\"htmx:afterRequest\", () => window.close())")]))
+
+(defn handler [req]
+ (cutils/auth-only req
+ (if-let [id (cutils/s->int-or-nil (get-in req [:path-params :id]))]
+ (->> (clrecipes/get-recipe id)
+ render
+ html/html
+ str
+ ruresp/response)
+ (ruresp/bad-request "Bad request."))))