diff options
Diffstat (limited to 'src/chef/pages/admin.clj')
-rw-r--r-- | src/chef/pages/admin.clj | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/src/chef/pages/admin.clj b/src/chef/pages/admin.clj index e38dac3..25f99a6 100644 --- a/src/chef/pages/admin.clj +++ b/src/chef/pages/admin.clj @@ -52,21 +52,60 @@ :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=500,height=500\")")} + "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" - [: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 [:and [:is :parent :null] [:> :id 0]]}) - (jdbc/execute! @cdb/db)))] - [:h2 "Rezepte"] - [:i "Coming soon..."])) + [: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 [:and [:is :parent :null] [:> :id 0]]}) + (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]) |