mirror of
https://github.com/sigmasternchen/kukkubukku
synced 2025-03-15 07:18:54 +00:00
displying recipes now works
This commit is contained in:
parent
101dd0bcc6
commit
f822e73362
3 changed files with 67 additions and 0 deletions
|
@ -9,3 +9,31 @@ home() {
|
|||
content="$(template "templates/home.fragment.templ")"
|
||||
template "templates/layout.html.templ"
|
||||
}
|
||||
|
||||
|
||||
route GET "/recipe" recipe
|
||||
recipe() {
|
||||
id="$(queryString "id")"
|
||||
|
||||
result="$(getRecipeById "$id")"
|
||||
|
||||
if test -z "$result"; then
|
||||
"$_404"
|
||||
return
|
||||
fi
|
||||
|
||||
htmlContent
|
||||
endHeaders
|
||||
|
||||
name="$(echo "$result" | head -n 1 | getColumns 1)"
|
||||
description="$(echo "$result" | head -n 1 | getColumns 2)"
|
||||
uid="$(echo "$result" | head -n 1 | getColumns 5)"
|
||||
author="$(echo "$result" | head -n 1 | getColumns 6)"
|
||||
qts="$(echo "$result" | getColumns 4)"
|
||||
ingredients="$(echo "$result" | getColumns 3)"
|
||||
nrIngredients="$(echo "$qts" | wc -l)"
|
||||
|
||||
title=""
|
||||
content="$(template "templates/recipe.fragment.templ")"
|
||||
template "templates/layout.html.templ"
|
||||
}
|
||||
|
|
|
@ -15,6 +15,26 @@ getRecipesByUsername() {
|
|||
EOF
|
||||
}
|
||||
|
||||
getRecipeById() {
|
||||
local id="$(echo "$1" | sed 's/[^0-9]//g')"
|
||||
|
||||
query <<EOF
|
||||
SELECT
|
||||
recipes.name,
|
||||
description,
|
||||
ingredients.name,
|
||||
ingredients.quantity,
|
||||
users.id,
|
||||
users.username
|
||||
FROM recipes
|
||||
INNER JOIN ingredients
|
||||
ON recipes.id = ingredients.recipeFk
|
||||
INNER JOIN users
|
||||
ON recipes.userFk = users.id
|
||||
WHERE recipes.id = $id
|
||||
EOF
|
||||
}
|
||||
|
||||
addRecipe() {
|
||||
local name="$1"
|
||||
local description="$2"
|
||||
|
|
19
templates/recipe.fragment.templ
Normal file
19
templates/recipe.fragment.templ
Normal file
|
@ -0,0 +1,19 @@
|
|||
<h1>{{ print "$name" }}</h1>
|
||||
<p>
|
||||
from <a href="/profile?id={{ print "$uid" }}">{{ print "$author" }}</a>
|
||||
</p>
|
||||
<table>
|
||||
{{ for i in $(seq $nrIngredients); do }}
|
||||
<tr>
|
||||
<td>
|
||||
{{ echo "$qts" | tail -n +$i | head -n 1 }}
|
||||
</td>
|
||||
<td>
|
||||
{{ echo "$ingredients" | tail -n +$i | head -n 1 }}
|
||||
</td>
|
||||
</tr>
|
||||
{{ done }}
|
||||
</table>
|
||||
<p>
|
||||
{{ print "$description" }}
|
||||
</p>
|
Loading…
Reference in a new issue