mirror of
https://github.com/sigmasternchen/kukkubukku
synced 2025-03-15 07:18:54 +00:00
adding recipes now works
This commit is contained in:
parent
cdf92851ff
commit
101dd0bcc6
5 changed files with 130 additions and 2 deletions
|
@ -10,3 +10,36 @@ backendHome() {
|
||||||
content="$(getRecipesByUsername "$username" | template "templates/backend.fragment.templ")"
|
content="$(getRecipesByUsername "$username" | template "templates/backend.fragment.templ")"
|
||||||
template "templates/layout.html.templ"
|
template "templates/layout.html.templ"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
route GET "/backend/new" backendNew
|
||||||
|
backendNew() {
|
||||||
|
requireLoggedIn
|
||||||
|
htmlContent
|
||||||
|
endHeaders
|
||||||
|
|
||||||
|
title="Backend - New"
|
||||||
|
content="$(template "templates/backend.new.fragment.templ")"
|
||||||
|
template "templates/layout.html.templ"
|
||||||
|
}
|
||||||
|
|
||||||
|
route POST "/backend/new" backendAdd
|
||||||
|
backendAdd() {
|
||||||
|
requireLoggedIn
|
||||||
|
cacheFormData
|
||||||
|
|
||||||
|
name="$(formData "name")"
|
||||||
|
description="$(formData "description")"
|
||||||
|
qts="$(formData "qts")"
|
||||||
|
ingredients="$(formData "ingredients")"
|
||||||
|
|
||||||
|
if test "$(echo "$qts" | wc -l)" -ne "$(echo "$ingredients" | wc -l)"; then
|
||||||
|
status 400
|
||||||
|
endHeaders
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
addRecipe "$name" "$description" "$username" "$qts" "$ingredients"
|
||||||
|
|
||||||
|
redirect "/backend"
|
||||||
|
endHeaders
|
||||||
|
}
|
||||||
|
|
|
@ -14,3 +14,40 @@ getRecipesByUsername() {
|
||||||
users.username = '$(escape "$username")'
|
users.username = '$(escape "$username")'
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addRecipe() {
|
||||||
|
local name="$1"
|
||||||
|
local description="$2"
|
||||||
|
local username="$3"
|
||||||
|
local qts="$4"
|
||||||
|
local ingredients="$5"
|
||||||
|
|
||||||
|
local nrIngredients="$(echo "$qts" | wc -l)"
|
||||||
|
|
||||||
|
template <(cat <<EOF
|
||||||
|
START TRANSACTION;
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
@uid := id
|
||||||
|
FROM users
|
||||||
|
WHERE username = '$(escape "$username")';
|
||||||
|
|
||||||
|
INSERT INTO recipes
|
||||||
|
(userFk, name, description) VALUES
|
||||||
|
(@uid, '$(escape "$name")', '$(escape "$description")');
|
||||||
|
|
||||||
|
SELECT @rid := LAST_INSERT_ID();
|
||||||
|
|
||||||
|
{{ for i in \$(seq $nrIngredients); do }}
|
||||||
|
INSERT INTO ingredients
|
||||||
|
(recipeFk, name, quantity) VALUES
|
||||||
|
(@rid,
|
||||||
|
'{{ escape "\$(echo "\$ingredients" | tail -n +\$i | head -n 1)" | tr -d \\\\n }}',
|
||||||
|
'{{ escape "\$(echo "\$qts" | tail -n +\$i | head -n 1)" | tr -d \\\\n }}'
|
||||||
|
);
|
||||||
|
{{ done }}
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
EOF
|
||||||
|
) | execute
|
||||||
|
}
|
||||||
|
|
2
shochu
2
shochu
|
@ -1 +1 @@
|
||||||
Subproject commit 10b8f41076765a411feb7b716ed7a9de3f792531
|
Subproject commit 10cc312892f2851b60ada93585aeab0ff4f9356e
|
|
@ -1,5 +1,7 @@
|
||||||
<h1>Hi</h1>
|
<h1>Hi</h1>
|
||||||
You are {{ print $username }}.
|
You are {{ print $username }}.<br />
|
||||||
|
|
||||||
|
<a href="/backend/new">New Recipe</a>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{{ while read line; do }}
|
{{ while read line; do }}
|
||||||
|
|
56
templates/backend.new.fragment.templ
Normal file
56
templates/backend.new.fragment.templ
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<a href="/backend">Back</a>
|
||||||
|
<form method="POST" action="?">
|
||||||
|
<input type="text" name="name" placeholder="Name"><br />
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Qt.
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Ingredient
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="qts">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="ingredients">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="qts">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="ingredients">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="qts">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="ingredients">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="qts">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="ingredients">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="qts">
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="text" name="ingredients">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<textarea name="description" placeholder="Description"></textarea><br />
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
Loading…
Reference in a new issue