mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 10:35:30 +00:00
start inhaltsliste
This commit is contained in:
264
controllers/almanach_contents_edit.go
Normal file
264
controllers/almanach_contents_edit.go
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"maps"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
URL_ALMANACH_CONTENTS_EDIT = "contents/edit"
|
||||||
|
TEMPLATE_ALMANACH_CONTENTS_EDIT = "/almanach/contents/edit/"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ep := &AlmanachContentsEditPage{
|
||||||
|
StaticPage: pagemodels.StaticPage{
|
||||||
|
Name: pagemodels.P_ALMANACH_CONTENTS_EDIT_NAME,
|
||||||
|
URL: URL_ALMANACH_CONTENTS_EDIT,
|
||||||
|
Template: TEMPLATE_ALMANACH_CONTENTS_EDIT,
|
||||||
|
Layout: pagemodels.LAYOUT_LOGIN_PAGES,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
app.Register(ep)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AlmanachContentsEditPage struct {
|
||||||
|
pagemodels.StaticPage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *AlmanachContentsEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
|
rg := router.Group(URL_ALMANACH)
|
||||||
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
|
rg.GET(URL_ALMANACH_CONTENTS_EDIT, p.GET(engine, app))
|
||||||
|
rg.POST(URL_ALMANACH_CONTENTS_EDIT, p.POSTSave(engine, app))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *AlmanachContentsEditPage) GET(engine *templating.Engine, app core.App) HandleFunc {
|
||||||
|
return func(e *core.RequestEvent) error {
|
||||||
|
id := e.Request.PathValue("id")
|
||||||
|
req := templating.NewRequest(e)
|
||||||
|
data := make(map[string]any)
|
||||||
|
result, err := NewAlmanachEditResult(app, id, BeitraegeFilterParameters{})
|
||||||
|
if err != nil {
|
||||||
|
engine.Response404(e, err, nil)
|
||||||
|
}
|
||||||
|
data["result"] = result
|
||||||
|
data["csrf_token"] = req.Session().Token
|
||||||
|
data["content_types"] = dbmodels.CONTENT_TYPE_VALUES
|
||||||
|
data["musenalm_types"] = dbmodels.MUSENALM_TYPE_VALUES
|
||||||
|
data["pagination_values"] = slices.Collect(maps.Values(dbmodels.MUSENALM_PAGINATION_VALUES))
|
||||||
|
|
||||||
|
if msg := e.Request.URL.Query().Get("saved_message"); msg != "" {
|
||||||
|
data["success"] = msg
|
||||||
|
}
|
||||||
|
|
||||||
|
return engine.Response200(e, p.Template, data, p.Layout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *AlmanachContentsEditPage) renderError(engine *templating.Engine, app core.App, e *core.RequestEvent, message string) error {
|
||||||
|
id := e.Request.PathValue("id")
|
||||||
|
req := templating.NewRequest(e)
|
||||||
|
data := make(map[string]any)
|
||||||
|
result, err := NewAlmanachEditResult(app, id, BeitraegeFilterParameters{})
|
||||||
|
if err != nil {
|
||||||
|
return engine.Response404(e, err, nil)
|
||||||
|
}
|
||||||
|
data["result"] = result
|
||||||
|
data["csrf_token"] = req.Session().Token
|
||||||
|
data["content_types"] = dbmodels.CONTENT_TYPE_VALUES
|
||||||
|
data["musenalm_types"] = dbmodels.MUSENALM_TYPE_VALUES
|
||||||
|
data["pagination_values"] = slices.Collect(maps.Values(dbmodels.MUSENALM_PAGINATION_VALUES))
|
||||||
|
data["error"] = message
|
||||||
|
return engine.Response200(e, p.Template, data, p.Layout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *AlmanachContentsEditPage) POSTSave(engine *templating.Engine, app core.App) HandleFunc {
|
||||||
|
return func(e *core.RequestEvent) error {
|
||||||
|
id := e.Request.PathValue("id")
|
||||||
|
req := templating.NewRequest(e)
|
||||||
|
|
||||||
|
if err := e.Request.ParseForm(); err != nil {
|
||||||
|
return p.renderError(engine, app, e, "Formulardaten ungültig.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := req.CheckCSRF(e.Request.FormValue("csrf_token")); err != nil {
|
||||||
|
return p.renderError(engine, app, e, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
entry, err := dbmodels.Entries_MusenalmID(app, id)
|
||||||
|
if err != nil {
|
||||||
|
return engine.Response404(e, err, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
contents, err := dbmodels.Contents_Entry(app, entry.Id)
|
||||||
|
if err != nil {
|
||||||
|
return p.renderError(engine, app, e, "Beiträge konnten nicht geladen werden.")
|
||||||
|
}
|
||||||
|
|
||||||
|
contentInputs := parseContentsForm(e.Request.PostForm)
|
||||||
|
user := req.User()
|
||||||
|
|
||||||
|
if err := app.RunInTransaction(func(tx core.App) error {
|
||||||
|
for _, content := range contents {
|
||||||
|
fields, ok := contentInputs[content.Id]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := applyContentForm(content, entry, fields, user); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Save(content); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
app.Logger().Error("Failed to save contents", "entry_id", entry.Id, "error", err)
|
||||||
|
return p.renderError(engine, app, e, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
go updateContentsFTS5(app, entry, contents)
|
||||||
|
|
||||||
|
redirect := fmt.Sprintf("/almanach/%s/contents/edit?saved_message=%s", id, url.QueryEscape("Änderungen gespeichert."))
|
||||||
|
return e.Redirect(http.StatusSeeOther, redirect)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseContentsForm(form url.Values) map[string]map[string][]string {
|
||||||
|
contentInputs := map[string]map[string][]string{}
|
||||||
|
for key, values := range form {
|
||||||
|
if key == "csrf_token" || key == "last_edited" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
trimmed := strings.TrimSuffix(key, "[]")
|
||||||
|
if !strings.HasPrefix(trimmed, "content_") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
rest := strings.TrimPrefix(trimmed, "content_")
|
||||||
|
sep := strings.Index(rest, "_")
|
||||||
|
if sep < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
contentID := rest[:sep]
|
||||||
|
field := rest[sep+1:]
|
||||||
|
if field == "" || contentID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, ok := contentInputs[contentID]; !ok {
|
||||||
|
contentInputs[contentID] = map[string][]string{}
|
||||||
|
}
|
||||||
|
contentInputs[contentID][field] = values
|
||||||
|
}
|
||||||
|
return contentInputs
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyContentForm(content *dbmodels.Content, entry *dbmodels.Entry, fields map[string][]string, user *dbmodels.FixedUser) error {
|
||||||
|
preferredTitle := strings.TrimSpace(firstValue(fields["preferred_title"]))
|
||||||
|
if preferredTitle == "" {
|
||||||
|
label := content.Id
|
||||||
|
if content.Numbering() > 0 {
|
||||||
|
label = strconv.FormatFloat(content.Numbering(), 'f', -1, 64)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Kurztitel ist erforderlich (Beitrag %s).", label)
|
||||||
|
}
|
||||||
|
|
||||||
|
yearValue := strings.TrimSpace(firstValue(fields["year"]))
|
||||||
|
year := 0
|
||||||
|
if yearValue != "" {
|
||||||
|
parsed, err := strconv.Atoi(yearValue)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Ungültiges Jahr (Beitrag %s).", content.Id)
|
||||||
|
}
|
||||||
|
year = parsed
|
||||||
|
}
|
||||||
|
|
||||||
|
numberingValue := strings.TrimSpace(firstValue(fields["numbering"]))
|
||||||
|
numbering := 0.0
|
||||||
|
if numberingValue != "" {
|
||||||
|
parsed, err := strconv.ParseFloat(numberingValue, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Ungültige Nummerierung (Beitrag %s).", content.Id)
|
||||||
|
}
|
||||||
|
numbering = parsed
|
||||||
|
}
|
||||||
|
|
||||||
|
status := strings.TrimSpace(firstValue(fields["edit_state"]))
|
||||||
|
if status == "" {
|
||||||
|
status = content.EditState()
|
||||||
|
}
|
||||||
|
if !slices.Contains(dbmodels.EDITORSTATE_VALUES, status) {
|
||||||
|
return fmt.Errorf("Ungültiger Status (Beitrag %s).", content.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
content.SetPreferredTitle(preferredTitle)
|
||||||
|
content.SetVariantTitle(strings.TrimSpace(firstValue(fields["variant_title"])))
|
||||||
|
content.SetParallelTitle(strings.TrimSpace(firstValue(fields["parallel_title"])))
|
||||||
|
content.SetTitleStmt(strings.TrimSpace(firstValue(fields["title_statement"])))
|
||||||
|
content.SetSubtitleStmt(strings.TrimSpace(firstValue(fields["subtitle_statement"])))
|
||||||
|
content.SetIncipitStmt(strings.TrimSpace(firstValue(fields["incipit_statement"])))
|
||||||
|
content.SetResponsibilityStmt(strings.TrimSpace(firstValue(fields["responsibility_statement"])))
|
||||||
|
content.SetPlaceStmt(strings.TrimSpace(firstValue(fields["place_statement"])))
|
||||||
|
content.SetPublicationStmt(strings.TrimSpace(firstValue(fields["publication_statement"])))
|
||||||
|
content.SetYear(year)
|
||||||
|
content.SetExtent(strings.TrimSpace(firstValue(fields["extent"])))
|
||||||
|
content.SetDimensions(strings.TrimSpace(firstValue(fields["dimensions"])))
|
||||||
|
content.SetLanguage(fields["language"])
|
||||||
|
content.SetContentType(fields["content_type"])
|
||||||
|
content.SetMusenalmType(fields["musenalm_type"])
|
||||||
|
content.SetMusenalmPagination(strings.TrimSpace(firstValue(fields["musenalm_pagination"])))
|
||||||
|
content.SetNumbering(numbering)
|
||||||
|
content.SetEntry(entry.Id)
|
||||||
|
content.SetMusenalmID(entry.MusenalmID())
|
||||||
|
content.SetEditState(status)
|
||||||
|
content.SetComment(strings.TrimSpace(firstValue(fields["edit_comment"])))
|
||||||
|
content.SetAnnotation(strings.TrimSpace(firstValue(fields["annotation"])))
|
||||||
|
if user != nil {
|
||||||
|
content.SetEditor(user.Id)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func firstValue(values []string) string {
|
||||||
|
if len(values) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return values[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateContentsFTS5(app core.App, entry *dbmodels.Entry, contents []*dbmodels.Content) {
|
||||||
|
if len(contents) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
agents, relations, err := dbmodels.AgentsForContents(app, contents)
|
||||||
|
if err != nil {
|
||||||
|
app.Logger().Error("Failed to load content agents for FTS5 update", "entry_id", entry.Id, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, content := range contents {
|
||||||
|
contentAgents := []*dbmodels.Agent{}
|
||||||
|
for _, rel := range relations[content.Id] {
|
||||||
|
if agent := agents[rel.Agent()]; agent != nil {
|
||||||
|
contentAgents = append(contentAgents, agent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := dbmodels.UpdateFTS5Content(app, content, entry, contentAgents); err != nil {
|
||||||
|
app.Logger().Error("Failed to update FTS5 content", "content_id", content.Id, "error", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ const (
|
|||||||
P_SEITEN_EDIT_NAME = "seiten_edit"
|
P_SEITEN_EDIT_NAME = "seiten_edit"
|
||||||
|
|
||||||
P_ALMANACH_EDIT_NAME = "almanach_edit"
|
P_ALMANACH_EDIT_NAME = "almanach_edit"
|
||||||
|
P_ALMANACH_CONTENTS_EDIT_NAME = "almanach_contents_edit"
|
||||||
P_ALMANACH_NEW_NAME = "almanach_new"
|
P_ALMANACH_NEW_NAME = "almanach_new"
|
||||||
P_REIHE_EDIT_NAME = "reihe_edit"
|
P_REIHE_EDIT_NAME = "reihe_edit"
|
||||||
P_REIHE_NEW_NAME = "reihe_new"
|
P_REIHE_NEW_NAME = "reihe_new"
|
||||||
|
|||||||
@@ -55,6 +55,10 @@
|
|||||||
<i class="ri-edit-line"></i>
|
<i class="ri-edit-line"></i>
|
||||||
<a href="/almanach/{{ $model.result.Entry.MusenalmID }}/edit">Bearbeiten</a>
|
<a href="/almanach/{{ $model.result.Entry.MusenalmID }}/edit">Bearbeiten</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<i class="ri-file-edit-line"></i>
|
||||||
|
<a href="/almanach/{{ $model.result.Entry.MusenalmID }}/contents/edit">Beiträge bearbeiten</a>
|
||||||
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
202
views/routes/almanach/contents/edit/body.gohtml
Normal file
202
views/routes/almanach/contents/edit/body.gohtml
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
{{ $model := . }}
|
||||||
|
|
||||||
|
<edit-page>
|
||||||
|
<div class="flex container-normal bg-slate-100 mx-auto px-8">
|
||||||
|
<div class="flex flex-row w-full justify-between">
|
||||||
|
<div class="flex flex-col justify-end-safe flex-2/5">
|
||||||
|
<div class="mb-1">
|
||||||
|
<i class="ri-file-list-3-line"></i> Inhalte
|
||||||
|
</div>
|
||||||
|
<h1 class="text-2xl w-full font-bold text-slate-900 mb-1">
|
||||||
|
{{- if $model.result -}}
|
||||||
|
{{- $model.result.Entry.PreferredTitle -}}
|
||||||
|
{{- else -}}
|
||||||
|
Inhalte bearbeiten
|
||||||
|
{{- end -}}
|
||||||
|
</h1>
|
||||||
|
{{- if $model.result -}}
|
||||||
|
<div class="flex flex-row gap-x-3">
|
||||||
|
<div>
|
||||||
|
<a
|
||||||
|
href="/almanach/{{ $model.result.Entry.MusenalmID }}"
|
||||||
|
class="text-gray-700 hover:text-slate-950 block no-underline">
|
||||||
|
<i class="ri-eye-line"></i> Anschauen
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
·
|
||||||
|
<div class="flex flex-row">
|
||||||
|
{{- if $model.result.PrevByID -}}
|
||||||
|
<div>
|
||||||
|
<a href="/almanach/{{ $model.result.PrevByID.MusenalmID }}/contents/edit" class="text-gray-700 hover:text-slate-950 no-underline block">
|
||||||
|
<i class="ri-arrow-left-s-line"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{- end -}}
|
||||||
|
<div class="px-1.5 py-0.5 rounded-xs bg-gray-200 w-fit font-bold">
|
||||||
|
{{ $model.result.Entry.MusenalmID }}
|
||||||
|
</div>
|
||||||
|
{{- if $model.result.NextByID -}}
|
||||||
|
<div>
|
||||||
|
<a href="/almanach/{{ $model.result.NextByID.MusenalmID }}/contents/edit" class="text-gray-700 hover:text-slate-950 no-underline block">
|
||||||
|
<i class="ri-arrow-right-s-line"></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
·
|
||||||
|
<div>
|
||||||
|
<a href="/almanach/{{- $model.result.Entry.MusenalmID -}}/contents/edit" class="text-gray-700 no-underline hover:text-slate-950 block">
|
||||||
|
<i class="ri-loop-left-line"></i> Reset
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
{{- if $model.result -}}
|
||||||
|
<div class="flex flex-row" id="contents-header-data">
|
||||||
|
<div class="flex flex-col justify-end gap-y-6 pr-20">
|
||||||
|
<div class="">
|
||||||
|
<div class="font-bold text-sm">
|
||||||
|
<i class="ri-navigation-line"></i> Navigation
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
{{- if $model.result.PrevByTitle -}}
|
||||||
|
<tool-tip position="top" class="!inline">
|
||||||
|
<div class="data-tip">{{ $model.result.PrevByTitle.PreferredTitle }}</div>
|
||||||
|
<a
|
||||||
|
href="/almanach/{{ $model.result.PrevByTitle.MusenalmID }}/contents/edit"
|
||||||
|
class="text-gray-700 hover:text-slate-950 no-underline">
|
||||||
|
<i class="ri-arrow-left-s-line"></i>
|
||||||
|
</a>
|
||||||
|
</tool-tip>
|
||||||
|
{{- end -}}
|
||||||
|
<span class="text-gray-800 font-bold no-underline">
|
||||||
|
A - Z
|
||||||
|
</span>
|
||||||
|
{{- if $model.result.NextByTitle -}}
|
||||||
|
<tool-tip position="top" class="!inline">
|
||||||
|
<div class="data-tip">{{ $model.result.NextByTitle.PreferredTitle }}</div>
|
||||||
|
<a
|
||||||
|
href="/almanach/{{ $model.result.NextByTitle.MusenalmID }}/contents/edit"
|
||||||
|
class="text-gray-700 hover:text-slate-950 no-underline">
|
||||||
|
<i class="ri-arrow-right-s-line"></i>
|
||||||
|
</a>
|
||||||
|
</tool-tip>
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col justify-end gap-y-6 pr-10">
|
||||||
|
<div class="">
|
||||||
|
<div class="font-bold text-sm">
|
||||||
|
<i class="ri-database-2-line"></i> Datenbank-ID
|
||||||
|
</div>
|
||||||
|
<div class="">{{ $model.result.Entry.Id }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col justify-end gap-y-6 pr-4">
|
||||||
|
<div class="">
|
||||||
|
<div class="font-bold text-sm mb-1"><i class="ri-calendar-line"></i> Zuletzt bearbeitet</div>
|
||||||
|
<div>
|
||||||
|
<div class="px-1.5 py-0.5 rounded-xs bg-gray-200 w-fit">
|
||||||
|
<span>{{ GermanDate $model.result.Entry.Updated }}</span>,
|
||||||
|
<span>{{ GermanTime $model.result.Entry.Updated }}</span>h
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
class="px-1.5 py-0.5 rounded-xs mt-1.5 bg-gray-200 w-fit {{ if not $model.result.User }}hidden{{ end }}">
|
||||||
|
<i class="ri-user-line mr-1"></i>
|
||||||
|
<span>{{- if $model.result.User -}}{{ $model.result.User.Name }}{{- end -}}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container-normal mx-auto mt-4 !px-0">
|
||||||
|
{{ template "_usermessage" $model }}
|
||||||
|
<form
|
||||||
|
autocomplete="off"
|
||||||
|
class="w-full dbform"
|
||||||
|
id="changecontentsform"
|
||||||
|
method="POST"
|
||||||
|
action="/almanach/{{ $model.result.Entry.MusenalmID }}/contents/edit">
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ $model.csrf_token }}" />
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-3">
|
||||||
|
{{- range $_, $content := $model.result.Contents -}}
|
||||||
|
{{- template "_content_edit" (Dict
|
||||||
|
"content" $content
|
||||||
|
"entry" $model.result.Entry
|
||||||
|
"content_types" $model.content_types
|
||||||
|
"musenalm_types" $model.musenalm_types
|
||||||
|
"pagination_values" $model.pagination_values
|
||||||
|
) -}}
|
||||||
|
{{- end -}}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full flex items-end justify-between gap-4 mt-6 flex-wrap">
|
||||||
|
<p class="text-sm text-gray-600" aria-live="polite"></p>
|
||||||
|
<div class="flex items-center gap-3 self-end flex-wrap">
|
||||||
|
<a href="/almanach/{{ $model.result.Entry.MusenalmID }}" class="resetbutton w-48 flex items-center gap-2 justify-center">
|
||||||
|
<i class="ri-close-line"></i>
|
||||||
|
<span>Abbrechen</span>
|
||||||
|
</a>
|
||||||
|
<a href="/almanach/{{ $model.result.Entry.MusenalmID }}/contents/edit" class="resetbutton w-48 flex items-center gap-2 justify-center">
|
||||||
|
<i class="ri-loop-left-line"></i>
|
||||||
|
<span>Reset</span>
|
||||||
|
</a>
|
||||||
|
<button type="submit" class="submitbutton w-48 flex items-center gap-2 justify-center">
|
||||||
|
<i class="ri-save-line"></i>
|
||||||
|
<span>Speichern</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</edit-page>
|
||||||
|
|
||||||
|
<script type="module">
|
||||||
|
const applyMultiSelectInit = (el) => {
|
||||||
|
if (!el) return;
|
||||||
|
const optionsRaw = el.getAttribute("data-initial-options") || "[]";
|
||||||
|
const valuesRaw = el.getAttribute("data-initial-values") || "[]";
|
||||||
|
let options = [];
|
||||||
|
let values = [];
|
||||||
|
try {
|
||||||
|
options = JSON.parse(optionsRaw);
|
||||||
|
values = JSON.parse(valuesRaw);
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (options.length && typeof el.setOptions === "function") {
|
||||||
|
el.setOptions(options);
|
||||||
|
}
|
||||||
|
if (values.length) {
|
||||||
|
el.value = values;
|
||||||
|
if (typeof el.captureInitialSelection === "function") {
|
||||||
|
el.captureInitialSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const initPage = () => {
|
||||||
|
document.querySelectorAll(".content-numbering").forEach((input, index) => {
|
||||||
|
input.value = index + 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
document
|
||||||
|
.querySelectorAll("multi-select-simple[data-initial-options], multi-select-simple[data-initial-values]")
|
||||||
|
.forEach((el) => applyMultiSelectInit(el));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (window.customElements?.whenDefined) {
|
||||||
|
window.customElements.whenDefined("multi-select-simple").then(() => {
|
||||||
|
requestAnimationFrame(initPage);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
initPage();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
8
views/routes/almanach/contents/edit/head.gohtml
Normal file
8
views/routes/almanach/contents/edit/head.gohtml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{{ $model := . }}
|
||||||
|
<title>
|
||||||
|
{{ if $model.result }}
|
||||||
|
Inhalte bearbeiten: {{ $model.result.Entry.PreferredTitle }} - Musenalm
|
||||||
|
{{ else }}
|
||||||
|
Inhalte bearbeiten - Musenalm
|
||||||
|
{{ end }}
|
||||||
|
</title>
|
||||||
204
views/routes/components/_content_edit.gohtml
Normal file
204
views/routes/components/_content_edit.gohtml
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
{{- $content := index . "content" -}}
|
||||||
|
{{- $entry := index . "entry" -}}
|
||||||
|
{{- $contentTypes := index . "content_types" -}}
|
||||||
|
{{- $musenalmTypes := index . "musenalm_types" -}}
|
||||||
|
{{- $paginationValues := index . "pagination_values" -}}
|
||||||
|
{{- $prefix := printf "content_%s_" $content.Id -}}
|
||||||
|
{{- $baseID := printf "content-%s" $content.Id -}}
|
||||||
|
|
||||||
|
<div class="border border-slate-200 bg-white rounded-xs p-3" data-content-id="{{ $content.Id }}" data-content-order="{{ $content.Numbering }}">
|
||||||
|
<input type="hidden" name="{{ $prefix }}numbering" class="content-numbering" value="{{- $content.Numbering -}}" />
|
||||||
|
<input type="hidden" name="{{ $prefix }}musenalm_id" value="{{ $entry.MusenalmID }}" />
|
||||||
|
<input type="hidden" name="{{ $prefix }}entries" value="{{ $entry.Id }}" />
|
||||||
|
|
||||||
|
<div class="flex items-center justify-between gap-3">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<i class="ri-drag-move-2-line text-slate-400 cursor-grab"></i>
|
||||||
|
<div class="text-xs text-slate-500">Alm-ID {{ $entry.MusenalmID }}</div>
|
||||||
|
</div>
|
||||||
|
<div class="border border-dashed border-slate-300 bg-slate-50 px-2 py-1 text-xs text-slate-600 rounded-xs">
|
||||||
|
<i class="ri-image-add-line"></i> Scans folgen
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-3 grid gap-2 xl:grid-cols-[1.3fr_1fr_1fr]">
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-preferred-title" class="inputlabel">Kurztitel</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}preferred_title" id="{{ $baseID }}-preferred-title" class="inputinput no-enter" autocomplete="off" rows="1" required>{{- $content.PreferredTitle -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-title" class="inputlabel">Titel</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}title_statement" id="{{ $baseID }}-title" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.TitleStmt -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-incipit" class="inputlabel">Incipit</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}incipit_statement" id="{{ $baseID }}-incipit" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.IncipitStmt -}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-responsibility" class="inputlabel">Autorangabe</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}responsibility_statement" id="{{ $baseID }}-responsibility" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.ResponsibilityStmt -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-extent" class="inputlabel">Seite</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}extent" id="{{ $baseID }}-extent" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.Extent -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-pagination" class="inputlabel">Paginierung</label>
|
||||||
|
</div>
|
||||||
|
<select name="{{ $prefix }}musenalm_pagination" id="{{ $baseID }}-pagination" class="inputselect">
|
||||||
|
{{- range $_, $p := $paginationValues -}}
|
||||||
|
<option value="{{- $p -}}" {{ if eq $content.MusenalmPagination $p }}selected{{ end }}>{{- $p -}}</option>
|
||||||
|
{{- end -}}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-content-type" class="inputlabel">Inhaltstyp</label>
|
||||||
|
</div>
|
||||||
|
<multi-select-simple
|
||||||
|
id="{{ $baseID }}-content-type"
|
||||||
|
name="{{ $prefix }}content_type[]"
|
||||||
|
show-create-button="false"
|
||||||
|
placeholder="Inhaltstypen suchen..."
|
||||||
|
data-empty-text="Keine Typen verknüpft"
|
||||||
|
value='[{{- range $i, $t := $content.ContentType -}}{{- if $i }},{{ end -}}"{{ $t }}"{{- end -}}]'
|
||||||
|
data-initial-options='[{{- range $i, $t := $contentTypes -}}{{- if $i }},{{ end -}}{{ printf "{\"id\":%q,\"name\":%q}" $t $t }}{{- end -}}]'
|
||||||
|
data-initial-values='[{{- range $i, $t := $content.ContentType -}}{{- if $i }},{{ end -}}{{ printf "%q" $t }}{{- end -}}]'>
|
||||||
|
</multi-select-simple>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-musenalm-type" class="inputlabel">Musenalm-Typ</label>
|
||||||
|
</div>
|
||||||
|
<multi-select-simple
|
||||||
|
id="{{ $baseID }}-musenalm-type"
|
||||||
|
name="{{ $prefix }}musenalm_type[]"
|
||||||
|
show-create-button="false"
|
||||||
|
placeholder="Musenalm-Typen suchen..."
|
||||||
|
data-empty-text="Keine Typen verknüpft"
|
||||||
|
value='[{{- range $i, $t := $content.MusenalmType -}}{{- if $i }},{{ end -}}"{{ $t }}"{{- end -}}]'
|
||||||
|
data-initial-options='[{{- range $i, $t := $musenalmTypes -}}{{- if $i }},{{ end -}}{{ printf "{\"id\":%q,\"name\":%q}" $t $t }}{{- end -}}]'
|
||||||
|
data-initial-values='[{{- range $i, $t := $content.MusenalmType -}}{{- if $i }},{{ end -}}{{ printf "%q" $t }}{{- end -}}]'>
|
||||||
|
</multi-select-simple>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-language" class="inputlabel">Sprache</label>
|
||||||
|
</div>
|
||||||
|
<multi-select-simple
|
||||||
|
id="{{ $baseID }}-language"
|
||||||
|
name="{{ $prefix }}language[]"
|
||||||
|
show-create-button="false"
|
||||||
|
placeholder="Sprachen suchen..."
|
||||||
|
data-empty-text="Keine Sprachen verknüpft"
|
||||||
|
value='[{{- range $i, $lang := $content.Language -}}{{- if $i }},{{ end -}}"{{ $lang }}"{{- end -}}]'
|
||||||
|
data-initial-values='[{{- range $i, $lang := $content.Language -}}{{- if $i }},{{ end -}}{{ printf "%q" $lang }}{{- end -}}]'>
|
||||||
|
</multi-select-simple>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<details class="mt-3">
|
||||||
|
<summary class="text-sm font-bold text-slate-700 cursor-pointer select-none">
|
||||||
|
Weitere Felder & Anmerkungen
|
||||||
|
</summary>
|
||||||
|
<div class="mt-3 grid gap-2">
|
||||||
|
<div class="grid gap-2 md:grid-cols-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-subtitle" class="inputlabel">Untertitel</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}subtitle_statement" id="{{ $baseID }}-subtitle" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.SubtitleStmt -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-parallel-title" class="inputlabel">Paralleltitel</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}parallel_title" id="{{ $baseID }}-parallel-title" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.ParallelTitle -}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2 md:grid-cols-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-variant-title" class="inputlabel">Titelvarianten</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}variant_title" id="{{ $baseID }}-variant-title" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.VariantTitle -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-year" class="inputlabel">Jahr</label>
|
||||||
|
</div>
|
||||||
|
<input name="{{ $prefix }}year" id="{{ $baseID }}-year" class="inputinput" autocomplete="off" value="{{ if $content.Year }}{{ $content.Year }}{{ end }}" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2 md:grid-cols-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-publication" class="inputlabel">Publikationsangabe</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}publication_statement" id="{{ $baseID }}-publication" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.PublicationStmt -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-place" class="inputlabel">Ortsangabe</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}place_statement" id="{{ $baseID }}-place" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.PlaceStmt -}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid gap-2 md:grid-cols-2">
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-dimensions" class="inputlabel">Maße</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}dimensions" id="{{ $baseID }}-dimensions" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.Dimensions -}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-edit-state" class="inputlabel">Status</label>
|
||||||
|
</div>
|
||||||
|
<select name="{{ $prefix }}edit_state" id="{{ $baseID }}-edit-state" class="inputselect font-bold">
|
||||||
|
<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>
|
||||||
|
<option value="Edited" {{ if eq $content.EditState "Edited" }}selected{{ end }}>Erfasst</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-edit-comment" class="inputlabel">Bearbeitungsvermerk</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}edit_comment" id="{{ $baseID }}-edit-comment" class="inputinput no-enter" autocomplete="off" rows="1">{{- $content.Comment -}}</textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="inputwrapper">
|
||||||
|
<div class="inputlabelrow">
|
||||||
|
<label for="{{ $baseID }}-annotation" class="inputlabel">Anmerkung</label>
|
||||||
|
</div>
|
||||||
|
<textarea name="{{ $prefix }}annotation" id="{{ $baseID }}-annotation" class="inputinput" autocomplete="off" rows="2">{{- $content.Annotation -}}</textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</details>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user