diff --git a/controllers/baende.go b/controllers/baende.go new file mode 100644 index 0000000..f45b6c1 --- /dev/null +++ b/controllers/baende.go @@ -0,0 +1,163 @@ +package controllers + +import ( + "net/url" + "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/dbx" + "github.com/pocketbase/pocketbase/core" + "github.com/pocketbase/pocketbase/tools/router" +) + +const ( + URL_BAENDE = "/baende/" + TEMPLATE_BAENDE = "/baende/" +) + +func init() { + bp := &BaendePage{ + StaticPage: pagemodels.StaticPage{ + Name: pagemodels.P_BAENDE_NAME, + URL: URL_BAENDE, + Template: TEMPLATE_BAENDE, + Layout: templating.DEFAULT_LAYOUT_NAME, + }, + } + app.Register(bp) +} + +type BaendePage struct { + pagemodels.StaticPage +} + +type BaendeResult struct { + Entries []*dbmodels.Entry + Series map[string]*dbmodels.Series + EntriesSeries map[string][]*dbmodels.REntriesSeries + Places map[string]*dbmodels.Place + Agents map[string]*dbmodels.Agent + EntriesAgents map[string][]*dbmodels.REntriesAgents + Items map[string][]*dbmodels.Item +} + +func (p *BaendePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error { + app := ia.Core() + rg := router.Group(URL_BAENDE) + rg.BindFunc(middleware.Authenticated(app)) + rg.GET("", func(e *core.RequestEvent) error { + req := templating.NewRequest(e) + if req.User() == nil { + redirectTo := url.QueryEscape(req.FullURL()) + return e.Redirect(303, "/login/?redirectTo="+redirectTo) + } + + letter := strings.ToUpper(strings.TrimSpace(e.Request.URL.Query().Get("letter"))) + if letter == "" { + letter = "A" + } + if len(letter) > 1 { + letter = letter[:1] + } + if letter < "A" || letter > "Z" { + letter = "A" + } + + entries := []*dbmodels.Entry{} + if err := app.RecordQuery(dbmodels.ENTRIES_TABLE). + Where(dbx.Like(dbmodels.PREFERRED_TITLE_FIELD, letter).Match(false, true)). + OrderBy(dbmodels.PREFERRED_TITLE_FIELD). + All(&entries); err != nil { + return engine.Response500(e, err, nil) + } + + entryIDs := []any{} + for _, entry := range entries { + entryIDs = append(entryIDs, entry.Id) + } + + seriesMap := map[string]*dbmodels.Series{} + entrySeriesMap := map[string][]*dbmodels.REntriesSeries{} + if len(entries) > 0 { + series, relations, err := Series_Entries(app, entries) + if err != nil { + return engine.Response500(e, err, nil) + } + for _, s := range series { + seriesMap[s.Id] = s + } + for _, r := range relations { + entrySeriesMap[r.Entry()] = append(entrySeriesMap[r.Entry()], r) + } + } + + agentsMap := map[string]*dbmodels.Agent{} + entryAgentsMap := map[string][]*dbmodels.REntriesAgents{} + if len(entryIDs) > 0 { + agents, arelations, err := Agents_Entries_IDs(app, entryIDs) + if err != nil { + return engine.Response500(e, err, nil) + } + for _, a := range agents { + agentsMap[a.Id] = a + } + for _, r := range arelations { + entryAgentsMap[r.Entry()] = append(entryAgentsMap[r.Entry()], r) + } + } + + placesMap := map[string]*dbmodels.Place{} + placesIDs := []any{} + for _, entry := range entries { + for _, placeID := range entry.Places() { + placesIDs = append(placesIDs, placeID) + } + } + if len(placesIDs) > 0 { + places, err := dbmodels.Places_IDs(app, placesIDs) + if err != nil { + return engine.Response500(e, err, nil) + } + for _, place := range places { + placesMap[place.Id] = place + } + } + + itemsMap := map[string][]*dbmodels.Item{} + for _, entry := range entries { + items, err := dbmodels.Items_Entry(app, entry.Id) + if err != nil { + return engine.Response500(e, err, nil) + } + if len(items) > 0 { + itemsMap[entry.Id] = items + } + } + + letters := []string{ + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", + "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", + } + + data := map[string]any{ + "result": &BaendeResult{ + Entries: entries, + Series: seriesMap, + EntriesSeries: entrySeriesMap, + Places: placesMap, + Agents: agentsMap, + EntriesAgents: entryAgentsMap, + Items: itemsMap, + }, + "letter": letter, + "letters": letters, + "csrf_token": req.Session().Token, + } + return engine.Response200(e, p.Template, data, p.Layout) + }) + return nil +} diff --git a/pagemodels/pagedata.go b/pagemodels/pagedata.go index 72e5874..3c8f8c4 100644 --- a/pagemodels/pagedata.go +++ b/pagemodels/pagedata.go @@ -13,6 +13,7 @@ const ( T_INDEX_TEXTE = "texte" P_REIHEN_NAME = "reihen" + P_BAENDE_NAME = "baende" P_ORTE_NAME = "orte" P_ABKUERZUNGEN_NAME = "abkuerzungen" P_DANK_NAME = "danksagungen" diff --git a/views/assets/scripts.js b/views/assets/scripts.js index 6bc951b..83edb1c 100644 --- a/views/assets/scripts.js +++ b/views/assets/scripts.js @@ -9072,6 +9072,15 @@ class Ac extends HTMLElement { +
| + | Titel | +Erscheinung | + + +Umfang / Maße | +Signaturen | +|
|---|---|---|---|---|---|
| + + | +
+
+ {{- if $entry.PreferredTitle -}}
+ {{ $entry.PreferredTitle }}
+ {{- else if ne $entry.Year 0 -}}
+ {{ $entry.Year }}
+ {{- else -}}
+ [o.J.]
+ {{- end -}}
+
+ {{- if $entry.TitleStmt -}}
+
+ {{- if eq $entry.EditState "Unknown" -}}
+ Gesucht
+ {{- else if eq $entry.EditState "ToDo" -}}
+ Zu erledigen
+ {{- else if eq $entry.EditState "Review" -}}
+ Überprüfen
+ {{- else if eq $entry.EditState "Seen" -}}
+ Autopsiert
+ {{- else if eq $entry.EditState "Edited" -}}
+ Vollständig Erfasst
+ {{- else -}}
+ {{ $entry.EditState }}
+ {{- end -}}
+
+
+ {{ $entry.TitleStmt }}
+
+ {{- end -}}
+ {{- if or $entry.SubtitleStmt $entry.VariantTitle $entry.ParallelTitle $entry.IncipitStmt -}}
+
+ {{- if $entry.SubtitleStmt -}}
+
+ {{- end -}}
+ Untertitel: {{ $entry.SubtitleStmt }}
+ {{- end -}}
+ {{- if $entry.VariantTitle -}}
+ Varianten: {{ $entry.VariantTitle }}
+ {{- end -}}
+ {{- if $entry.ParallelTitle -}}
+ Parallel: {{ $entry.ParallelTitle }}
+ {{- end -}}
+ {{- if $entry.IncipitStmt -}}
+ Incipit: {{ $entry.IncipitStmt }}
+ {{- end -}}
+ |
+
+ {{- if or $entry.ResponsibilityStmt $entry.PublicationStmt $entry.PlaceStmt -}}
+
+ {{- if and $entry.ResponsibilityStmt (not (eq $entry.ResponsibilityStmt "unbezeichnet")) -}}
+
+ {{- end -}}
+
+
+ {{- end -}}
+ {{- if $entry.PublicationStmt -}}
+ Herausgaberangabe
+ {{ $entry.ResponsibilityStmt }}
+
+
+ {{- end -}}
+ {{- if $entry.PlaceStmt -}}
+ Publikationsangabe
+ {{ $entry.PublicationStmt }}
+
+
+ {{- end -}}
+ Ortsangabe
+ {{ $entry.PlaceStmt }}
+ |
+
+
+
+ {{- if or $entry.Extent $entry.Dimensions -}}
+
+ {{- if $entry.Extent -}}
+
+ {{- end -}}
+ Struktur{{ $entry.Extent }}
+ {{- end -}}
+ {{- if $entry.Dimensions -}}
+ Maße: {{ $entry.Dimensions }}
+ {{- end -}}
+ |
+
+ {{- $items := index $model.result.Items $entry.Id -}}
+ {{- if $items -}}
+
+ {{- range $_, $item := $items -}}
+
+ {{- end -}}
+
+ {{- if $item.Identifier -}}
+
+ {{- end -}}
+ {{ $item.Identifier }}
+ {{- end -}}
+ {{- if $item.Media -}}
+
+ {{- range $i, $media := $item.Media -}}{{- if $i }}, {{ end -}}{{ $media }}{{- end -}}
+
+ {{- end -}}
+ |
+ |
| + + | +
+
+
+
+
+
+ {{- if $entry.PreferredTitle -}}
+ {{ $entry.PreferredTitle }}
+ {{- else if ne $entry.Year 0 -}}
+ {{ $entry.Year }}
+ {{- else -}}
+ [o.J.]
+ {{- end -}}
+
+
+ {{- if eq $entry.EditState "Unknown" -}}
+ Gesucht
+ {{- else if eq $entry.EditState "ToDo" -}}
+ Zu erledigen
+ {{- else if eq $entry.EditState "Review" -}}
+ Überprüfen
+ {{- else if eq $entry.EditState "Seen" -}}
+ Autopsiert
+ {{- else if eq $entry.EditState "Edited" -}}
+ Vollständig Erfasst
+ {{- else -}}
+ {{ $entry.EditState }}
+ {{- end -}}
+
+
+
+
+ {{- if or $entry.TitleStmt $entry.SubtitleStmt $entry.VariantTitle $entry.ParallelTitle $entry.IncipitStmt -}}
+
+
+
+ {{- end -}}
+ {{- if or $entry.ResponsibilityStmt $entry.PublicationStmt $entry.PlaceStmt -}}
+ Titelangaben
+
+ {{- if $entry.TitleStmt -}}
+ Titel: {{ $entry.TitleStmt }} {{- end -}}
+ {{- if $entry.SubtitleStmt -}}Untertitel: {{ $entry.SubtitleStmt }} {{- end -}}
+ {{- if $entry.VariantTitle -}}Varianten: {{ $entry.VariantTitle }} {{- end -}}
+ {{- if $entry.ParallelTitle -}}Parallel: {{ $entry.ParallelTitle }} {{- end -}}
+ {{- if $entry.IncipitStmt -}}Incipit: {{ $entry.IncipitStmt }} {{- end -}}
+
+
+ {{- end -}}
+ {{- if $entry.Annotation -}}
+ Erscheinung
+
+ {{- if and $entry.ResponsibilityStmt (not (eq $entry.ResponsibilityStmt "unbezeichnet")) -}}
+ Herausgaberangabe: {{ $entry.ResponsibilityStmt }} {{- end -}}
+ {{- if $entry.PublicationStmt -}}Publikationsangabe: {{ $entry.PublicationStmt }} {{- end -}}
+ {{- if $entry.PlaceStmt -}}Ortsangabe: {{ $entry.PlaceStmt }} {{- end -}}
+
+
+ {{- end -}}
+ {{- $srels := index $model.result.EntriesSeries $entry.Id -}}
+ {{- if $srels -}}
+ Annotation
+ {{ $entry.Annotation }}
+
+
+ {{- end -}}
+ {{- if $entry.Places -}}
+ Reihen
+
+ {{- range $_, $rel := $srels -}}
+ {{- $s := index $model.result.Series $rel.Series -}}
+ {{- if $s -}}
+
+
+ {{- if not (eq $rel.Type "Bevorzugter Reihentitel") -}}
+ {{ $rel.Type }}
+ {{- end -}}
+ {{ $s.Title }}
+
+ {{- end -}}
+ {{- end -}}
+
+
+ {{- end -}}
+ {{- $arels := index $model.result.EntriesAgents $entry.Id -}}
+ {{- if $arels -}}
+ Orte
+
+ {{- $sep := false -}}
+ {{- range $_, $pid := $entry.Places -}}
+ {{- $p := index $model.result.Places $pid -}}
+ {{- if $p -}}
+ {{- if $sep }}, {{ end -}}
+ {{ $p.Name }}
+ {{- $sep = true -}}
+ {{- end -}}
+ {{- end -}}
+
+
+
+ {{- end -}}
+ Personen
+
+ {{- range $_, $arel := $arels -}}
+ {{- $a := index $model.result.Agents $arel.Agent -}}
+ {{- if $a -}}
+
+
+ {{ $a.Name }}
+ {{ $arel.Type }}
+
+ {{- end -}}
+ {{- end -}}
+
+ {{- if $entry.Comment -}}
+
+
+
+ {{- end -}}
+ {{- if $entry.Language -}}
+ Kommentar
+ {{ $entry.Comment }}
+
+
+ {{- end -}}
+ {{- if or $entry.Extent $entry.Dimensions -}}
+ Sprachen
+
+ {{- range $i, $lang := $entry.Language -}}{{- if $i }}, {{ end -}}{{ LanguageNameGerman $lang }}{{- end -}}
+
+
+
+ {{- end -}}
+ {{- if $entry.References -}}
+ Umfang / Maße
+
+ {{- if $entry.Extent -}}
+ Struktur{{ $entry.Extent }} {{- end -}}
+ {{- if $entry.Dimensions -}}Maße: {{ $entry.Dimensions }} {{- end -}}
+
+
+ {{- end -}}
+ {{- if ne $entry.Year 0 -}}
+ Nachweise
+ {{ $entry.References }}
+
+
+ {{- end -}}
+ {{- $items := index $model.result.Items $entry.Id -}}
+ {{- if $items -}}
+ Jahr
+ {{ $entry.Year }}
+
+
+ {{- end -}}
+ Exemplare
+
+ {{- range $_, $item := $items -}}
+
+
+
+ {{- end -}}
+
+
+ {{- if or $item.Location $item.Owner -}}
+
+ {{- if $item.Identifier -}}
+
+ {{ $item.Identifier }}
+ {{- end -}}
+ {{- if $item.Media -}}
+
+ {{- range $i, $media := $item.Media -}}{{- if $i }}, {{ end -}}{{ $media }}{{- end -}}
+
+ {{- end -}}
+
+ {{- if or $item.Location $item.Owner -}}
+
+
+ {{- if $item.Location -}}{{ $item.Location }}{{- end -}}
+ {{- if $item.Owner -}}{{ $item.Owner }}{{- end -}}
+
+ {{- end -}}
+
+ {{- if $item.Location -}}{{ $item.Location }}{{- end -}}
+ {{- if $item.Owner -}}{{ $item.Owner }}{{- end -}}
+
+ {{- end -}}
+ |
+ ||||