mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Refactored single almanach view
This commit is contained in:
@@ -2,6 +2,14 @@ package dbmodels
|
|||||||
|
|
||||||
import "github.com/pocketbase/pocketbase/core"
|
import "github.com/pocketbase/pocketbase/core"
|
||||||
|
|
||||||
|
func Ids[T core.RecordProxy](records []T) []any {
|
||||||
|
ids := []any{}
|
||||||
|
for _, r := range records {
|
||||||
|
ids = append(ids, r.ProxyRecord().Id)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
func SetBasicPublicRules(collection *core.Collection) {
|
func SetBasicPublicRules(collection *core.Collection) {
|
||||||
collection.ViewRule = PUBLIC_VIEW_RULE
|
collection.ViewRule = PUBLIC_VIEW_RULE
|
||||||
collection.ListRule = PUBLIC_LIST_RULE
|
collection.ListRule = PUBLIC_LIST_RULE
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
// For scanning, with an Iter_ prefix, yields single row results
|
// For scanning, with an Iter_ prefix, yields single row results
|
||||||
|
|
||||||
func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
|
func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
|
||||||
return TableByField[[]*REntriesAgents](
|
return TableByFields[[]*REntriesAgents](
|
||||||
app,
|
app,
|
||||||
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
|
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
|
||||||
AGENTS_TABLE,
|
AGENTS_TABLE,
|
||||||
@@ -23,7 +23,7 @@ func REntriesAgents_Agent(app core.App, id string) ([]*REntriesAgents, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
|
func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
|
||||||
return TableByField[[]*REntriesAgents](
|
return TableByFields[[]*REntriesAgents](
|
||||||
app,
|
app,
|
||||||
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
|
RelationTableName(ENTRIES_TABLE, AGENTS_TABLE),
|
||||||
ENTRIES_TABLE,
|
ENTRIES_TABLE,
|
||||||
@@ -32,7 +32,7 @@ func REntriesAgents_Entry(app core.App, id string) ([]*REntriesAgents, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error) {
|
func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error) {
|
||||||
return TableByField[[]*RContentsAgents](
|
return TableByFields[[]*RContentsAgents](
|
||||||
app,
|
app,
|
||||||
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
|
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
|
||||||
AGENTS_TABLE,
|
AGENTS_TABLE,
|
||||||
@@ -40,8 +40,17 @@ func RContentsAgents_Agent(app core.App, id string) ([]*RContentsAgents, error)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func REntriesSeries_Entries(app core.App, ids any) ([]*REntriesSeries, error) {
|
func RContentsAgents_Contents(app core.App, id []any) ([]*RContentsAgents, error) {
|
||||||
return TableByField[[]*REntriesSeries](
|
return TableByFields[[]*RContentsAgents](
|
||||||
|
app,
|
||||||
|
RelationTableName(CONTENTS_TABLE, AGENTS_TABLE),
|
||||||
|
CONTENTS_TABLE,
|
||||||
|
id,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func REntriesSeries_Entries(app core.App, ids []any) ([]*REntriesSeries, error) {
|
||||||
|
return TableByFields[[]*REntriesSeries](
|
||||||
app,
|
app,
|
||||||
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
|
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
|
||||||
ENTRIES_TABLE,
|
ENTRIES_TABLE,
|
||||||
@@ -49,18 +58,55 @@ func REntriesSeries_Entries(app core.App, ids any) ([]*REntriesSeries, error) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func REntriesSeries_Entry(app core.App, id string) ([]*REntriesSeries, error) {
|
||||||
|
return TableByFields[[]*REntriesSeries](
|
||||||
|
app,
|
||||||
|
RelationTableName(ENTRIES_TABLE, SERIES_TABLE),
|
||||||
|
ENTRIES_TABLE,
|
||||||
|
id,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func Agents_ID(app core.App, id string) (*Agent, error) {
|
func Agents_ID(app core.App, id string) (*Agent, error) {
|
||||||
return TableByID[*Agent](app, AGENTS_TABLE, id)
|
r, err := TableByID[Agent](app, AGENTS_TABLE, id)
|
||||||
|
return &r, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Agents_IDs(app core.App, ids []any) ([]*Agent, error) {
|
||||||
|
return TableByIDs[[]*Agent](app, AGENTS_TABLE, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Entries_ID(app core.App, id string) (*Entry, error) {
|
||||||
|
e, err := TableByID[Entry](app, ENTRIES_TABLE, id)
|
||||||
|
return &e, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func Entries_MusenalmID(app core.App, id string) (*Entry, error) {
|
||||||
|
ret, err := TableByField[Entry](app, ENTRIES_TABLE, MUSENALMID_FIELD, id)
|
||||||
|
return &ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Entries_IDs(app core.App, ids []any) ([]*Entry, error) {
|
func Entries_IDs(app core.App, ids []any) ([]*Entry, error) {
|
||||||
return TableByID[[]*Entry](app, ENTRIES_TABLE, ids)
|
return TableByIDs[[]*Entry](app, ENTRIES_TABLE, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Series_IDs(app core.App, ids []any) ([]*Series, error) {
|
func Series_IDs(app core.App, ids []any) ([]*Series, error) {
|
||||||
return TableByID[[]*Series](app, SERIES_TABLE, ids)
|
return TableByIDs[[]*Series](app, SERIES_TABLE, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Places_IDs(app core.App, ids []any) ([]*Place, error) {
|
||||||
|
return TableByIDs[[]*Place](app, PLACES_TABLE, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Contents_IDs(app core.App, ids []any) ([]*Content, error) {
|
func Contents_IDs(app core.App, ids []any) ([]*Content, error) {
|
||||||
return TableByID[[]*Content](app, CONTENTS_TABLE, ids)
|
return TableByIDs[[]*Content](app, CONTENTS_TABLE, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Contents_Entry(app core.App, id string) ([]*Content, error) {
|
||||||
|
return TableByFields[[]*Content](
|
||||||
|
app,
|
||||||
|
CONTENTS_TABLE,
|
||||||
|
ENTRIES_TABLE,
|
||||||
|
id,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,30 +11,55 @@ import (
|
|||||||
|
|
||||||
// BUG: this is not working:
|
// BUG: this is not working:
|
||||||
// github.com/pocketbase/pocketbase/apis.NewRouter.panicRecover.func3.1()
|
// github.com/pocketbase/pocketbase/apis.NewRouter.panicRecover.func3.1()
|
||||||
|
//
|
||||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/apis/middlewares.go:269 +0x13c
|
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/apis/middlewares.go:269 +0x13c
|
||||||
|
//
|
||||||
// panic({0x15b34c0?, 0x2831680?})
|
// panic({0x15b34c0?, 0x2831680?})
|
||||||
|
//
|
||||||
// /usr/local/go/src/runtime/panic.go:787 +0x132
|
// /usr/local/go/src/runtime/panic.go:787 +0x132
|
||||||
|
//
|
||||||
// github.com/pocketbase/pocketbase/core.(*Record).FieldsData(0xc000632820)
|
// github.com/pocketbase/pocketbase/core.(*Record).FieldsData(0xc000632820)
|
||||||
|
//
|
||||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:774 +0x1a
|
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:774 +0x1a
|
||||||
|
//
|
||||||
// github.com/pocketbase/pocketbase/core.(*Record).PostScan(0xc000632820)
|
// github.com/pocketbase/pocketbase/core.(*Record).PostScan(0xc000632820)
|
||||||
|
//
|
||||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:591 +0x4e
|
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/core/record_model.go:591 +0x4e
|
||||||
|
//
|
||||||
// github.com/pocketbase/dbx.(*Rows).ScanStruct(0xc00052e6d0, {0x175f840?, 0xc000586060?})
|
// github.com/pocketbase/dbx.(*Rows).ScanStruct(0xc00052e6d0, {0x175f840?, 0xc000586060?})
|
||||||
|
//
|
||||||
// /home/simon/go/pkg/mod/github.com/pocketbase/dbx@v1.11.0/rows.go:97 +0x32e
|
// /home/simon/go/pkg/mod/github.com/pocketbase/dbx@v1.11.0/rows.go:97 +0x32e
|
||||||
|
//
|
||||||
// github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels.Iter_TableByField[...].func1()
|
// github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels.Iter_TableByField[...].func1()
|
||||||
|
//
|
||||||
// /home/simon/source/musenalm/dbmodels/queryhelpers.go:23 +0x65
|
// /home/simon/source/musenalm/dbmodels/queryhelpers.go:23 +0x65
|
||||||
|
//
|
||||||
// github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels.Iter_REntriesAgents_Agent.func1(0xc000624840)
|
// github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels.Iter_REntriesAgents_Agent.func1(0xc000624840)
|
||||||
|
//
|
||||||
// /home/simon/source/musenalm/dbmodels/queries_iter.go:30 +0xae
|
// /home/simon/source/musenalm/dbmodels/queries_iter.go:30 +0xae
|
||||||
|
//
|
||||||
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.(*PersonResult).FilterEntriesByPerson(0x1762c40?, {0x1dfba88, 0xc000438870}, {0xc00004627c, 0xf}, 0xc000064720)
|
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.(*PersonResult).FilterEntriesByPerson(0x1762c40?, {0x1dfba88, 0xc000438870}, {0xc00004627c, 0xf}, 0xc000064720)
|
||||||
|
//
|
||||||
// /home/simon/source/musenalm/pages/person.go:111 +0x248
|
// /home/simon/source/musenalm/pages/person.go:111 +0x248
|
||||||
|
//
|
||||||
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.NewPersonResult({0x1dfba88, 0xc000438870}, {0xc00004627c, 0xf})
|
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.NewPersonResult({0x1dfba88, 0xc000438870}, {0xc00004627c, 0xf})
|
||||||
|
//
|
||||||
// /home/simon/source/musenalm/pages/person.go:92 +0x4f
|
// /home/simon/source/musenalm/pages/person.go:92 +0x4f
|
||||||
|
//
|
||||||
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.(*PersonPage).Setup.func1(0xc0002da000)
|
// github.com/Theodor-Springmann-Stiftung/musenalm/pages.(*PersonPage).Setup.func1(0xc0002da000)
|
||||||
|
//
|
||||||
// /home/simon/source/musenalm/pages/person.go:46 +0x1ee
|
// /home/simon/source/musenalm/pages/person.go:46 +0x1ee
|
||||||
|
//
|
||||||
// github.com/pocketbase/pocketbase/tools/hook.(*Hook[...]).Trigger.func1()
|
// github.com/pocketbase/pocketbase/tools/hook.(*Hook[...]).Trigger.func1()
|
||||||
|
//
|
||||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/hook.go:169 +0x5d
|
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/hook.go:169 +0x5d
|
||||||
|
//
|
||||||
// github.com/pocketbase/pocketbase/tools/hook.(*Event).Next(0xc0002da000?)
|
// github.com/pocketbase/pocketbase/tools/hook.(*Event).Next(0xc0002da000?)
|
||||||
|
//
|
||||||
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/event.go:32 +0x17
|
// /home/simon/go/pkg/mod/github.com/pocketbase/pocketbase@v0.25.5/tools/hook/event.go:32 +0x17
|
||||||
|
//
|
||||||
// github.com/pocketbase/pocketbase/apis.NewRouter.BodyLimit.func7(0xc0002da000)
|
// github.com/pocketbase/pocketbase/apis.NewRouter.BodyLimit.func7(0xc0002da000)
|
||||||
|
//
|
||||||
// /home
|
// /home
|
||||||
func Iter_TableByField[T interface{}](app core.App, table, field string, value interface{}) (iter.Seq2[*T, error], error) {
|
func Iter_TableByField[T interface{}](app core.App, table, field string, value interface{}) (iter.Seq2[*T, error], error) {
|
||||||
rows, err := app.RecordQuery(table).
|
rows, err := app.RecordQuery(table).
|
||||||
@@ -74,10 +99,22 @@ func Iter_TableByID[T interface{}](app core.App, table, id interface{}) (iter.Se
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TableByField[T interface{}](app core.App, table, field string, value interface{}) (T, error) {
|
func TableByField[T interface{}](app core.App, table, field string, value string) (T, error) {
|
||||||
var ret T
|
var ret T
|
||||||
err := app.RecordQuery(table).
|
err := app.RecordQuery(table).
|
||||||
Where(dbx.HashExp{field: value}).
|
Where(dbx.HashExp{field: value}).
|
||||||
|
One(&ret)
|
||||||
|
if err != nil {
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TableByFields[T interface{}](app core.App, table, field string, values any) (T, error) {
|
||||||
|
var ret T
|
||||||
|
err := app.RecordQuery(table).
|
||||||
|
Where(dbx.HashExp{field: values}).
|
||||||
All(&ret)
|
All(&ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, err
|
return ret, err
|
||||||
@@ -86,10 +123,22 @@ func TableByField[T interface{}](app core.App, table, field string, value interf
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TableByID[T interface{}](app core.App, table, id interface{}) (T, error) {
|
func TableByID[T interface{}](app core.App, table, id string) (T, error) {
|
||||||
var ret T
|
var ret T
|
||||||
err := app.RecordQuery(table).
|
err := app.RecordQuery(table).
|
||||||
Where(dbx.HashExp{ID_FIELD: id}).
|
Where(dbx.HashExp{ID_FIELD: id}).
|
||||||
|
One(&ret)
|
||||||
|
if err != nil {
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TableByIDs[T interface{}](app core.App, table string, ids []any) (T, error) {
|
||||||
|
var ret T
|
||||||
|
err := app.RecordQuery(table).
|
||||||
|
Where(dbx.HashExp{ID_FIELD: ids}).
|
||||||
All(&ret)
|
All(&ret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, err
|
return ret, err
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -9,6 +9,7 @@ require (
|
|||||||
github.com/pocketbase/dbx v1.11.0
|
github.com/pocketbase/dbx v1.11.0
|
||||||
github.com/pocketbase/pocketbase v0.25.5
|
github.com/pocketbase/pocketbase v0.25.5
|
||||||
github.com/yalue/merged_fs v1.3.0
|
github.com/yalue/merged_fs v1.3.0
|
||||||
|
golang.org/x/net v0.35.0
|
||||||
golang.org/x/text v0.22.0
|
golang.org/x/text v0.22.0
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,7 +58,6 @@ require (
|
|||||||
golang.org/x/crypto v0.33.0 // indirect
|
golang.org/x/crypto v0.33.0 // indirect
|
||||||
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
|
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
|
||||||
golang.org/x/image v0.24.0 // indirect
|
golang.org/x/image v0.24.0 // indirect
|
||||||
golang.org/x/net v0.35.0 // indirect
|
|
||||||
golang.org/x/oauth2 v0.26.0 // indirect
|
golang.org/x/oauth2 v0.26.0 // indirect
|
||||||
golang.org/x/sync v0.11.0 // indirect
|
golang.org/x/sync v0.11.0 // indirect
|
||||||
golang.org/x/sys v0.30.0 // indirect
|
golang.org/x/sys v0.30.0 // indirect
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package pages
|
|||||||
import (
|
import (
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/app"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/musenalm/helpers/datatypes"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/pagemodels"
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
@@ -31,55 +32,12 @@ func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], app core
|
|||||||
router.GET(URL_ALMANACH, func(e *core.RequestEvent) error {
|
router.GET(URL_ALMANACH, func(e *core.RequestEvent) error {
|
||||||
id := e.Request.PathValue("id")
|
id := e.Request.PathValue("id")
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
entry, err := dbmodels.EntryForMusenalmID(app, id)
|
result, err := NewAlmanachResult(app, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return engine.Response404(e, err, data)
|
engine.Response404(e, err, nil)
|
||||||
}
|
|
||||||
data["entry"] = entry
|
|
||||||
|
|
||||||
series, srelations, _, err := dbmodels.SeriesForEntries(app, []*dbmodels.Entry{entry})
|
|
||||||
if err != nil {
|
|
||||||
return engine.Response404(e, err, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s := map[string]*dbmodels.Series{}
|
data["result"] = result
|
||||||
for _, r := range series {
|
|
||||||
s[r.Id] = r
|
|
||||||
}
|
|
||||||
|
|
||||||
data["srelations"] = srelations
|
|
||||||
data["series"] = series
|
|
||||||
|
|
||||||
places, err := dbmodels.PlacesForEntry(app, entry)
|
|
||||||
if err != nil {
|
|
||||||
return engine.Response404(e, err, data)
|
|
||||||
}
|
|
||||||
data["places"] = places
|
|
||||||
|
|
||||||
contents, err := dbmodels.ContentsForEntry(app, entry)
|
|
||||||
if err != nil {
|
|
||||||
return engine.Response404(e, err, data)
|
|
||||||
}
|
|
||||||
data["contents"] = contents
|
|
||||||
|
|
||||||
agents, arelations, err := dbmodels.AgentsForEntries(app, []*dbmodels.Entry{entry})
|
|
||||||
if err != nil {
|
|
||||||
return engine.Response404(e, err, data)
|
|
||||||
}
|
|
||||||
data["arelations"] = arelations
|
|
||||||
|
|
||||||
if len(contents) > 0 {
|
|
||||||
cagents, crelations, err := dbmodels.AgentsForContents(app, contents)
|
|
||||||
if err != nil {
|
|
||||||
return engine.Response404(e, err, data)
|
|
||||||
}
|
|
||||||
data["crelations"] = crelations
|
|
||||||
for k, v := range cagents {
|
|
||||||
agents[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
data["agents"] = agents
|
|
||||||
|
|
||||||
err = p.getAbbr(app, data)
|
err = p.getAbbr(app, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return engine.Response404(e, err, data)
|
return engine.Response404(e, err, data)
|
||||||
@@ -110,7 +68,84 @@ type AlmanachResult struct {
|
|||||||
Places []*dbmodels.Place
|
Places []*dbmodels.Place
|
||||||
Series []*dbmodels.Series
|
Series []*dbmodels.Series
|
||||||
Contents []*dbmodels.Content
|
Contents []*dbmodels.Content
|
||||||
|
Agents map[string]*dbmodels.Agent // <- Key is agent id
|
||||||
|
EntriesSeries map[string]*dbmodels.REntriesSeries // <- Key is series id
|
||||||
|
EntriesAgents []*dbmodels.REntriesAgents
|
||||||
|
ContentsAgents map[string][]*dbmodels.RContentsAgents // <- Key is content id
|
||||||
}
|
}
|
||||||
|
|
||||||
type AlmanachData struct {
|
func NewAlmanachResult(app core.App, id string) (*AlmanachResult, error) {
|
||||||
|
// INFO: what about sql.ErrNoRows?
|
||||||
|
// We don't get sql.ErrNoRows here, since dbx converts every empty slice or
|
||||||
|
// empty id to a WHERE 0=1 query, which will not error.
|
||||||
|
entry, err := dbmodels.Entries_MusenalmID(app, id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
places, err := dbmodels.Places_IDs(app, datatypes.ToAny(entry.Places()))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
srelations, err := dbmodels.REntriesSeries_Entry(app, entry.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
sids := []any{}
|
||||||
|
srelationsMap := map[string]*dbmodels.REntriesSeries{}
|
||||||
|
for _, r := range srelations {
|
||||||
|
sids = append(sids, r.Series())
|
||||||
|
srelationsMap[r.Series()] = r
|
||||||
|
}
|
||||||
|
|
||||||
|
series, err := dbmodels.Series_IDs(app, sids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
contents, err := dbmodels.Contents_Entry(app, entry.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
contentsagents, err := dbmodels.RContentsAgents_Contents(app, dbmodels.Ids(contents))
|
||||||
|
caids := []any{}
|
||||||
|
caMap := map[string][]*dbmodels.RContentsAgents{}
|
||||||
|
for _, r := range contentsagents {
|
||||||
|
caids = append(caids, r.Agent())
|
||||||
|
caMap[r.Content()] = append(caMap[r.Content()], r)
|
||||||
|
}
|
||||||
|
|
||||||
|
entriesagents, err := dbmodels.REntriesAgents_Entry(app, entry.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, r := range entriesagents {
|
||||||
|
caids = append(caids, r.Agent())
|
||||||
|
}
|
||||||
|
|
||||||
|
agents, err := dbmodels.Agents_IDs(app, caids)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
agentsMap := map[string]*dbmodels.Agent{}
|
||||||
|
for _, a := range agents {
|
||||||
|
agentsMap[a.Id] = a
|
||||||
|
}
|
||||||
|
|
||||||
|
return &AlmanachResult{
|
||||||
|
Entry: entry,
|
||||||
|
Places: places,
|
||||||
|
Series: series,
|
||||||
|
Contents: contents,
|
||||||
|
Agents: agentsMap,
|
||||||
|
EntriesSeries: srelationsMap,
|
||||||
|
EntriesAgents: entriesagents,
|
||||||
|
ContentsAgents: caMap,
|
||||||
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ type AgentResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAgentResult(app core.App, id string) (*AgentResult, error) {
|
func NewAgentResult(app core.App, id string) (*AgentResult, error) {
|
||||||
agent, err := dbmodels.AgentForId(app, id)
|
agent, err := dbmodels.Agents_ID(app, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ tmp_dir = "tmp"
|
|||||||
|
|
||||||
[build]
|
[build]
|
||||||
args_bin = []
|
args_bin = []
|
||||||
full_bin = ""
|
full_bin = "true"
|
||||||
cmd = "npm run build"
|
cmd = "npm run build"
|
||||||
delay = 400
|
delay = 400
|
||||||
exclude_dir = [
|
exclude_dir = [
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -1,11 +1,23 @@
|
|||||||
{{ $model := . }}
|
{{ $model := . }}
|
||||||
|
{{/* .result:
|
||||||
|
type AlmanachResult struct {
|
||||||
|
Entry *dbmodels.Entry
|
||||||
|
Places []*dbmodels.Place
|
||||||
|
Series []*dbmodels.Series
|
||||||
|
Contents []*dbmodels.Content
|
||||||
|
Agents map[string]*dbmodels.Agent // <- Key is agent id
|
||||||
|
EntriesSeries map[string]*dbmodels.REntriesSeries // <- Key is series id
|
||||||
|
EntriesAgents []*dbmodels.REntriesAgents
|
||||||
|
ContentsAgents map[string][]*dbmodels.RContentsAgents // <- Key is content id
|
||||||
|
}
|
||||||
|
*/}}
|
||||||
{{ $isGer := false }}
|
{{ $isGer := false }}
|
||||||
{{ $isFra := false }}
|
{{ $isFra := false }}
|
||||||
{{ $isEng := false }}
|
{{ $isEng := false }}
|
||||||
|
|
||||||
|
|
||||||
<div id="breadcrumbs">
|
<div id="breadcrumbs">
|
||||||
{{- range $i, $s := $model.series -}}
|
{{- range $i, $s := $model.result.Series -}}
|
||||||
<div>
|
<div>
|
||||||
<div class="{{ if $i -}}opacity-0 pointer-events-none select-none{{- end -}}">
|
<div class="{{ if $i -}}opacity-0 pointer-events-none select-none{{- end -}}">
|
||||||
Reihentitel <i class="ri-arrow-right-wide-line"></i>
|
Reihentitel <i class="ri-arrow-right-wide-line"></i>
|
||||||
@@ -14,10 +26,10 @@
|
|||||||
<a href="/reihe/{{- $s.MusenalmID -}}">{{ $s.Title }}</a>
|
<a href="/reihe/{{- $s.MusenalmID -}}">{{ $s.Title }}</a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{{- if $model.entry.Year -}}
|
{{- if $model.result.Entry.Year -}}
|
||||||
<i class="ri-arrow-right-wide-line"></i> <b>{{ $model.entry.Year }}</b>
|
<i class="ri-arrow-right-wide-line"></i> <b>{{ $model.result.Entry.Year }}</b>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<i class="ri-arrow-right-wide-line"></i> <b>{{ $model.entry.PreferredTitle }}</b>
|
<i class="ri-arrow-right-wide-line"></i> <b>{{ $model.result.Entry.PreferredTitle }}</b>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
<div class="grow"></div>
|
<div class="grow"></div>
|
||||||
@@ -36,49 +48,51 @@
|
|||||||
<div class="flex flex-col" id="entrydata">
|
<div class="flex flex-col" id="entrydata">
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Almanach-Nummer</div>
|
<div class="fieldlabel">Almanach-Nummer</div>
|
||||||
<div class="fieldvalue">{{ $model.entry.MusenalmID }}</div>
|
<div class="fieldvalue">{{ $model.result.Entry.MusenalmID }}</div>
|
||||||
</div>
|
</div>
|
||||||
{{- if $model.entry.PreferredTitle -}}
|
{{- if $model.result.Entry.PreferredTitle -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Kurztitel</div>
|
<div class="fieldlabel">Kurztitel</div>
|
||||||
<div class="fieldvalue">{{ $model.entry.PreferredTitle }}</div>
|
<div class="fieldvalue">{{ $model.result.Entry.PreferredTitle }}</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.entry.TitleStmt -}}
|
{{- if $model.result.Entry.TitleStmt -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Titel</div>
|
<div class="fieldlabel">Titel</div>
|
||||||
<div class="fieldvalue">{{ $model.entry.TitleStmt }}</div>
|
<div class="fieldvalue">{{ $model.result.Entry.TitleStmt }}</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Jahr</div>
|
<div class="fieldlabel">Jahr</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- if $model.entry.Year -}}
|
{{- if $model.result.Entry.Year -}}
|
||||||
<a href="/reihen?year={{ $model.entry.Year }}&hidden=true">{{ $model.entry.Year }}</a>
|
<a href="/reihen?year={{ $model.result.Entry.Year }}&hidden=true"
|
||||||
|
>{{ $model.result.Entry.Year }}</a
|
||||||
|
>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
[keine Angabe]
|
[keine Angabe]
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- if $model.entry.ResponsibilityStmt -}}
|
{{- if $model.result.Entry.ResponsibilityStmt -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Herausgeber</div>
|
<div class="fieldlabel">Herausgeber</div>
|
||||||
<div class="fieldvalue">{{ $model.entry.ResponsibilityStmt }}</div>
|
<div class="fieldvalue">{{ $model.result.Entry.ResponsibilityStmt }}</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.entry.Extent -}}
|
{{- if $model.result.Entry.Extent -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Umfang</div>
|
<div class="fieldlabel">Umfang</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
<abbrev-tooltips data-text="{{ $model.entry.Extent }}"></abbrev-tooltips>
|
<abbrev-tooltips data-text="{{ $model.result.Entry.Extent }}"></abbrev-tooltips>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.entry.Language -}}
|
{{- if $model.result.Entry.Language -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Sprache</div>
|
<div class="fieldlabel">Sprache</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- range $i, $lang := $model.entry.Language -}}
|
{{- range $i, $lang := $model.result.Entry.Language -}}
|
||||||
{{- if $i -}},{{- end -}}
|
{{- if $i -}},{{- end -}}
|
||||||
{{- if eq $lang "ger" -}}
|
{{- if eq $lang "ger" -}}
|
||||||
{{ $isGer = true }}
|
{{ $isGer = true }}
|
||||||
@@ -100,36 +114,35 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.entry.References -}}
|
{{- if $model.result.Entry.References -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Nachweise</div>
|
<div class="fieldlabel">Nachweise</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- $model.entry.References -}}
|
{{- $model.result.Entry.References -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.series -}}
|
{{- if $model.result.Series -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Reihen</div>
|
<div class="fieldlabel">Reihen</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- range $i, $s := $model.series -}}
|
{{- range $i, $s := $model.result.Series -}}
|
||||||
<div>
|
<div>
|
||||||
{{- $rel := index $model.srelations $s.Id -}}
|
{{- $rel := index $model.result.EntriesSeries $s.Id -}}
|
||||||
{{- if $rel -}}
|
{{- if $rel -}}
|
||||||
{{- $crel := index $rel 0 -}}
|
{{- if not (eq $rel.Type "Bevorzugter Reihentitel") -}}
|
||||||
{{- if not (eq $crel.Type "Bevorzugter Reihentitel") -}}
|
|
||||||
<span class="text-sm font-sans mr-2">
|
<span class="text-sm font-sans mr-2">
|
||||||
{{- if eq $crel.Type "Früherer Reihentitel" -}}
|
{{- if eq $rel.Type "Früherer Reihentitel" -}}
|
||||||
hat Titelauflage s.a.
|
hat Titelauflage s.a.
|
||||||
{{- else if eq $crel.Type "Späterer Reihentitel" -}}
|
{{- else if eq $rel.Type "Späterer Reihentitel" -}}
|
||||||
ist Titelauflage von, s.a.
|
ist Titelauflage von, s.a.
|
||||||
{{- else if eq $crel.Type "In anderer Sprache" -}}
|
{{- else if eq $rel.Type "In anderer Sprache" -}}
|
||||||
{{- if $isFra -}}
|
{{- if $isFra -}}
|
||||||
In deutscher Sprache s.a.
|
In deutscher Sprache s.a.
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
In französischer Sprache s.a.
|
In französischer Sprache s.a.
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- else if eq $crel.Type "Alternatives Titelblatt" -}}
|
{{- else if eq $rel.Type "Alternatives Titelblatt" -}}
|
||||||
alternatives Titelblatt, s.a.
|
alternatives Titelblatt, s.a.
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</span>
|
</span>
|
||||||
@@ -141,11 +154,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.places -}}
|
{{- if $model.result.Places -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Orte</div>
|
<div class="fieldlabel">Orte</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- range $i, $p := $model.places -}}
|
{{- range $i, $p := $model.result.Places -}}
|
||||||
<div>
|
<div>
|
||||||
<a href="/reihen?place={{ $p.Id }}&hidden=true">{{ $p.Name }}</a>
|
<a href="/reihen?place={{ $p.Id }}&hidden=true">{{ $p.Name }}</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -153,13 +166,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.arelations -}}
|
{{- if $model.result.EntriesAgents -}}
|
||||||
{{- $rels := index $model.arelations $model.entry.Id -}}
|
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Personen</div>
|
<div class="fieldlabel">Personen</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- range $i, $r := $rels -}}
|
{{- range $i, $r := $model.result.EntriesAgents -}}
|
||||||
{{- $a := index $model.agents $r.Agent -}}
|
{{- $a := index $model.result.Agents $r.Agent -}}
|
||||||
{{- if $a -}}
|
{{- if $a -}}
|
||||||
<div>
|
<div>
|
||||||
<a href="/person/{{ $a.Id }}">
|
<a href="/person/{{ $a.Id }}">
|
||||||
@@ -174,11 +186,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- if $model.entry.Annotation -}}
|
{{- if $model.result.Entry.Annotation -}}
|
||||||
<div class="entryrow">
|
<div class="entryrow">
|
||||||
<div class="fieldlabel">Anmerkungen</div>
|
<div class="fieldlabel">Anmerkungen</div>
|
||||||
<div class="fieldvalue">
|
<div class="fieldvalue">
|
||||||
{{- Safe (ReplaceSlashParen $model.entry.Annotation) -}}
|
{{- Safe (ReplaceSlashParen $model.result.Entry.Annotation) -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<div id="searchcontrol" class="container-normal">
|
<div id="searchcontrol" class="container-normal">
|
||||||
{{- template "_heading" $model.parameters.Parameters -}}
|
{{- template "_heading" $model.parameters -}}
|
||||||
<div id="" class="border-l border-zinc-300 px-8 py-10 relative">
|
<div id="" class="border-l border-zinc-300 px-8 py-10 relative">
|
||||||
{{- if not $model.parameters.Extended -}}
|
{{- if not $model.parameters.Extended -}}
|
||||||
<form
|
<form
|
||||||
@@ -14,9 +14,9 @@
|
|||||||
<div class="searchformcolumn">
|
<div class="searchformcolumn">
|
||||||
{{- $q := "" }}
|
{{- $q := "" }}
|
||||||
{{- if $model.parameters.Query -}}
|
{{- if $model.parameters.Query -}}
|
||||||
{{- q = $model.parameters.Query -}}
|
{{- $q = $model.parameters.Query -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{ template "_searchboxsimple" Arr $model.parameters.Parameters true $q }}
|
{{ template "_searchboxsimple" Arr $model.parameters true $q }}
|
||||||
<fieldset class="selectgroup">
|
<fieldset class="selectgroup">
|
||||||
<div class="selectgroup-option">
|
<div class="selectgroup-option">
|
||||||
<input type="checkbox" name="alm" id="alm" checked />
|
<input type="checkbox" name="alm" id="alm" checked />
|
||||||
@@ -51,11 +51,11 @@
|
|||||||
<label for="annotations">Anmerkungen</label>
|
<label for="annotations">Anmerkungen</label>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{ template "infotextsimple" true }}
|
{{ template "_infotextsimple" true }}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{{- template "_fieldscript" -}}
|
{{- template "_fieldscript" -}}
|
||||||
|
|||||||
@@ -2,21 +2,21 @@
|
|||||||
|
|
||||||
|
|
||||||
<div id="searchcontrol" class="container-normal">
|
<div id="searchcontrol" class="container-normal">
|
||||||
{{- template "_heading" $model.parameters.Parameters -}}
|
{{- template "_heading" $model.parameters -}}
|
||||||
<div id="" class="border-l border-zinc-300 px-8 py-10 relative">
|
<div id="" class="border-l border-zinc-300 px-8 py-10 relative">
|
||||||
{{- if not $model.parameters.Extended -}}
|
{{- if not $model.parameters.Extended -}}
|
||||||
<form
|
<form
|
||||||
id="searchform"
|
id="searchform"
|
||||||
class="w-full font-serif"
|
class="w-full font-serif"
|
||||||
method="get"
|
method="get"
|
||||||
action="/suche/baende"
|
action="/suche/beitraege"
|
||||||
autocomplete="off">
|
autocomplete="off">
|
||||||
<div class="searchformcolumn">
|
<div class="searchformcolumn">
|
||||||
{{- $q := "" }}
|
{{- $q := "" }}
|
||||||
{{- if $model.parameters.Query -}}
|
{{- if $model.parameters.Query -}}
|
||||||
{{- q = $model.parameters.Query -}}
|
{{- $q = $model.parameters.Query -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{ template "_searchboxsimple" Arr $model.parameters.Parameters true $q }}
|
{{ template "_searchboxsimple" Arr $model.parameters true $q }}
|
||||||
<fieldset class="selectgroup">
|
<fieldset class="selectgroup">
|
||||||
<div class="selectgroup-option">
|
<div class="selectgroup-option">
|
||||||
<input type="checkbox" name="number" id="number" checked />
|
<input type="checkbox" name="number" id="number" checked />
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
<label for="annotations">Anmerkungen</label>
|
<label for="annotations">Anmerkungen</label>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{ template "infotextsimple" true }}
|
{{ template "_infotextsimple" true }}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user