From bcf7d1847d47391a758ccb9445748740f012adf4 Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Mon, 12 Jan 2026 20:14:47 +0100 Subject: [PATCH] +a-z nav on alma pages --- controllers/almanach.go | 36 +++++++++++++++++ controllers/almanach_edit.go | 26 ------------- .../almanach/components/entrydata.gohtml | 39 ++++++++++++++++--- 3 files changed, 70 insertions(+), 31 deletions(-) diff --git a/controllers/almanach.go b/controllers/almanach.go index 7b84aca..c119a70 100644 --- a/controllers/almanach.go +++ b/controllers/almanach.go @@ -67,6 +67,9 @@ type AlmanachResult struct { Types []string HasScans bool + + PrevByTitle *dbmodels.Entry + NextByTitle *dbmodels.Entry } func NewAlmanachResult(app core.App, id string, params BeitraegeFilterParameters) (*AlmanachResult, error) { @@ -167,6 +170,11 @@ func NewAlmanachResult(app core.App, id string, params BeitraegeFilterParameters agentsMap[a.Id] = a } + prevByTitle, nextByTitle, err := entryNeighborsByPreferredTitle(app, entry.Id) + if err != nil { + return nil, err + } + ret := &AlmanachResult{ Entry: entry, Places: places, @@ -179,6 +187,8 @@ func NewAlmanachResult(app core.App, id string, params BeitraegeFilterParameters ContentsAgents: caMap, Types: types, HasScans: hs, + PrevByTitle: prevByTitle, + NextByTitle: nextByTitle, } ret.Collections() @@ -186,6 +196,32 @@ func NewAlmanachResult(app core.App, id string, params BeitraegeFilterParameters } +func entryNeighborsByPreferredTitle(app core.App, entryID string) (*dbmodels.Entry, *dbmodels.Entry, error) { + entries := []*dbmodels.Entry{} + if err := app.RecordQuery(dbmodels.ENTRIES_TABLE).All(&entries); err != nil { + return nil, nil, err + } + if len(entries) == 0 { + return nil, nil, nil + } + dbmodels.Sort_Entries_Title_Year(entries) + for index, item := range entries { + if item.Id != entryID { + continue + } + var prev *dbmodels.Entry + var next *dbmodels.Entry + if index > 0 { + prev = entries[index-1] + } + if index+1 < len(entries) { + next = entries[index+1] + } + return prev, next, nil + } + return nil, nil, nil +} + func (r *AlmanachResult) Collections() { ids := []int{} collections := []*dbmodels.Content{} diff --git a/controllers/almanach_edit.go b/controllers/almanach_edit.go index afe4e06..e9e41d0 100644 --- a/controllers/almanach_edit.go +++ b/controllers/almanach_edit.go @@ -116,32 +116,6 @@ func NewAlmanachEditResult(app core.App, id string, filters BeitraegeFilterParam }, nil } -func entryNeighborsByPreferredTitle(app core.App, entryID string) (*dbmodels.Entry, *dbmodels.Entry, error) { - entries := []*dbmodels.Entry{} - if err := app.RecordQuery(dbmodels.ENTRIES_TABLE).All(&entries); err != nil { - return nil, nil, err - } - if len(entries) == 0 { - return nil, nil, nil - } - dbmodels.Sort_Entries_Title_Year(entries) - for index, item := range entries { - if item.Id != entryID { - continue - } - var prev *dbmodels.Entry - var next *dbmodels.Entry - if index > 0 { - prev = entries[index-1] - } - if index+1 < len(entries) { - next = entries[index+1] - } - return prev, next, nil - } - return nil, nil, nil -} - func (p *AlmanachEditPage) POSTSave(engine *templating.Engine, app core.App) HandleFunc { return func(e *core.RequestEvent) error { id := e.Request.PathValue("id") diff --git a/views/routes/almanach/components/entrydata.gohtml b/views/routes/almanach/components/entrydata.gohtml index ed4cb68..19b8135 100644 --- a/views/routes/almanach/components/entrydata.gohtml +++ b/views/routes/almanach/components/entrydata.gohtml @@ -22,12 +22,41 @@
Almanach
- {{- if (IsAdminOrEditor $model.request.user) -}} -
- - Bearbeiten +
+ +
+ {{- if $model.result.PrevByTitle -}} + +
{{ $model.result.PrevByTitle.PreferredTitle }}
+ + + +
+ {{- end -}} + + A - Z + + {{- if $model.result.NextByTitle -}} + +
{{ $model.result.NextByTitle.PreferredTitle }}
+ + + +
+ {{- end -}}
- {{- end -}} + + {{- if (IsAdminOrEditor $model.request.user) -}} +
+ + Bearbeiten +
+ {{- end -}} +