mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
further frontend annoyances
This commit is contained in:
@@ -68,6 +68,7 @@ func (p *AlmanachContentsEditPage) GET(engine *templating.Engine, app core.App)
|
||||
data["content_types"] = dbmodels.CONTENT_TYPE_VALUES
|
||||
data["musenalm_types"] = dbmodels.MUSENALM_TYPE_VALUES
|
||||
data["pagination_values"] = paginationValuesSorted()
|
||||
data["agent_relations"] = dbmodels.AGENT_RELATIONS
|
||||
|
||||
if msg := e.Request.URL.Query().Get("saved_message"); msg != "" {
|
||||
data["success"] = msg
|
||||
@@ -92,6 +93,7 @@ func (p *AlmanachContentsEditPage) renderError(engine *templating.Engine, app co
|
||||
data["content_types"] = dbmodels.CONTENT_TYPE_VALUES
|
||||
data["musenalm_types"] = dbmodels.MUSENALM_TYPE_VALUES
|
||||
data["pagination_values"] = paginationValuesSorted()
|
||||
data["agent_relations"] = dbmodels.AGENT_RELATIONS
|
||||
data["error"] = message
|
||||
data["edit_content_id"] = strings.TrimSpace(e.Request.URL.Query().Get("edit_content"))
|
||||
data["new_content"] = strings.TrimSpace(e.Request.URL.Query().Get("new_content"))
|
||||
@@ -125,6 +127,14 @@ func (p *AlmanachContentsEditPage) POSTSave(engine *templating.Engine, app core.
|
||||
contentInputs := parseContentsForm(e.Request.PostForm)
|
||||
contentOrder := parseContentsOrder(e.Request.PostForm)
|
||||
orderMap := buildContentOrderMap(contentOrder)
|
||||
relationsByContent := map[string]contentAgentRelationsPayload{}
|
||||
for contentID := range contentInputs {
|
||||
payload := parseContentAgentRelations(e.Request.PostForm, contentID)
|
||||
if err := validateContentAgentRelations(payload); err != nil {
|
||||
return p.renderSaveError(engine, app, e, req, nil, nil, err.Error(), isHTMX)
|
||||
}
|
||||
relationsByContent[contentID] = payload
|
||||
}
|
||||
user := req.User()
|
||||
existingByID := make(map[string]*dbmodels.Content, len(contents))
|
||||
for _, content := range contents {
|
||||
@@ -192,6 +202,11 @@ func (p *AlmanachContentsEditPage) POSTSave(engine *templating.Engine, app core.
|
||||
if err := tx.Save(content); err != nil {
|
||||
return err
|
||||
}
|
||||
if relations, ok := relationsByContent[tempID]; ok {
|
||||
if err := applyContentAgentRelations(tx, content, relations); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
created = append(created, content)
|
||||
}
|
||||
for _, content := range contents {
|
||||
@@ -206,6 +221,11 @@ func (p *AlmanachContentsEditPage) POSTSave(engine *templating.Engine, app core.
|
||||
if err := tx.Save(content); err != nil {
|
||||
return err
|
||||
}
|
||||
if relations, ok := relationsByContent[content.Id]; ok {
|
||||
if err := applyContentAgentRelations(tx, content, relations); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
updatedContents = append(updatedContents, contents...)
|
||||
updatedContents = append(updatedContents, created...)
|
||||
@@ -267,6 +287,9 @@ func (p *AlmanachContentsEditPage) POSTInsert(engine *templating.Engine, app cor
|
||||
"content_types": dbmodels.CONTENT_TYPE_VALUES,
|
||||
"musenalm_types": dbmodels.MUSENALM_TYPE_VALUES,
|
||||
"pagination_values": paginationValuesSorted(),
|
||||
"agent_relations": dbmodels.AGENT_RELATIONS,
|
||||
"agents": map[string]*dbmodels.Agent{},
|
||||
"content_agents": []*dbmodels.RContentsAgents{},
|
||||
"open_edit": true,
|
||||
"is_new": true,
|
||||
"content_id": record.Id,
|
||||
@@ -424,6 +447,49 @@ func (p *AlmanachContentsEditPage) renderSaveError(
|
||||
isNew = true
|
||||
}
|
||||
|
||||
relationsPayload := parseContentAgentRelations(e.Request.PostForm, contentID)
|
||||
if err := validateContentAgentRelations(relationsPayload); err != nil {
|
||||
return p.renderError(engine, app, e, err.Error())
|
||||
}
|
||||
|
||||
renderRelations := []contentAgentRender{}
|
||||
renderNewRelations := []contentAgentRender{}
|
||||
agentIDs := map[string]struct{}{}
|
||||
for _, relation := range relationsPayload.Relations {
|
||||
renderRelations = append(renderRelations, contentAgentRender{
|
||||
Id: relation.ID,
|
||||
Agent: relation.TargetID,
|
||||
Type: relation.Type,
|
||||
Uncertain: relation.Uncertain,
|
||||
})
|
||||
if relation.TargetID != "" {
|
||||
agentIDs[relation.TargetID] = struct{}{}
|
||||
}
|
||||
}
|
||||
for _, relation := range relationsPayload.NewRelations {
|
||||
renderNewRelations = append(renderNewRelations, contentAgentRender{
|
||||
Agent: relation.TargetID,
|
||||
Type: relation.Type,
|
||||
Uncertain: relation.Uncertain,
|
||||
})
|
||||
if relation.TargetID != "" {
|
||||
agentIDs[relation.TargetID] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
agentsMap := map[string]*dbmodels.Agent{}
|
||||
if len(agentIDs) > 0 {
|
||||
ids := make([]any, 0, len(agentIDs))
|
||||
for id := range agentIDs {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if agents, err := dbmodels.Agents_IDs(app, ids); err == nil {
|
||||
for _, agent := range agents {
|
||||
agentsMap[agent.Id] = agent
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numbering := 0.0
|
||||
if order := parseContentsOrder(e.Request.PostForm); len(order) > 0 {
|
||||
if mapped, ok := buildContentOrderMap(order)[contentID]; ok {
|
||||
@@ -440,6 +506,10 @@ func (p *AlmanachContentsEditPage) renderSaveError(
|
||||
"content_types": dbmodels.CONTENT_TYPE_VALUES,
|
||||
"musenalm_types": dbmodels.MUSENALM_TYPE_VALUES,
|
||||
"pagination_values": paginationValuesSorted(),
|
||||
"agent_relations": dbmodels.AGENT_RELATIONS,
|
||||
"agents": agentsMap,
|
||||
"content_agents_render": renderRelations,
|
||||
"content_agents_new": renderNewRelations,
|
||||
"open_edit": true,
|
||||
"is_new": isNew,
|
||||
"error": message,
|
||||
@@ -482,6 +552,136 @@ func parseContentsForm(form url.Values) map[string]map[string][]string {
|
||||
return contentInputs
|
||||
}
|
||||
|
||||
type contentAgentRelationPayload struct {
|
||||
ID string
|
||||
TargetID string
|
||||
Type string
|
||||
Uncertain bool
|
||||
}
|
||||
|
||||
type contentAgentRelationsPayload struct {
|
||||
Relations []contentAgentRelationPayload
|
||||
NewRelations []contentAgentRelationPayload
|
||||
DeletedIDs []string
|
||||
}
|
||||
|
||||
type contentAgentRender struct {
|
||||
Id string
|
||||
Agent string
|
||||
Type string
|
||||
Uncertain bool
|
||||
}
|
||||
|
||||
func valuesForKey(form url.Values, key string) []string {
|
||||
if values, ok := form[key]; ok {
|
||||
return values
|
||||
}
|
||||
if values, ok := form[key+"[]"]; ok {
|
||||
return values
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func hasKey(form url.Values, key string) bool {
|
||||
_, ok := form[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
func parseContentAgentRelations(form url.Values, contentID string) contentAgentRelationsPayload {
|
||||
payload := contentAgentRelationsPayload{}
|
||||
if contentID == "" {
|
||||
return payload
|
||||
}
|
||||
prefix := fmt.Sprintf("content_%s_agents_", contentID)
|
||||
idPrefix := prefix + "id["
|
||||
|
||||
for key, values := range form {
|
||||
if !strings.HasPrefix(key, idPrefix) {
|
||||
continue
|
||||
}
|
||||
relationKey := strings.TrimSuffix(strings.TrimPrefix(key, idPrefix), "]")
|
||||
relationID := strings.TrimSpace(firstValue(values))
|
||||
if relationKey == "" || relationID == "" {
|
||||
continue
|
||||
}
|
||||
targetKey := fmt.Sprintf("%sagent[%s]", prefix, relationKey)
|
||||
typeKey := fmt.Sprintf("%stype[%s]", prefix, relationKey)
|
||||
deleteKey := fmt.Sprintf("%sdelete[%s]", prefix, relationKey)
|
||||
uncertainKey := fmt.Sprintf("%suncertain[%s]", prefix, relationKey)
|
||||
|
||||
targetID := strings.TrimSpace(firstValue(valuesForKey(form, targetKey)))
|
||||
if targetID == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := form[deleteKey]; ok {
|
||||
payload.DeletedIDs = append(payload.DeletedIDs, relationID)
|
||||
continue
|
||||
}
|
||||
payload.Relations = append(payload.Relations, contentAgentRelationPayload{
|
||||
ID: relationID,
|
||||
TargetID: targetID,
|
||||
Type: strings.TrimSpace(firstValue(valuesForKey(form, typeKey))),
|
||||
Uncertain: hasKey(form, uncertainKey),
|
||||
})
|
||||
}
|
||||
|
||||
newIDs := valuesForKey(form, prefix+"new_id")
|
||||
newTypes := valuesForKey(form, prefix+"new_type")
|
||||
newUncertain := valuesForKey(form, prefix+"new_uncertain")
|
||||
uncertainSet := map[string]struct{}{}
|
||||
for _, value := range newUncertain {
|
||||
trimmed := strings.TrimSpace(value)
|
||||
if trimmed == "" {
|
||||
continue
|
||||
}
|
||||
uncertainSet[trimmed] = struct{}{}
|
||||
}
|
||||
|
||||
for index, targetID := range newIDs {
|
||||
targetID = strings.TrimSpace(targetID)
|
||||
if targetID == "" {
|
||||
continue
|
||||
}
|
||||
relationType := ""
|
||||
if index < len(newTypes) {
|
||||
relationType = strings.TrimSpace(newTypes[index])
|
||||
}
|
||||
_, uncertain := uncertainSet[targetID]
|
||||
payload.NewRelations = append(payload.NewRelations, contentAgentRelationPayload{
|
||||
TargetID: targetID,
|
||||
Type: relationType,
|
||||
Uncertain: uncertain,
|
||||
})
|
||||
}
|
||||
|
||||
return payload
|
||||
}
|
||||
|
||||
func validateContentAgentRelations(payload contentAgentRelationsPayload) error {
|
||||
for _, relation := range payload.Relations {
|
||||
if err := validateRelationTypeValue(relation.Type, dbmodels.AGENT_RELATIONS); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, relation := range payload.NewRelations {
|
||||
if err := validateRelationTypeValue(relation.Type, dbmodels.AGENT_RELATIONS); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRelationTypeValue(value string, allowed []string) error {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return fmt.Errorf("Ungültiger Beziehungstyp.")
|
||||
}
|
||||
if !slices.Contains(allowed, value) {
|
||||
return fmt.Errorf("Ungültiger Beziehungstyp.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyContentForm(content *dbmodels.Content, entry *dbmodels.Entry, fields map[string][]string, user *dbmodels.FixedUser, numbering float64) error {
|
||||
preferredTitle := buildContentPreferredTitle(content, fields)
|
||||
if preferredTitle == "" {
|
||||
@@ -554,6 +754,86 @@ func applyContentForm(content *dbmodels.Content, entry *dbmodels.Entry, fields m
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyContentAgentRelations(tx core.App, content *dbmodels.Content, payload contentAgentRelationsPayload) error {
|
||||
if content == nil {
|
||||
return nil
|
||||
}
|
||||
tableName := dbmodels.RelationTableName(dbmodels.CONTENTS_TABLE, dbmodels.AGENTS_TABLE)
|
||||
var collection *core.Collection
|
||||
getCollection := func() (*core.Collection, error) {
|
||||
if collection != nil {
|
||||
return collection, nil
|
||||
}
|
||||
col, err := tx.FindCollectionByNameOrId(tableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
collection = col
|
||||
return collection, nil
|
||||
}
|
||||
|
||||
for _, relation := range payload.Relations {
|
||||
relationID := strings.TrimSpace(relation.ID)
|
||||
if relationID == "" {
|
||||
continue
|
||||
}
|
||||
record, err := tx.FindRecordById(tableName, relationID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proxy := dbmodels.NewRContentsAgents(record)
|
||||
if proxy.Content() != content.Id {
|
||||
return fmt.Errorf("Relation %s gehört zu einem anderen Beitrag.", relationID)
|
||||
}
|
||||
proxy.SetContent(content.Id)
|
||||
proxy.SetAgent(strings.TrimSpace(relation.TargetID))
|
||||
proxy.SetType(strings.TrimSpace(relation.Type))
|
||||
proxy.SetUncertain(relation.Uncertain)
|
||||
if err := tx.Save(proxy); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, relationID := range payload.DeletedIDs {
|
||||
relationID = strings.TrimSpace(relationID)
|
||||
if relationID == "" {
|
||||
continue
|
||||
}
|
||||
record, err := tx.FindRecordById(tableName, relationID)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
proxy := dbmodels.NewRContentsAgents(record)
|
||||
if proxy.Content() != content.Id {
|
||||
continue
|
||||
}
|
||||
if err := tx.Delete(record); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, relation := range payload.NewRelations {
|
||||
targetID := strings.TrimSpace(relation.TargetID)
|
||||
if targetID == "" {
|
||||
continue
|
||||
}
|
||||
col, err := getCollection()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proxy := dbmodels.NewRContentsAgents(core.NewRecord(col))
|
||||
proxy.SetContent(content.Id)
|
||||
proxy.SetAgent(targetID)
|
||||
proxy.SetType(strings.TrimSpace(relation.Type))
|
||||
proxy.SetUncertain(relation.Uncertain)
|
||||
if err := tx.Save(proxy); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyContentFormDraft(content *dbmodels.Content, entry *dbmodels.Entry, fields map[string][]string, numbering float64) {
|
||||
if value, ok := optionalFieldValue(fields, "variant_title"); ok {
|
||||
content.SetVariantTitle(value)
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -49,6 +49,12 @@
|
||||
<i class="ri-loop-left-line"></i> Reset
|
||||
</a>
|
||||
</div>
|
||||
·
|
||||
<div>
|
||||
<a href="/almanach/{{- $model.result.Entry.MusenalmID -}}/edit" class="text-gray-700 no-underline hover:text-slate-950 block">
|
||||
<i class="ri-edit-2-line"></i> Almanach
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
@@ -137,6 +143,9 @@
|
||||
"content_types" $model.content_types
|
||||
"musenalm_types" $model.musenalm_types
|
||||
"pagination_values" $model.pagination_values
|
||||
"agents" $model.result.Agents
|
||||
"content_agents" (index $model.result.ContentsAgents $content.Id)
|
||||
"agent_relations" $model.agent_relations
|
||||
"open_edit" false
|
||||
"is_new" false
|
||||
) -}}
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
"content_types" $contentTypes
|
||||
"musenalm_types" $musenalmTypes
|
||||
"pagination_values" $paginationValues
|
||||
"agents" (index . "agents")
|
||||
"content_agents" (index . "content_agents")
|
||||
"agent_relations" (index . "agent_relations")
|
||||
"open_edit" true
|
||||
"is_new" true
|
||||
) -}}
|
||||
|
||||
@@ -17,6 +17,9 @@
|
||||
"content_types" $contentTypes
|
||||
"musenalm_types" $musenalmTypes
|
||||
"pagination_values" $paginationValues
|
||||
"agents" (index . "agents")
|
||||
"content_agents" (index . "content_agents")
|
||||
"agent_relations" (index . "agent_relations")
|
||||
"open_edit" $openEdit
|
||||
"is_new" $isNew
|
||||
"error" $error
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
{{- $entry := index . "entry" -}}
|
||||
{{- $musenalmTypes := index . "musenalm_types" -}}
|
||||
{{- $paginationValues := index . "pagination_values" -}}
|
||||
{{- $agents := index . "agents" -}}
|
||||
{{- $contentAgents := index . "content_agents" -}}
|
||||
{{- $contentAgentsRender := index . "content_agents_render" -}}
|
||||
{{- $contentAgentsNew := index . "content_agents_new" -}}
|
||||
{{- $agentRelations := index . "agent_relations" -}}
|
||||
{{- $overrideID := index . "content_id" -}}
|
||||
{{- $contentID := $content.Id -}}
|
||||
{{- if and $overrideID (ne $overrideID "") -}}
|
||||
@@ -11,11 +16,14 @@
|
||||
{{- $baseID := printf "content-%s" $contentID -}}
|
||||
{{- $annotationID := printf "%sannotation" $prefix -}}
|
||||
{{- $annotationToolbar := printf "%sannotation-toolbar" $prefix -}}
|
||||
{{- $agentsPrefix := printf "content_%s_agents" $contentID -}}
|
||||
{{- $agentsAddToggleID := printf "content-%s-agents-add-toggle" $contentID -}}
|
||||
{{- $agentsSectionID := printf "content-%s-agents-section" $contentID -}}
|
||||
|
||||
<div class="border border-slate-200 bg-white rounded-xs" data-role="content-card" data-content-id="{{ $contentID }}" data-content-order="{{ $content.Numbering }}">
|
||||
<input type="hidden" name="{{ $prefix }}numbering" class="content-numbering" value="{{- $content.Numbering -}}" />
|
||||
<input type="hidden" name="{{ $prefix }}entries" value="{{ $entry.Id }}" />
|
||||
<div class="border border-slate-200 bg-stone-100 rounded-xs">
|
||||
<div class="border border-slate-200 border-b-0 bg-stone-100 rounded-xs rounded-b-none">
|
||||
<div class="flex flex-wrap items-center justify-between gap-4 border-b border-slate-200 bg-stone-200 px-3 py-2">
|
||||
<div class="flex items-center gap-3">
|
||||
<button type="button" class="text-slate-600 cursor-grab text-sm" data-role="content-drag-handle" draggable="true" aria-label="Beitrag verschieben">
|
||||
@@ -39,7 +47,7 @@
|
||||
</multi-select-simple>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<select name="{{ $prefix }}edit_state" id="{{ $baseID }}-edit-state" class="inputselect font-bold status-select px-2 py-1" data-status="{{ $content.EditState }}">
|
||||
<select name="{{ $prefix }}edit_state" id="{{ $baseID }}-edit-state" class="inputselect font-bold status-select px-2 py-1 shadow-sm rounded-sm" data-status="{{ $content.EditState }}">
|
||||
<option value="Unknown" {{ if eq $content.EditState "Unknown" }}selected{{ end }}>Unbekannt</option>
|
||||
<option value="ToDo" {{ if eq $content.EditState "ToDo" }}selected{{ end }}>Zu erledigen</option>
|
||||
<option value="Review" {{ if eq $content.EditState "Review" }}selected{{ end }}>Überprüfen</option>
|
||||
@@ -59,7 +67,7 @@
|
||||
</div>
|
||||
|
||||
<div id="{{ $baseID }}-edit-fields" class="mt-3 flex flex-col gap-3"></div>
|
||||
<div-manager dm-target="{{ $baseID }}-edit-fields" class="flex items-center justify-end mt-3">
|
||||
<div-manager dm-target="{{ $baseID }}-edit-fields" class="flex items-center justify-end mt-1">
|
||||
<button class="dm-menu-button text-right cursor-pointer whitespace-nowrap"><i class="ri-add-line"></i>
|
||||
Felder hinzufügen</button>
|
||||
|
||||
@@ -205,4 +213,240 @@
|
||||
</div-manager>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-0">
|
||||
<relations-editor data-prefix="{{ $agentsPrefix }}" data-link-base="/person/" data-new-label="(Neu)" data-add-toggle-id="{{ $agentsAddToggleID }}">
|
||||
<div class="inputwrapper !border-none">
|
||||
<div class="grid grid-cols-[8rem_1fr] gap-x-3 gap-y-2 items-start px-3 py-2">
|
||||
<div class="flex flex-col gap-1 text-sm text-gray-700 font-bold">
|
||||
<div class="flex items-center gap-1">
|
||||
<span>Personen & Körperschaften</span>
|
||||
<tool-tip position="top" class="!inline">
|
||||
<div class="data-tip">{{ helpOr "contents" "agents" "Beteiligte Personen oder Körperschaften." }}</div>
|
||||
<i class="ri-question-line"></i>
|
||||
</tool-tip>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div id="{{ $agentsSectionID }}" class="rel-section-container px-0 mt-0">
|
||||
{{- if and $contentAgentsRender (gt (len $contentAgentsRender) 0) -}}
|
||||
{{- range $i, $r := $contentAgentsRender -}}
|
||||
{{- $a := index $agents $r.Agent -}}
|
||||
<div data-rel-row class="contents-agent-row rel-row">
|
||||
<div class="rel-grid">
|
||||
<div data-rel-strike class="relation-strike rel-name-col">
|
||||
{{- if $a -}}
|
||||
<a data-rel-link href="/person/{{ $a.Id }}" class="rel-link" target="_blank" rel="noreferrer">
|
||||
<span data-rel-name>{{- $a.Name -}}</span>
|
||||
</a>
|
||||
{{- if $a.BiographicalData -}}
|
||||
<div data-rel-detail-container class="rel-detail"><span data-rel-detail>{{- $a.BiographicalData -}}</span></div>
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
<div class="text-base text-gray-800">Unbekannte Person</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike">
|
||||
<select name="{{ $agentsPrefix }}_type[{{ $r.Id }}]" id="{{ $agentsPrefix }}_type_{{ $r.Id }}" autocomplete="off" class="inputselect font-bold w-full">
|
||||
{{- range $t := $agentRelations -}}
|
||||
<option value="{{- $t -}}" {{ if eq $r.Type $t }}selected{{ end }}>{{- $t -}}</option>
|
||||
{{- end -}}
|
||||
</select>
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike rel-uncertain-container">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="{{ $agentsPrefix }}_uncertain[{{ $r.Id }}]"
|
||||
id="{{ $agentsPrefix }}_uncertain_{{ $r.Id }}"
|
||||
{{ if $r.Uncertain }}checked{{ end }} />
|
||||
<label for="{{ $agentsPrefix }}_uncertain_{{ $r.Id }}" class="rel-uncertain-label">Unsicher</label>
|
||||
</div>
|
||||
<div class="rel-button-container">
|
||||
<button
|
||||
type="button"
|
||||
class="text-sm"
|
||||
data-delete-toggle="{{ $agentsPrefix }}_delete_{{ $r.Id }}">
|
||||
<i class="ri-delete-bin-line mr-1"></i>
|
||||
<span class="no-underline" data-delete-label data-delete-default="Entfernen" data-delete-active="Wird entfernt" data-delete-hover="Rückgängig">Entfernen</span>
|
||||
</button>
|
||||
<input type="checkbox" class="hidden" name="{{ $agentsPrefix }}_delete[{{ $r.Id }}]" id="{{ $agentsPrefix }}_delete_{{ $r.Id }}" />
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="{{ $agentsPrefix }}_id[{{ $r.Id }}]" value="{{ $r.Id }}" />
|
||||
<input type="hidden" name="{{ $agentsPrefix }}_agent[{{ $r.Id }}]" value="{{ $r.Agent }}" />
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- else if $contentAgents -}}
|
||||
{{- range $i, $r := $contentAgents -}}
|
||||
{{- $a := index $agents $r.Agent -}}
|
||||
<div data-rel-row class="contents-agent-row rel-row">
|
||||
<div class="rel-grid">
|
||||
<div data-rel-strike class="relation-strike rel-name-col">
|
||||
{{- if $a -}}
|
||||
<a data-rel-link href="/person/{{ $a.Id }}" class="rel-link" target="_blank" rel="noreferrer">
|
||||
<span data-rel-name>{{- $a.Name -}}</span>
|
||||
</a>
|
||||
{{- if $a.BiographicalData -}}
|
||||
<div data-rel-detail-container class="rel-detail"><span data-rel-detail>{{- $a.BiographicalData -}}</span></div>
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
<div class="text-base text-gray-800">Unbekannte Person</div>
|
||||
{{- end -}}
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike">
|
||||
<select name="{{ $agentsPrefix }}_type[{{ $r.Id }}]" id="{{ $agentsPrefix }}_type_{{ $r.Id }}" autocomplete="off" class="inputselect font-bold w-full">
|
||||
{{- range $t := $agentRelations -}}
|
||||
<option value="{{- $t -}}" {{ if eq $r.Type $t }}selected{{ end }}>{{- $t -}}</option>
|
||||
{{- end -}}
|
||||
</select>
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike rel-uncertain-container">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="{{ $agentsPrefix }}_uncertain[{{ $r.Id }}]"
|
||||
id="{{ $agentsPrefix }}_uncertain_{{ $r.Id }}"
|
||||
{{ if $r.Uncertain }}checked{{ end }} />
|
||||
<label for="{{ $agentsPrefix }}_uncertain_{{ $r.Id }}" class="rel-uncertain-label">Unsicher</label>
|
||||
</div>
|
||||
<div class="rel-button-container">
|
||||
<button
|
||||
type="button"
|
||||
class="text-sm"
|
||||
data-delete-toggle="{{ $agentsPrefix }}_delete_{{ $r.Id }}">
|
||||
<i class="ri-delete-bin-line mr-1"></i>
|
||||
<span class="no-underline" data-delete-label data-delete-default="Entfernen" data-delete-active="Wird entfernt" data-delete-hover="Rückgängig">Entfernen</span>
|
||||
</button>
|
||||
<input type="checkbox" class="hidden" name="{{ $agentsPrefix }}_delete[{{ $r.Id }}]" id="{{ $agentsPrefix }}_delete_{{ $r.Id }}" />
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" name="{{ $agentsPrefix }}_id[{{ $r.Id }}]" value="{{ $r.Id }}" />
|
||||
<input type="hidden" name="{{ $agentsPrefix }}_agent[{{ $r.Id }}]" value="{{ $r.Agent }}" />
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
<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 -}}
|
||||
{{- $a := index $agents $r.Agent -}}
|
||||
<div data-rel-row class="rel-row">
|
||||
<div class="rel-grid">
|
||||
<div data-rel-strike class="relation-strike rel-name-col">
|
||||
<div class="text-base text-gray-800 truncate">
|
||||
<a data-rel-link class="no-underline hover:text-slate-900" href="/person/{{ $r.Agent }}" target="_blank" rel="noreferrer">
|
||||
<span data-rel-name>{{- if $a -}}{{ $a.Name }}{{- end -}}</span>
|
||||
</a>
|
||||
<em data-rel-new class="rel-new-badge">(Neu)</em>
|
||||
</div>
|
||||
{{- if $a -}}
|
||||
{{- if $a.BiographicalData -}}
|
||||
<div data-rel-detail-container class="rel-detail"><span data-rel-detail>{{- $a.BiographicalData -}}</span></div>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike">
|
||||
<select name="{{ $agentsPrefix }}_new_type" class="inputselect font-bold w-full">
|
||||
{{- range $t := $agentRelations -}}
|
||||
<option value="{{- $t -}}" {{ if eq $r.Type $t }}selected{{ end }}>{{- $t -}}</option>
|
||||
{{- end -}}
|
||||
</select>
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike rel-uncertain-container">
|
||||
<input data-rel-input="uncertain" type="checkbox" name="{{ $agentsPrefix }}_new_uncertain" value="{{ $r.Agent }}" {{ if $r.Uncertain }}checked{{ end }} />
|
||||
<label data-rel-uncertain-label class="rel-uncertain-label">Unsicher</label>
|
||||
</div>
|
||||
<div class="rel-button-container">
|
||||
<button type="button" class="text-sm text-red-700 hover:text-red-900" data-role="relation-new-delete">
|
||||
<i class="ri-delete-bin-line mr-1"></i> Entfernen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" data-rel-input="id" name="{{ $agentsPrefix }}_new_id" value="{{ $r.Agent }}" />
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</div>
|
||||
<div data-role="relation-add-panel" class="mt-2 px-0 hidden">
|
||||
<div class="rel-row">
|
||||
<div class="rel-grid">
|
||||
<div class="min-w-0">
|
||||
<label for="{{ $agentsAddToggleID }}-select" class="sr-only">Akteur suchen</label>
|
||||
<single-select-remote
|
||||
id="{{ $agentsAddToggleID }}-select"
|
||||
data-role="relation-add-select"
|
||||
name="{{ $agentsPrefix }}_new_id"
|
||||
placeholder="Akteur suchen..."
|
||||
data-endpoint="/api/agents/search"
|
||||
data-result-key="agents"
|
||||
data-minchars="1"
|
||||
data-limit="15">
|
||||
</single-select-remote>
|
||||
</div>
|
||||
<div>
|
||||
<label for="{{ $agentsPrefix }}_new_type" class="sr-only">Beziehung</label>
|
||||
<select data-role="relation-type-select" name="{{ $agentsPrefix }}_new_type" id="{{ $agentsPrefix }}_new_type" autocomplete="off" class="inputselect font-bold w-full">
|
||||
{{- range $t := $agentRelations -}}
|
||||
<option value="{{- $t -}}">{{- $t -}}</option>
|
||||
{{- end -}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="rel-uncertain-container">
|
||||
<input data-role="relation-uncertain" type="checkbox" name="{{ $agentsPrefix }}_new_uncertain" id="{{ $agentsPrefix }}_new_uncertain" />
|
||||
<label for="{{ $agentsPrefix }}_new_uncertain" class="rel-uncertain-label">Unsicher</label>
|
||||
</div>
|
||||
<div class="rel-button-container">
|
||||
<div class="flex items-center gap-3 text-lg">
|
||||
<button type="button" data-role="relation-add-apply" class="text-gray-700 hover:text-gray-900" aria-label="Person hinzufügen">
|
||||
<i class="ri-check-line"></i>
|
||||
</button>
|
||||
<button type="button" data-role="relation-add-close" class="text-gray-700 hover:text-gray-900" aria-label="Ausblenden">
|
||||
<i class="ri-close-line"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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">
|
||||
<div data-rel-strike class="relation-strike rel-name-col">
|
||||
<div class="text-base text-gray-800 truncate">
|
||||
<a data-rel-link class="no-underline hover:text-slate-900">
|
||||
<span data-rel-name></span>
|
||||
</a>
|
||||
<em data-rel-new class="rel-new-badge"></em>
|
||||
</div>
|
||||
<div data-rel-detail-container class="rel-detail"><span data-rel-detail></span></div>
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike">
|
||||
<select data-rel-input="type" class="inputselect font-bold w-full"></select>
|
||||
</div>
|
||||
<div data-rel-strike class="relation-strike rel-uncertain-container">
|
||||
<input data-rel-input="uncertain" type="checkbox" />
|
||||
<label data-rel-uncertain-label class="rel-uncertain-label">Unsicher</label>
|
||||
</div>
|
||||
<div class="rel-button-container">
|
||||
<button type="button" class="text-sm text-red-700 hover:text-red-900" data-role="relation-new-delete">
|
||||
<i class="ri-delete-bin-line mr-1"></i> Entfernen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<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
|
||||
</a>
|
||||
<button type="button" id="{{ $agentsAddToggleID }}" class="text-gray-700 hover:text-slate-950 no-underline text-left">
|
||||
<i class="ri-link"></i> Person verlinken
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</relations-editor>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
{{- $contentTypes := index . "content_types" -}}
|
||||
{{- $musenalmTypes := index . "musenalm_types" -}}
|
||||
{{- $paginationValues := index . "pagination_values" -}}
|
||||
{{- $agents := index . "agents" -}}
|
||||
{{- $contentAgents := index . "content_agents" -}}
|
||||
{{- $agentRelations := index . "agent_relations" -}}
|
||||
{{- $overrideID := index . "content_id" -}}
|
||||
{{- $openEdit := index . "open_edit" -}}
|
||||
{{- $isNew := index . "is_new" -}}
|
||||
@@ -49,7 +52,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="status-badge text-xs" data-status="{{ $content.EditState }}">
|
||||
<span class="status-badge text-xs shadow-sm" data-status="{{ $content.EditState }}">
|
||||
<i class="status-icon {{- if eq $content.EditState "Edited" }} ri-checkbox-circle-line{{- else if eq $content.EditState "Seen" }} ri-information-line{{- else if eq $content.EditState "Review" }} ri-search-line{{- else if eq $content.EditState "ToDo" }} ri-list-check{{- else }} ri-forbid-2-line{{- end }}"></i>
|
||||
{{- if eq $content.EditState "Edited" -}}Erfasst{{- else if eq $content.EditState "Review" -}}Überprüfen{{- else if eq $content.EditState "ToDo" -}}Zu erledigen{{- else if eq $content.EditState "Seen" -}}Autopsiert{{- else -}}Unbekannt{{- end -}}
|
||||
</span>
|
||||
@@ -76,6 +79,26 @@
|
||||
<div class="text-sm font-bold text-gray-700">Autorangabe</div>
|
||||
<div class="text-base italic">{{- $content.ResponsibilityStmt -}}</div>
|
||||
{{- end -}}
|
||||
{{- if $contentAgents -}}
|
||||
<div class="text-sm font-bold text-gray-700">Personen</div>
|
||||
<div class="text-base">
|
||||
<div class="flex flex-col">
|
||||
{{- range $_, $rel := $contentAgents -}}
|
||||
{{- $agent := index $agents $rel.Agent -}}
|
||||
{{- if $agent -}}
|
||||
<div class="font-sans w-max">
|
||||
<a href="/person/{{- $agent.Id -}}" class="no-underline hover:text-slate-900">
|
||||
{{- $agent.Name -}}
|
||||
</a>
|
||||
{{- if $agent.BiographicalData -}}
|
||||
<span>({{ $agent.BiographicalData }})</span>
|
||||
{{- end -}}
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
</div>
|
||||
</div>
|
||||
{{- end -}}
|
||||
{{- if $content.Annotation -}}
|
||||
{{- $link := printf "%s%s" "/almanach/" $entry.MusenalmIDString -}}
|
||||
<div class="text-sm font-bold text-gray-700">Anmerkung</div>
|
||||
@@ -109,6 +132,9 @@
|
||||
"content_types" $contentTypes
|
||||
"musenalm_types" $musenalmTypes
|
||||
"pagination_values" $paginationValues
|
||||
"agents" $agents
|
||||
"content_agents" $contentAgents
|
||||
"agent_relations" $agentRelations
|
||||
) -}}
|
||||
<div class="w-full flex items-center justify-end gap-3 mt-4 flex-wrap">
|
||||
<button type="button" class="resetbutton w-40 flex items-center gap-2 justify-center" data-role="content-edit-cancel">
|
||||
|
||||
@@ -28,6 +28,7 @@ export class RelationsEditor extends HTMLElement {
|
||||
this._emptyText = this.querySelector(".rel-empty-text");
|
||||
this._setupAddPanel();
|
||||
this._setupDeleteToggles();
|
||||
this._setupNewRowDeletes();
|
||||
this._setupPreferredOptionHandling();
|
||||
}
|
||||
|
||||
@@ -248,6 +249,7 @@ export class RelationsEditor extends HTMLElement {
|
||||
if (uncertain && this._uncertain) {
|
||||
uncertain.checked = this._uncertain.checked;
|
||||
uncertain.name = `${this._prefix}_new_uncertain`;
|
||||
uncertain.value = this._pendingItem.id;
|
||||
const uncertainId = `${this._prefix}_new_uncertain_row`;
|
||||
uncertain.id = uncertainId;
|
||||
const uncertainLabel = fragment.querySelector("[data-rel-uncertain-label]");
|
||||
@@ -389,6 +391,31 @@ export class RelationsEditor extends HTMLElement {
|
||||
});
|
||||
}
|
||||
|
||||
_setupNewRowDeletes() {
|
||||
if (!this._addRow) {
|
||||
return;
|
||||
}
|
||||
this._addRow.querySelectorAll(ROLE_NEW_DELETE).forEach((button) => {
|
||||
if (button.dataset.relationNewBound === "true") {
|
||||
return;
|
||||
}
|
||||
button.dataset.relationNewBound = "true";
|
||||
button.addEventListener("click", () => {
|
||||
const row = button.closest(ROLE_REL_ROW);
|
||||
if (row) {
|
||||
row.remove();
|
||||
}
|
||||
this._pendingItem = null;
|
||||
this._clearAddPanel();
|
||||
if (this._addPanel) {
|
||||
this._addPanel.classList.add("hidden");
|
||||
}
|
||||
this._updateEmptyTextVisibility();
|
||||
this._updatePreferredOptions();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_setupPreferredOptionHandling() {
|
||||
if (this._prefix !== "entries_series" || !this._preferredLabel) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user