mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 01:05:32 +00:00
FTS5-Suche
This commit is contained in:
@@ -1,58 +1,43 @@
|
||||
package pagemodels
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
type DefaultPage struct {
|
||||
core.BaseRecordProxy
|
||||
type DefaultPage[T IPageCollection] struct {
|
||||
Record T
|
||||
Name string
|
||||
Template string
|
||||
Layout string
|
||||
URL string
|
||||
}
|
||||
|
||||
func NewDefaultPage(record *core.Record) *DefaultPage {
|
||||
i := &DefaultPage{}
|
||||
i.SetProxyRecord(record)
|
||||
return i
|
||||
}
|
||||
func (r *DefaultPage[T]) Up(app core.App, engine *templating.Engine) error {
|
||||
_, err := app.FindCollectionByNameOrId(GeneratePageTableName(r.Name))
|
||||
if err == sql.ErrNoRows {
|
||||
collection := r.Record.Collection(r.Name)
|
||||
err = app.Save(collection)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error saving collection", "Name", GeneratePageTableName(r.Name), "Error", err, "Collection", collection)
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
app.Logger().Error("Error finding collection %s: %s", GeneratePageTableName(r.Name), err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Title() string {
|
||||
return r.GetString(F_TITLE)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) SetTitle(titel string) {
|
||||
r.Set(F_TITLE, titel)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Description() string {
|
||||
return r.GetString(F_DESCRIPTION)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) SetDescription(beschreibung string) {
|
||||
r.Set(F_DESCRIPTION, beschreibung)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Keywords() string {
|
||||
return r.GetString(F_TAGS)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) SetKeywords(keywords string) {
|
||||
r.Set(F_TAGS, keywords)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Up(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Down(app core.App, engine *templating.Engine) error {
|
||||
func (r *DefaultPage[T]) Down(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DefaultPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
func (p *DefaultPage[T]) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||
data := make(map[string]interface{})
|
||||
|
||||
@@ -64,14 +49,14 @@ func (p *DefaultPage) Setup(router *router.Router[*core.RequestEvent], app core.
|
||||
return engine.Response404(e, err, data)
|
||||
}
|
||||
|
||||
p.SetProxyRecord(record)
|
||||
p.Record.SetProxyRecord(record)
|
||||
data["record"] = p
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DefaultPage) Get(e *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||
func (p *DefaultPage[T]) Get(e *core.RequestEvent, engine *templating.Engine, data map[string]interface{}) error {
|
||||
err := p.SetCommonData(e.App, data)
|
||||
if err != nil {
|
||||
return engine.Response404(e, err, data)
|
||||
@@ -80,17 +65,17 @@ func (p *DefaultPage) Get(e *core.RequestEvent, engine *templating.Engine, data
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
}
|
||||
|
||||
func (p *DefaultPage) SetCommonData(app core.App, data map[string]interface{}) error {
|
||||
func (p *DefaultPage[T]) SetCommonData(app core.App, data map[string]interface{}) error {
|
||||
record, err := p.GetLatestData(app)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.SetProxyRecord(record)
|
||||
data["page"] = p
|
||||
p.Record.SetProxyRecord(record)
|
||||
data["page"] = p.Record
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DefaultPage) GetLatestData(app core.App) (*core.Record, error) {
|
||||
func (p *DefaultPage[T]) GetLatestData(app core.App) (*core.Record, error) {
|
||||
record := &core.Record{}
|
||||
tn := GeneratePageTableName(p.Name)
|
||||
err := app.RecordQuery(tn).OrderBy("created").Limit(1).One(record)
|
||||
|
||||
44
pagemodels/defaultrecord.go
Normal file
44
pagemodels/defaultrecord.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package pagemodels
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
)
|
||||
|
||||
type DefaultPageRecord struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
|
||||
func NewDefaultPageRecord(record *core.Record) *DefaultPageRecord {
|
||||
i := &DefaultPageRecord{}
|
||||
i.SetProxyRecord(record)
|
||||
return i
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) Title() string {
|
||||
return r.GetString(F_TITLE)
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) SetTitle(titel string) {
|
||||
r.Set(F_TITLE, titel)
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) Description() string {
|
||||
return r.GetString(F_DESCRIPTION)
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) SetDescription(beschreibung string) {
|
||||
r.Set(F_DESCRIPTION, beschreibung)
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) Keywords() string {
|
||||
return r.GetString(F_TAGS)
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) SetKeywords(keywords string) {
|
||||
r.Set(F_TAGS, keywords)
|
||||
}
|
||||
|
||||
func (r *DefaultPageRecord) Collection(pagename string) *core.Collection {
|
||||
coll := BasePageCollection(pagename)
|
||||
return coll
|
||||
}
|
||||
@@ -88,3 +88,13 @@ func (t *IndexTexte) Abs2() string {
|
||||
func (t *IndexTexte) SetAbs2(abs2 string) {
|
||||
t.Set(F_INDEX_TEXTE_ABS2, abs2)
|
||||
}
|
||||
|
||||
func (t *IndexTexte) Collection(pagename string) *core.Collection {
|
||||
coll := BasePageCollection(pagename)
|
||||
coll.Fields = append(coll.Fields, StandardPageFields()...)
|
||||
coll.Fields = append(coll.Fields, core.NewFieldsList(
|
||||
EditorField(F_INDEX_TEXTE_ABS1),
|
||||
EditorField(F_INDEX_TEXTE_ABS2),
|
||||
)...)
|
||||
return coll
|
||||
}
|
||||
|
||||
8
pagemodels/pagecollection.go
Normal file
8
pagemodels/pagecollection.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package pagemodels
|
||||
|
||||
import "github.com/pocketbase/pocketbase/core"
|
||||
|
||||
type IPageCollection interface {
|
||||
core.RecordProxy
|
||||
Collection(pagename string) *core.Collection
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package pagemodels
|
||||
const (
|
||||
P_DATENSCHUTZ_NAME = "datenschutz"
|
||||
|
||||
P_SUCHE_NAME = "suche"
|
||||
|
||||
P_INDEX_NAME = "index"
|
||||
T_INDEX_BILDER = "bilder"
|
||||
T_INDEX_TEXTE = "texte"
|
||||
|
||||
Reference in New Issue
Block a user