From 9413240165ca71e7983de724f017640470239de0 Mon Sep 17 00:00:00 2001 From: roberto Date: Fri, 17 Jan 2025 18:00:46 +0100 Subject: [PATCH] Item shares form page --- assets/templates/items/form.tmpl | 4 +- assets/templates/items/shares.tmpl | 61 ++++++++++++++++++++++++++++++ cmd/web/items_handlers.go | 2 + 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 assets/templates/items/shares.tmpl diff --git a/assets/templates/items/form.tmpl b/assets/templates/items/form.tmpl index 4f1a79c..c0b04f3 100644 --- a/assets/templates/items/form.tmpl +++ b/assets/templates/items/form.tmpl @@ -18,7 +18,9 @@ Fields {{ end }} Relations + {{ if $fields_present }} Shares + {{ end }}
@@ -108,7 +110,7 @@ {{ if $shares_present }} {{ end }} diff --git a/assets/templates/items/shares.tmpl b/assets/templates/items/shares.tmpl new file mode 100644 index 0000000..cec6e95 --- /dev/null +++ b/assets/templates/items/shares.tmpl @@ -0,0 +1,61 @@ +{{define "item:shares"}} + + + + + + + + + + + +{{ range .item.Relations}} +{{ $relation_name := printf "%s%v-%v" "ItemRelation-" .Item_id .Related_item_id }} +{{ $relation_name_remove := printf "%s%v-%v" "ItemRelation-ToRemove-" .Item_id .Related_item_id }} + + + + + + + + {{ end }} + +
ItemCategoriesTagsRelation type
+ {{ $target_id := .Related_item_id}} + {{ $relation_type := .Relation_type }} + {{ if eq .Related_item_id $.item.Id }} + {{ $target_id = .Item_id}} + {{ if eq "Parent" .Relation_type}} + {{ $relation_type = "Child" }} + {{ else if eq "Child" .Relation_type}} + {{ $relation_type = "Parent" }} + {{ end }} + {{ end }} + {{.Title}} + + + {{ if gt (len .Categories) 0 }} + + {{ range (stringToArray .Categories "|")}} + {{ $category_name := index $.categoriesMap .}} +
+ {{ $category_name }} +
+ {{ end }} + {{ end }} +
+ {{ if gt (len .Tags) 0 }} + + {{ range (stringToArray .Tags ",")}} +
+ {{ . }} +
+ {{ end }} + {{ end }} +
{{ widget_relation_type $relation_name $relation_type `id="$relation_name"` }} + + +
+ {{ end }} diff --git a/cmd/web/items_handlers.go b/cmd/web/items_handlers.go index 5686a1b..3517813 100644 --- a/cmd/web/items_handlers.go +++ b/cmd/web/items_handlers.go @@ -710,6 +710,7 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) { notebooks := strings.Split(strings.Trim(item.Notebooks, "|"), "|") categories := strings.Split(strings.Trim(item.Categories, "|"), "|") relations, _, _ := itemModel.GetRelations(item.Id) + shares, _, _ := itemModel.GetShares(item.Id) data["item"] = itemForm{ Id: item.Id, @@ -728,6 +729,7 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) { Categories: categories, Notebooks: notebooks, Relations: relations, + Shares: shares, } data["categories"] = categoryModel.AllAsOptions()