diff options
author | xengineering <me@xengineering.eu> | 2024-02-13 21:16:44 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-02-15 19:58:03 +0100 |
commit | 246687318e03fb649c30c4510e264e65b25ec6da (patch) | |
tree | e2cb89e19f68ca0bfaf040d6d6addbda1a470cda /view | |
parent | bf0ad86df2e64191f6c430c328fee211ac3affa7 (diff) | |
download | ceres-246687318e03fb649c30c4510e264e65b25ec6da.tar ceres-246687318e03fb649c30c4510e264e65b25ec6da.tar.zst ceres-246687318e03fb649c30c4510e264e65b25ec6da.zip |
view: Add edit view for model.Recipe type
Diffstat (limited to 'view')
-rw-r--r-- | view/html/recipe-edit.html | 39 | ||||
-rw-r--r-- | view/html/recipe.html | 1 | ||||
-rw-r--r-- | view/recipe.go | 8 |
3 files changed, 47 insertions, 1 deletions
diff --git a/view/html/recipe-edit.html b/view/html/recipe-edit.html new file mode 100644 index 0000000..d615a7f --- /dev/null +++ b/view/html/recipe-edit.html @@ -0,0 +1,39 @@ +{{define "recipe-edit"}} +<html> + {{ template "head" }} + <header> + <nav> + <a href="/">HOME</a> + </nav> + <h1>Recipe editor</h1> + </header> + <body> + <main> + <form> + <p> + <label>Title</label> + <input type="text" name="title" value="{{.Title}}"> + </p> + + <p> + <label>Portions</label> + <input type="number" name="portions" value="{{.Portions}}"> + </p> + + <p> + <label>URL</label> + <input type="text" name="url" value="{{.Url}}"> + </p> + + <p> + <label>Notes</label> + <input type="text" name="notes" value="{{.Notes}}"> + </p> + + <a href="/recipe/{{.Id}}"><button type="button">cancel</button></a> + </form> + </main> + {{ template "footer" }} + </body> +</html> +{{end}} diff --git a/view/html/recipe.html b/view/html/recipe.html index 30aecb5..c8db391 100644 --- a/view/html/recipe.html +++ b/view/html/recipe.html @@ -12,6 +12,7 @@ <p>Portions: {{.Portions}}</p> <p><a href="{{.Url}}">original recipe</a></p> <p>{{.Notes}}</p> + <a href="/recipe/{{.Id}}?edit=true"><button>edit</button></a> </main> {{ template "footer" }} </body> diff --git a/view/recipe.go b/view/recipe.go index 3739143..b0525a1 100644 --- a/view/recipe.go +++ b/view/recipe.go @@ -22,7 +22,13 @@ func Recipe(w http.ResponseWriter, r *http.Request) { return } - err = html.ExecuteTemplate(w, "recipe", recipe) + tmpl := "recipe" + edit, ok := r.URL.Query()["edit"] + if ok && len(edit) == 1 && edit[0] == "true" { + tmpl = "recipe-edit" + } + + err = html.ExecuteTemplate(w, tmpl, recipe) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return |