mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 01:05:32 +00:00
Slight page refactoring, text pages, tooltips
This commit is contained in:
@@ -8,8 +8,10 @@ import (
|
||||
|
||||
type DefaultPage struct {
|
||||
core.BaseRecordProxy
|
||||
Page
|
||||
URL string
|
||||
Name string
|
||||
Template string
|
||||
Layout string
|
||||
URL string
|
||||
}
|
||||
|
||||
func NewDefaultPage(record *core.Record) *DefaultPage {
|
||||
@@ -42,36 +44,55 @@ func (r *DefaultPage) SetKeywords(keywords string) {
|
||||
r.Set(F_TAGS, keywords)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Text() string {
|
||||
return r.GetString(F_TEXT)
|
||||
func (r *DefaultPage) Up(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DefaultPage) SetText(text string) {
|
||||
r.Set(F_TEXT, text)
|
||||
}
|
||||
|
||||
func (r *DefaultPage) Up(app core.App) error {
|
||||
record := &core.Record{}
|
||||
err := app.RecordQuery(GeneratePageTableName(r.Name)).
|
||||
OrderBy("created").
|
||||
One(record)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
r.SetProxyRecord(record)
|
||||
func (r *DefaultPage) 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 {
|
||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||
data := make(map[string]interface{})
|
||||
data["title"] = p.Title()
|
||||
data["description"] = p.Description()
|
||||
data["keywords"] = p.Keywords()
|
||||
data["text"] = p.Text()
|
||||
|
||||
record := &core.Record{}
|
||||
err := app.RecordQuery(GeneratePageTableName(p.Name)).
|
||||
OrderBy("created").
|
||||
One(record)
|
||||
if err != nil {
|
||||
return engine.Response404(e, err, data)
|
||||
}
|
||||
|
||||
p.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 {
|
||||
err := p.SetCommonData(e.App, data)
|
||||
if err != nil {
|
||||
return engine.Response404(e, err, data)
|
||||
}
|
||||
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
}
|
||||
|
||||
func (p *DefaultPage) 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
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *DefaultPage) GetLatestData(app core.App) (*core.Record, error) {
|
||||
record := &core.Record{}
|
||||
tn := GeneratePageTableName(p.Name)
|
||||
err := app.RecordQuery(tn).OrderBy("created").Limit(1).One(record)
|
||||
return record, err
|
||||
}
|
||||
|
||||
@@ -7,30 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type IPage interface {
|
||||
Up(app core.App) error
|
||||
Down(app core.App) error
|
||||
Up(app core.App, engine *templating.Engine) error
|
||||
Down(app core.App, engine *templating.Engine) error
|
||||
// TODO: pass the cache here
|
||||
Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
// WARNING: this is not thread safe, just set this once in setup
|
||||
Name string
|
||||
Layout string
|
||||
Template string
|
||||
}
|
||||
|
||||
func (p *Page) Up(app core.App) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) Down(app core.App) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
router.GET(p.Name, func(e *core.RequestEvent) error {
|
||||
return engine.Response200(e, p.Template, nil, p.Layout)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package pagemodels
|
||||
|
||||
const (
|
||||
P_DATENSCHUTZ_NAME = "datenschutz"
|
||||
|
||||
P_INDEX_NAME = "index"
|
||||
T_INDEX_BILDER = "bilder"
|
||||
T_INDEX_TEXTE = "texte"
|
||||
|
||||
@@ -55,6 +55,10 @@ func (r *Reihen) Image() string {
|
||||
return r.GetString(F_IMAGE)
|
||||
}
|
||||
|
||||
func (r *Reihen) ImagePath() string {
|
||||
return "/api/files/" + r.TableName() + "/" + r.Id + "/" + r.Image()
|
||||
}
|
||||
|
||||
func (r *Reihen) SetImage(image *filesystem.File) {
|
||||
r.Set(F_IMAGE, image)
|
||||
}
|
||||
|
||||
31
pagemodels/static.go
Normal file
31
pagemodels/static.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package pagemodels
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
type StaticPage struct {
|
||||
Name string
|
||||
Template string
|
||||
Layout string
|
||||
URL string
|
||||
}
|
||||
|
||||
func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||
data := map[string]interface{}{}
|
||||
data["record"] = p
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *StaticPage) Up(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *StaticPage) Down(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
106
pagemodels/textpage.go
Normal file
106
pagemodels/textpage.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package pagemodels
|
||||
|
||||
import (
|
||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
type TextPage struct {
|
||||
core.BaseRecordProxy
|
||||
Name string
|
||||
Template string
|
||||
Layout string
|
||||
URL string
|
||||
}
|
||||
|
||||
func NewTextPage(record *core.Record) *TextPage {
|
||||
i := &TextPage{}
|
||||
i.SetProxyRecord(record)
|
||||
return i
|
||||
}
|
||||
|
||||
func (r *TextPage) Title() string {
|
||||
return r.GetString(F_TITLE)
|
||||
}
|
||||
|
||||
func (r *TextPage) SetTitle(titel string) {
|
||||
r.Set(F_TITLE, titel)
|
||||
}
|
||||
|
||||
func (r *TextPage) Description() string {
|
||||
return r.GetString(F_DESCRIPTION)
|
||||
}
|
||||
|
||||
func (r *TextPage) SetDescription(beschreibung string) {
|
||||
r.Set(F_DESCRIPTION, beschreibung)
|
||||
}
|
||||
|
||||
func (r *TextPage) Keywords() string {
|
||||
return r.GetString(F_TAGS)
|
||||
}
|
||||
|
||||
func (r *TextPage) SetKeywords(keywords string) {
|
||||
r.Set(F_TAGS, keywords)
|
||||
}
|
||||
|
||||
func (r *TextPage) Text() string {
|
||||
return r.GetString(F_TEXT)
|
||||
}
|
||||
|
||||
func (r *TextPage) SetText(text string) {
|
||||
r.Set(F_TEXT, text)
|
||||
}
|
||||
|
||||
func (r *TextPage) Up(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *TextPage) Down(app core.App, engine *templating.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *TextPage) 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{})
|
||||
|
||||
record := &core.Record{}
|
||||
err := app.RecordQuery(GeneratePageTableName(p.Name)).
|
||||
OrderBy("created").
|
||||
One(record)
|
||||
if err != nil {
|
||||
return engine.Response404(e, err, data)
|
||||
}
|
||||
|
||||
p.SetProxyRecord(record)
|
||||
data["record"] = p
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *TextPage) Get(e *core.RequestEvent, data map[string]interface{}, engine *templating.Engine) error {
|
||||
err := p.SetCommonData(e.App, data)
|
||||
if err != nil {
|
||||
return engine.Response404(e, err, data)
|
||||
}
|
||||
|
||||
return engine.Response200(e, p.Template, data, p.Layout)
|
||||
}
|
||||
|
||||
func (p *TextPage) 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
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *TextPage) GetLatestData(app core.App) (*core.Record, error) {
|
||||
record := &core.Record{}
|
||||
tn := GeneratePageTableName(p.Name)
|
||||
err := app.RecordQuery(tn).OrderBy("created").Limit(1).One(record)
|
||||
return record, err
|
||||
}
|
||||
Reference in New Issue
Block a user