mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
+Person relation on Inhalte
This commit is contained in:
@@ -242,9 +242,58 @@ 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 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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") {
|
||||
|
||||
@@ -326,6 +326,7 @@
|
||||
<div class="rel-empty-text">Keine Personen verknüpft.</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
|
||||
<div data-role="relation-add-row" class="flex flex-col gap-2 mt-2 px-0">
|
||||
{{- if and $contentAgentsNew (gt (len $contentAgentsNew) 0) -}}
|
||||
{{- range $i, $r := $contentAgentsNew -}}
|
||||
@@ -367,6 +368,7 @@
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</div>
|
||||
|
||||
<div data-role="relation-add-panel" class="mt-2 px-0 hidden">
|
||||
<div class="rel-row">
|
||||
<div class="rel-grid">
|
||||
@@ -409,6 +411,7 @@
|
||||
<div data-role="relation-add-error" class="text-xs text-red-700 mt-2 hidden" data-error-empty="Bitte Akteur auswählen.">Bitte Akteur auswählen.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template data-role="relation-new-template">
|
||||
<div data-rel-row class="rel-row">
|
||||
<div class="rel-grid">
|
||||
@@ -437,6 +440,7 @@
|
||||
<input type="hidden" data-rel-input="id" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="mt-2 pb-2 flex justify-end gap-4">
|
||||
<a href="/personen/new/" class="text-gray-700 hover:text-slate-950 no-underline" target="_blank" rel="noreferrer">
|
||||
<i class="ri-add-line"></i> Neue Person
|
||||
@@ -447,6 +451,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</relations-editor>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user