+a-z nav on alma pages

This commit is contained in:
Simon Martens
2026-01-12 20:14:47 +01:00
parent 98b9888e83
commit bcf7d1847d
3 changed files with 70 additions and 31 deletions

View File

@@ -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{}

View File

@@ -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")