diff --git a/controllers/almanach_contents_edit.go b/controllers/almanach_contents_edit.go index a9217b0..6a43c45 100644 --- a/controllers/almanach_contents_edit.go +++ b/controllers/almanach_contents_edit.go @@ -242,8 +242,57 @@ func (p *AlmanachContentsEditPage) POSTSave(engine *templating.Engine, app core. redirect := fmt.Sprintf("/almanach/%s/contents/edit?saved_message=%s", id, url.QueryEscape("Änderungen gespeichert.")) if isHTMX { - e.Response.Header().Set("HX-Redirect", redirect) - return e.String(http.StatusOK, "") + renderID := "" + for contentID := range contentInputs { + renderID = contentID + break + } + var renderContent *dbmodels.Content + if renderID != "" { + if existing, ok := existingByID[renderID]; ok { + renderContent = existing + } else if len(newContentIDs) > 0 && len(updatedContents) > 0 { + renderContent = updatedContents[len(updatedContents)-1] + } + } + if renderContent == nil && renderID != "" { + if refreshed, err := dbmodels.Contents_IDs(app, []any{renderID}); err == nil && len(refreshed) > 0 { + renderContent = refreshed[0] + } + } + if renderContent == nil { + e.Response.Header().Set("HX-Redirect", redirect) + return e.String(http.StatusOK, "") + } + if refreshed, err := dbmodels.Contents_IDs(app, []any{renderContent.Id}); err == nil && len(refreshed) > 0 { + renderContent = refreshed[0] + } + agentsMap, contentAgentsMap, err := dbmodels.AgentsForContents(app, []*dbmodels.Content{renderContent}) + if err != nil { + agentsMap = map[string]*dbmodels.Agent{} + contentAgentsMap = map[string][]*dbmodels.RContentsAgents{} + } + data := map[string]any{ + "content": renderContent, + "content_id": renderContent.Id, + "entry": entry, + "csrf_token": req.Session().Token, + "content_types": dbmodels.CONTENT_TYPE_VALUES, + "musenalm_types": dbmodels.MUSENALM_TYPE_VALUES, + "pagination_values": paginationValuesSorted(), + "agent_relations": dbmodels.AGENT_RELATIONS, + "agents": agentsMap, + "content_agents": contentAgentsMap[renderContent.Id], + "open_edit": false, + "is_new": false, + } + var builder strings.Builder + if err := engine.Render(&builder, "/almanach/contents/item/", data, "fragment"); err != nil { + app.Logger().Error("Failed to render content save", "entry_id", entry.Id, "content_id", renderContent.Id, "error", err) + e.Response.Header().Set("HX-Redirect", redirect) + return e.String(http.StatusOK, "") + } + return e.HTML(http.StatusOK, builder.String()) } return e.Redirect(http.StatusSeeOther, redirect) } diff --git a/views/routes/almanach/contents/edit/body.gohtml b/views/routes/almanach/contents/edit/body.gohtml index d43afbc..20f8e10 100644 --- a/views/routes/almanach/contents/edit/body.gohtml +++ b/views/routes/almanach/contents/edit/body.gohtml @@ -224,6 +224,9 @@ }; items.forEach((item) => { + if (item.parentElement !== list) { + return; + } const contentId = item.querySelector("[data-role='content-card']")?.dataset.contentId || ""; list.insertBefore(createGap("before", contentId, false), item); }); @@ -242,6 +245,17 @@ const syncEditSpacing = () => { setEditSpacing(!!list.querySelector("[data-role='content-item'].data-editing")); }; + const showEditButtonsIfIdle = () => { + if (list.querySelector("[data-role='content-item'].data-editing")) { + return; + } + getItems().forEach((item) => { + const editButton = item.querySelector("[data-role='content-edit-button']"); + if (editButton) { + editButton.classList.remove("hidden"); + } + }); + }; if (getItems().length === 0) { return; } @@ -561,6 +575,7 @@ getItems().forEach((item) => setupItem(item)); renderInsertGaps(); syncEditSpacing(); + showEditButtonsIfIdle(); updateCollapseAllLabel(); if (list.dataset.pageInit !== "true") { diff --git a/views/routes/components/_content_edit.gohtml b/views/routes/components/_content_edit.gohtml index 92a0b61..8c51a79 100644 --- a/views/routes/components/_content_edit.gohtml +++ b/views/routes/components/_content_edit.gohtml @@ -228,132 +228,207 @@
- {{- if and $contentAgentsRender (gt (len $contentAgentsRender) 0) -}} - {{- range $i, $r := $contentAgentsRender -}} - {{- $a := index $agents $r.Agent -}} -
-
-
- {{- if $a -}} - - {{- $a.Name -}} - - {{- if $a.BiographicalData -}} -
{{- $a.BiographicalData -}}
+ {{- if and $contentAgentsRender (gt (len $contentAgentsRender) 0) -}} + {{- range $i, $r := $contentAgentsRender -}} + {{- $a := index $agents $r.Agent -}} +
+
+
+ {{- if $a -}} + + {{- $a.Name -}} + + {{- if $a.BiographicalData -}} +
{{- $a.BiographicalData -}}
+ {{- end -}} + {{- else -}} +
Unbekannte Person
{{- end -}} - {{- else -}} -
Unbekannte Person
- {{- end -}} -
-
- -
-
- - -
-
- - +
+
+ +
+
+ + +
+
+ + +
+ +
- - -
- {{- end -}} - {{- else if $contentAgents -}} - {{- range $i, $r := $contentAgents -}} - {{- $a := index $agents $r.Agent -}} -
-
-
- {{- if $a -}} - - {{- $a.Name -}} - - {{- if $a.BiographicalData -}} -
{{- $a.BiographicalData -}}
+ {{- end -}} + {{- else if $contentAgents -}} + {{- range $i, $r := $contentAgents -}} + {{- $a := index $agents $r.Agent -}} +
+
+
+ {{- if $a -}} + + {{- $a.Name -}} + + {{- if $a.BiographicalData -}} +
{{- $a.BiographicalData -}}
+ {{- end -}} + {{- else -}} +
Unbekannte Person
{{- end -}} - {{- else -}} -
Unbekannte Person
- {{- end -}} -
-
- -
-
- - -
-
- - +
+
+ +
+
+ + +
+
+ + +
+ +
- - -
+ {{- end -}} + {{- else -}} +
Keine Personen verknüpft.
{{- end -}} - {{- else -}} -
Keine Personen verknüpft.
- {{- end -}}
+
- {{- if and $contentAgentsNew (gt (len $contentAgentsNew) 0) -}} - {{- range $i, $r := $contentAgentsNew -}} - {{- $a := index $agents $r.Agent -}} + {{- if and $contentAgentsNew (gt (len $contentAgentsNew) 0) -}} + {{- range $i, $r := $contentAgentsNew -}} + {{- $a := index $agents $r.Agent -}} +
+
+
+ + {{- if $a -}} + {{- if $a.BiographicalData -}} +
{{- $a.BiographicalData -}}
+ {{- end -}} + {{- end -}} +
+
+ +
+
+ + +
+
+ +
+
+ +
+ {{- end -}} + {{- end -}} +
+ + + +