mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2026-02-04 02:25:30 +00:00
+ make IApp available in the controllers
This commit is contained in:
172
app/pb.go
172
app/pb.go
@@ -3,6 +3,9 @@ package app
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/dbmodels"
|
||||||
@@ -30,9 +33,9 @@ type App struct {
|
|||||||
PB *pocketbase.PocketBase
|
PB *pocketbase.PocketBase
|
||||||
MAConfig Config
|
MAConfig Config
|
||||||
Pages []pagemodels.IPage
|
Pages []pagemodels.IPage
|
||||||
dataCache map[string]any
|
dataCache *PrefixCache
|
||||||
dataMutex sync.RWMutex
|
dataMutex sync.RWMutex
|
||||||
htmlCache map[string]any
|
htmlCache *PrefixCache
|
||||||
htmlMutex sync.RWMutex
|
htmlMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +66,7 @@ func init() {
|
|||||||
dbx.BuilderFuncMap["pb_sqlite3"] = dbx.BuilderFuncMap["sqlite3"]
|
dbx.BuilderFuncMap["pb_sqlite3"] = dbx.BuilderFuncMap["sqlite3"]
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config Config) App {
|
func New(config Config) *App {
|
||||||
app := App{
|
app := App{
|
||||||
MAConfig: config,
|
MAConfig: config,
|
||||||
}
|
}
|
||||||
@@ -71,7 +74,7 @@ func New(config Config) App {
|
|||||||
app.createPBInstance()
|
app.createPBInstance()
|
||||||
app.Bootstrap()
|
app.Bootstrap()
|
||||||
|
|
||||||
return app
|
return &app
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) createPBInstance() {
|
func (app *App) createPBInstance() {
|
||||||
@@ -142,6 +145,10 @@ func (app *App) Serve() error {
|
|||||||
return app.PB.Start()
|
return app.PB.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *App) Logger() *slog.Logger {
|
||||||
|
return app.PB.Logger()
|
||||||
|
}
|
||||||
|
|
||||||
func (app *App) createEngine() (*templating.Engine, error) {
|
func (app *App) createEngine() (*templating.Engine, error) {
|
||||||
engine := templating.NewEngine(&views.LayoutFS, &views.RoutesFS)
|
engine := templating.NewEngine(&views.LayoutFS, &views.RoutesFS)
|
||||||
engine.Globals(map[string]interface{}{
|
engine.Globals(map[string]interface{}{
|
||||||
@@ -155,56 +162,149 @@ func (app *App) createEngine() (*templating.Engine, error) {
|
|||||||
|
|
||||||
app.ResetDataCache()
|
app.ResetDataCache()
|
||||||
engine.AddFunc("data", func(key string) any {
|
engine.AddFunc("data", func(key string) any {
|
||||||
if len(app.dataCache) == 0 {
|
app.ensureDataCache()
|
||||||
data, err := dbmodels.Data_All(app.PB.App)
|
|
||||||
if err != nil {
|
|
||||||
app.PB.Logger().Error("Failed to fetch data cache: %v", err)
|
|
||||||
return "{}"
|
|
||||||
}
|
|
||||||
app.dataMutex.Lock()
|
|
||||||
for _, d := range data {
|
|
||||||
app.dataCache[d.Key()] = d.Value()
|
|
||||||
}
|
|
||||||
app.dataMutex.Unlock()
|
|
||||||
}
|
|
||||||
app.dataMutex.RLock()
|
app.dataMutex.RLock()
|
||||||
defer app.dataMutex.RUnlock()
|
defer app.dataMutex.RUnlock()
|
||||||
return app.dataCache[key]
|
return app.dataCache.Get(key)
|
||||||
|
})
|
||||||
|
engine.AddFunc("dataPrefix", func(prefix string) map[string]any {
|
||||||
|
app.ensureDataCache()
|
||||||
|
app.dataMutex.RLock()
|
||||||
|
defer app.dataMutex.RUnlock()
|
||||||
|
return app.dataCache.GetPrefix(prefix)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.ResetHtmlCache()
|
app.ResetHtmlCache()
|
||||||
engine.AddFunc("html", func(key string) any {
|
engine.AddFunc("html", func(key string) any {
|
||||||
if len(app.htmlCache) == 0 {
|
app.ensureHtmlCache()
|
||||||
html, err := dbmodels.Html_All(app.PB.App)
|
|
||||||
if err != nil {
|
|
||||||
app.PB.Logger().Error("Failed to fetch html cache: %v", err)
|
|
||||||
return "{}"
|
|
||||||
}
|
|
||||||
app.htmlMutex.Lock()
|
|
||||||
for _, h := range html {
|
|
||||||
app.htmlCache[h.Key()] = h.HTML()
|
|
||||||
}
|
|
||||||
app.htmlMutex.Unlock()
|
|
||||||
}
|
|
||||||
app.htmlMutex.RLock()
|
app.htmlMutex.RLock()
|
||||||
defer app.htmlMutex.RUnlock()
|
defer app.htmlMutex.RUnlock()
|
||||||
return app.htmlCache[key]
|
return app.htmlCache.Get(key)
|
||||||
|
})
|
||||||
|
engine.AddFunc("htmlPrefix", func(prefix string) map[string]any {
|
||||||
|
app.ensureHtmlCache()
|
||||||
|
app.htmlMutex.RLock()
|
||||||
|
defer app.htmlMutex.RUnlock()
|
||||||
|
return app.htmlCache.GetPrefix(prefix)
|
||||||
})
|
})
|
||||||
|
|
||||||
return engine, nil
|
return engine, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUG: we cant call this from the templates, bc this App struct is not available
|
// Core returns the underlying pocketbase core.App
|
||||||
|
func (app *App) Core() core.App {
|
||||||
|
return app.PB.App
|
||||||
|
}
|
||||||
|
|
||||||
func (app *App) ResetDataCache() {
|
func (app *App) ResetDataCache() {
|
||||||
app.dataMutex.Lock()
|
app.dataMutex.Lock()
|
||||||
defer app.dataMutex.Unlock()
|
defer app.dataMutex.Unlock()
|
||||||
app.dataCache = make(map[string]any)
|
app.dataCache = NewPrefixCache()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) ResetHtmlCache() {
|
func (app *App) ResetHtmlCache() {
|
||||||
app.htmlMutex.Lock()
|
app.htmlMutex.Lock()
|
||||||
defer app.htmlMutex.Unlock()
|
defer app.htmlMutex.Unlock()
|
||||||
app.htmlCache = make(map[string]any)
|
app.htmlCache = NewPrefixCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
type PrefixCache struct {
|
||||||
|
data map[string]any
|
||||||
|
keys []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPrefixCache() *PrefixCache {
|
||||||
|
return &PrefixCache{
|
||||||
|
data: make(map[string]any),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PrefixCache) Get(key string) any {
|
||||||
|
if c == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return c.data[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *PrefixCache) GetPrefix(prefix string) map[string]any {
|
||||||
|
if c == nil || len(c.keys) == 0 {
|
||||||
|
return map[string]any{}
|
||||||
|
}
|
||||||
|
|
||||||
|
start := sort.Search(len(c.keys), func(i int) bool {
|
||||||
|
return c.keys[i] >= prefix
|
||||||
|
})
|
||||||
|
|
||||||
|
matches := make(map[string]any)
|
||||||
|
for i := start; i < len(c.keys); i++ {
|
||||||
|
key := c.keys[i]
|
||||||
|
if !strings.HasPrefix(key, prefix) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
matches[key] = c.data[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) ensureDataCache() {
|
||||||
|
app.dataMutex.RLock()
|
||||||
|
if app.dataCache != nil && len(app.dataCache.data) > 0 {
|
||||||
|
app.dataMutex.RUnlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.dataMutex.RUnlock()
|
||||||
|
|
||||||
|
data, err := dbmodels.Data_All(app.PB.App)
|
||||||
|
if err != nil {
|
||||||
|
app.PB.Logger().Error("Failed to fetch data cache: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cache := NewPrefixCache()
|
||||||
|
cache.keys = make([]string, 0, len(data))
|
||||||
|
for _, d := range data {
|
||||||
|
key := d.Key()
|
||||||
|
cache.data[key] = d.Value()
|
||||||
|
cache.keys = append(cache.keys, key)
|
||||||
|
}
|
||||||
|
sort.Strings(cache.keys)
|
||||||
|
|
||||||
|
app.dataMutex.Lock()
|
||||||
|
if app.dataCache == nil || len(app.dataCache.data) == 0 {
|
||||||
|
app.dataCache = cache
|
||||||
|
}
|
||||||
|
app.dataMutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) ensureHtmlCache() {
|
||||||
|
app.htmlMutex.RLock()
|
||||||
|
if app.htmlCache != nil && len(app.htmlCache.data) > 0 {
|
||||||
|
app.htmlMutex.RUnlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.htmlMutex.RUnlock()
|
||||||
|
|
||||||
|
html, err := dbmodels.Html_All(app.PB.App)
|
||||||
|
if err != nil {
|
||||||
|
app.PB.Logger().Error("Failed to fetch html cache: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cache := NewPrefixCache()
|
||||||
|
cache.keys = make([]string, 0, len(html))
|
||||||
|
for _, h := range html {
|
||||||
|
key := h.Key()
|
||||||
|
cache.data[key] = h.HTML()
|
||||||
|
cache.keys = append(cache.keys, key)
|
||||||
|
}
|
||||||
|
sort.Strings(cache.keys)
|
||||||
|
|
||||||
|
app.htmlMutex.Lock()
|
||||||
|
if app.htmlCache == nil || len(app.htmlCache.data) == 0 {
|
||||||
|
app.htmlCache = cache
|
||||||
|
}
|
||||||
|
app.htmlMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) setWatchers(engine *templating.Engine) {
|
func (app *App) setWatchers(engine *templating.Engine) {
|
||||||
@@ -234,17 +334,17 @@ func (app *App) bindPages(engine *templating.Engine) ServeFunc {
|
|||||||
|
|
||||||
// INFO: we put this here, to make sure all migrations are done
|
// INFO: we put this here, to make sure all migrations are done
|
||||||
for _, page := range pages {
|
for _, page := range pages {
|
||||||
err := page.Up(e.App, engine)
|
err := page.Up(app, engine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.PB.Logger().Error("Failed to up page %q: %v", "error", err)
|
app.PB.Logger().Error("Failed to up page %q: %v", "error", err)
|
||||||
page.Down(e.App, engine)
|
page.Down(app, engine)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
app.Pages = append(app.Pages, page)
|
app.Pages = append(app.Pages, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, page := range app.Pages {
|
for _, page := range app.Pages {
|
||||||
page.Setup(e.Router, e.App, engine)
|
page.Setup(e.Router, app, engine)
|
||||||
}
|
}
|
||||||
|
|
||||||
return e.Next()
|
return e.Next()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ type ErrorPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ErrorPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *ErrorPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
router.GET(URL_ERROR_404, func(e *core.RequestEvent) error {
|
router.GET(URL_ERROR_404, func(e *core.RequestEvent) error {
|
||||||
return engine.Response404(e, nil, nil)
|
return engine.Response404(e, nil, nil)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -49,12 +49,13 @@ type AbkuerzungenResult struct {
|
|||||||
Entries []AbkEntry
|
Entries []AbkEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AbkuerzungenPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *AbkuerzungenPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_ABKUERZUNGEN, p.GET(engine, app))
|
router.GET(URL_ABKUERZUNGEN, p.GET(engine, app))
|
||||||
|
|
||||||
rg := router.Group(URL_ABKUERZUNGEN)
|
rg := router.Group(URL_ABKUERZUNGEN)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.POST("", p.POST(engine, app))
|
rg.POST("", p.POST(engine, ia))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -123,8 +124,9 @@ type abkFormEntry struct {
|
|||||||
Delete string `form:"_delete"`
|
Delete string `form:"_delete"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AbkuerzungenPage) POST(engine *templating.Engine, app core.App) HandleFunc {
|
func (p *AbkuerzungenPage) POST(engine *templating.Engine, ia pagemodels.IApp) HandleFunc {
|
||||||
return func(e *core.RequestEvent) error {
|
return func(e *core.RequestEvent) error {
|
||||||
|
app := ia.Core()
|
||||||
req := templating.NewRequest(e)
|
req := templating.NewRequest(e)
|
||||||
|
|
||||||
// Parse form manually to handle array syntax
|
// Parse form manually to handle array syntax
|
||||||
@@ -198,6 +200,8 @@ func (p *AbkuerzungenPage) POST(engine *templating.Engine, app core.App) HandleF
|
|||||||
return p.redirectError(e, "Speichern fehlgeschlagen.")
|
return p.redirectError(e, "Speichern fehlgeschlagen.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go ia.ResetDataCache()
|
||||||
|
|
||||||
// Redirect with success message
|
// Redirect with success message
|
||||||
redirect := fmt.Sprintf("%s?success=%s", URL_ABKUERZUNGEN, url.QueryEscape("Änderungen gespeichert."))
|
redirect := fmt.Sprintf("%s?success=%s", URL_ABKUERZUNGEN, url.QueryEscape("Änderungen gespeichert."))
|
||||||
return e.Redirect(http.StatusSeeOther, redirect)
|
return e.Redirect(http.StatusSeeOther, redirect)
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ type AlmanachPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *AlmanachPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(p.URL, p.GET(engine, app))
|
router.GET(p.URL, p.GET(engine, app))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ type AlmanachEditPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlmanachEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *AlmanachEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_ALMANACH)
|
rg := router.Group(URL_ALMANACH)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET(URL_ALMANACH_EDIT, p.GET(engine, app))
|
rg.GET(URL_ALMANACH_EDIT, p.GET(engine, app))
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ type AlmanachNewPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlmanachNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *AlmanachNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_ALMANACH_NEW)
|
rg := router.Group(URL_ALMANACH_NEW)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET("", p.GET(engine, app))
|
rg.GET("", p.GET(engine, app))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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/middleware"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||||
|
"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"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
@@ -24,15 +25,16 @@ func init() {
|
|||||||
|
|
||||||
type AgentsAPI struct{}
|
type AgentsAPI struct{}
|
||||||
|
|
||||||
func (p *AgentsAPI) Up(app core.App, engine *templating.Engine) error {
|
func (p *AgentsAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AgentsAPI) Down(app core.App, engine *templating.Engine) error {
|
func (p *AgentsAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *AgentsAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *AgentsAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_API_AGENTS)
|
rg := router.Group(URL_API_AGENTS)
|
||||||
rg.BindFunc(middleware.Authenticated(app))
|
rg.BindFunc(middleware.Authenticated(app))
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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/middleware"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||||
|
"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"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
@@ -24,15 +25,16 @@ func init() {
|
|||||||
|
|
||||||
type EntriesAPI struct{}
|
type EntriesAPI struct{}
|
||||||
|
|
||||||
func (p *EntriesAPI) Up(app core.App, engine *templating.Engine) error {
|
func (p *EntriesAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EntriesAPI) Down(app core.App, engine *templating.Engine) error {
|
func (p *EntriesAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EntriesAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *EntriesAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_API_ENTRIES)
|
rg := router.Group(URL_API_ENTRIES)
|
||||||
rg.BindFunc(middleware.Authenticated(app))
|
rg.BindFunc(middleware.Authenticated(app))
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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/middleware"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||||
|
"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"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
@@ -24,15 +25,16 @@ func init() {
|
|||||||
|
|
||||||
type PlacesAPI struct{}
|
type PlacesAPI struct{}
|
||||||
|
|
||||||
func (p *PlacesAPI) Up(app core.App, engine *templating.Engine) error {
|
func (p *PlacesAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlacesAPI) Down(app core.App, engine *templating.Engine) error {
|
func (p *PlacesAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlacesAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *PlacesAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_API_PLACES)
|
rg := router.Group(URL_API_PLACES)
|
||||||
rg.BindFunc(middleware.Authenticated(app))
|
rg.BindFunc(middleware.Authenticated(app))
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ 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/middleware"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/middleware"
|
||||||
|
"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"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
@@ -24,15 +25,16 @@ func init() {
|
|||||||
|
|
||||||
type SeriesAPI struct{}
|
type SeriesAPI struct{}
|
||||||
|
|
||||||
func (p *SeriesAPI) Up(app core.App, engine *templating.Engine) error {
|
func (p *SeriesAPI) Up(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SeriesAPI) Down(app core.App, engine *templating.Engine) error {
|
func (p *SeriesAPI) Down(ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SeriesAPI) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *SeriesAPI) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_API_SERIES)
|
rg := router.Group(URL_API_SERIES)
|
||||||
rg.BindFunc(middleware.Authenticated(app))
|
rg.BindFunc(middleware.Authenticated(app))
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ type BeitragPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *BeitragPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *BeitragPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||||
id := e.Request.PathValue("id")
|
id := e.Request.PathValue("id")
|
||||||
data := make(map[string]any)
|
data := make(map[string]any)
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ type IndexPage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
func (p *IndexPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *IndexPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET("/{$}", func(e *core.RequestEvent) error {
|
router.GET("/{$}", func(e *core.RequestEvent) error {
|
||||||
bilder := []*pagemodels.IndexBilder{}
|
bilder := []*pagemodels.IndexBilder{}
|
||||||
err := app.RecordQuery(pagemodels.GeneratePageTableName(pagemodels.P_INDEX_NAME, pagemodels.T_INDEX_BILDER)).
|
err := app.RecordQuery(pagemodels.GeneratePageTableName(pagemodels.P_INDEX_NAME, pagemodels.T_INDEX_BILDER)).
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ type LoginPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *LoginPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *LoginPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_LOGIN, p.GET(engine, app))
|
router.GET(URL_LOGIN, p.GET(engine, app))
|
||||||
r := router.POST(URL_LOGIN, p.POST(engine, app))
|
r := router.POST(URL_LOGIN, p.POST(engine, app))
|
||||||
r.BindFunc(middleware.RateLimiter(30, time.Minute*2, time.Hour*6))
|
r.BindFunc(middleware.RateLimiter(30, time.Minute*2, time.Hour*6))
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ type LogoutPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *LogoutPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *LogoutPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(p.URL, p.GET(app))
|
router.GET(p.URL, p.GET(app))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ type OrtEditPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrtEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *OrtEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_ORT)
|
rg := router.Group(URL_ORT)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET(URL_ORT_EDIT, p.GET(engine, app))
|
rg.GET(URL_ORT_EDIT, p.GET(engine, app))
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ type OrtNewPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrtNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *OrtNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_ORTE_NEW)
|
rg := router.Group(URL_ORTE_NEW)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET("", p.GET(engine, app))
|
rg.GET("", p.GET(engine, app))
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ type OrteResult struct {
|
|||||||
Places []*dbmodels.Place
|
Places []*dbmodels.Place
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *OrtePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *OrtePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_ORTE, func(e *core.RequestEvent) error {
|
router.GET(URL_ORTE, func(e *core.RequestEvent) error {
|
||||||
places := []*dbmodels.Place{}
|
places := []*dbmodels.Place{}
|
||||||
if err := app.RecordQuery(dbmodels.PLACES_TABLE).All(&places); err != nil {
|
if err := app.RecordQuery(dbmodels.PLACES_TABLE).All(&places); err != nil {
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ type PersonPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *PersonPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_PERSON, func(e *core.RequestEvent) error {
|
router.GET(URL_PERSON, func(e *core.RequestEvent) error {
|
||||||
person := e.Request.PathValue("id")
|
person := e.Request.PathValue("id")
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ type PersonEditPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersonEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *PersonEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group("/person/{id}/")
|
rg := router.Group("/person/{id}/")
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET(URL_PERSON_EDIT, p.GET(engine, app))
|
rg.GET(URL_PERSON_EDIT, p.GET(engine, app))
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ type PersonNewPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersonNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *PersonNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_PERSONEN_NEW)
|
rg := router.Group(URL_PERSONEN_NEW)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET("", p.GET(engine, app))
|
rg.GET("", p.GET(engine, app))
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ type PersonenPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PersonenPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *PersonenPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_PERSONEN, func(e *core.RequestEvent) error {
|
router.GET(URL_PERSONEN, func(e *core.RequestEvent) error {
|
||||||
if e.Request.URL.Query().Get(PARAM_SEARCH) != "" {
|
if e.Request.URL.Query().Get(PARAM_SEARCH) != "" {
|
||||||
return p.SearchRequest(app, engine, e)
|
return p.SearchRequest(app, engine, e)
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ type ReihePage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: data richtig seutzen, damit die Reihe mit dem template _reihe angezeigt wird
|
// TODO: data richtig seutzen, damit die Reihe mit dem template _reihe angezeigt wird
|
||||||
func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *ReihePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_REIHE, func(e *core.RequestEvent) error {
|
router.GET(URL_REIHE, 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{})
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ type ReiheEditPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReiheEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *ReiheEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_REIHE)
|
rg := router.Group(URL_REIHE)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET(URL_REIHE_EDIT, p.GET(engine, app))
|
rg.GET(URL_REIHE_EDIT, p.GET(engine, app))
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ type ReiheNewPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReiheNewPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *ReiheNewPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_REIHEN_NEW)
|
rg := router.Group(URL_REIHEN_NEW)
|
||||||
rg.BindFunc(middleware.IsAdminOrEditor())
|
rg.BindFunc(middleware.IsAdminOrEditor())
|
||||||
rg.GET("", p.GET(engine, app))
|
rg.GET("", p.GET(engine, app))
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ type ReihenPage struct {
|
|||||||
pagemodels.DefaultPage[*pagemodels.DefaultPageRecord]
|
pagemodels.DefaultPage[*pagemodels.DefaultPageRecord]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReihenPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *ReihenPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_REIHEN, func(e *core.RequestEvent) error {
|
router.GET(URL_REIHEN, func(e *core.RequestEvent) error {
|
||||||
search := e.Request.URL.Query().Get(PARAM_SEARCH)
|
search := e.Request.URL.Query().Get(PARAM_SEARCH)
|
||||||
if search != "" {
|
if search != "" {
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ func init() {
|
|||||||
app.Register(rp)
|
app.Register(rp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SuchePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *SuchePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(URL_SUCHE_ALT, func(e *core.RequestEvent) error {
|
router.GET(URL_SUCHE_ALT, func(e *core.RequestEvent) error {
|
||||||
return e.Redirect(http.StatusPermanentRedirect, DEFAULT_SUCHE)
|
return e.Redirect(http.StatusPermanentRedirect, DEFAULT_SUCHE)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ type UserCreatePage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *UserCreatePage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *UserCreatePage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_USER_CREATE)
|
rg := router.Group(URL_USER_CREATE)
|
||||||
rg.BindFunc(middleware.HasToken())
|
rg.BindFunc(middleware.HasToken())
|
||||||
rg.GET("{"+PATH_VALUE_ROLE+"}", p.GET(engine, app))
|
rg.GET("{"+PATH_VALUE_ROLE+"}", p.GET(engine, app))
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ type UserEditPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *UserEditPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *UserEditPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_USER)
|
rg := router.Group(URL_USER)
|
||||||
rg.BindFunc(middleware.IsAdminOrUser())
|
rg.BindFunc(middleware.IsAdminOrUser())
|
||||||
rg.GET(URL_USER_EDIT, p.GET(engine, app))
|
rg.GET(URL_USER_EDIT, p.GET(engine, app))
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ type UserManagementPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *UserManagementPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *UserManagementPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_USER_MANAGEMENT)
|
rg := router.Group(URL_USER_MANAGEMENT)
|
||||||
rg.BindFunc(middleware.IsAdmin())
|
rg.BindFunc(middleware.IsAdmin())
|
||||||
rg.GET("", p.GET(engine, app))
|
rg.GET("", p.GET(engine, app))
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ type UserManagementAccessPage struct {
|
|||||||
pagemodels.StaticPage
|
pagemodels.StaticPage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *UserManagementAccessPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *UserManagementAccessPage) Setup(router *router.Router[*core.RequestEvent], ia pagemodels.IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
rg := router.Group(URL_USER_MANAGEMENT_ACCESS)
|
rg := router.Group(URL_USER_MANAGEMENT_ACCESS)
|
||||||
rg.BindFunc(middleware.IsAdmin())
|
rg.BindFunc(middleware.IsAdmin())
|
||||||
rg.GET("{"+PATH_VALUE_ROLE+"}", p.GET(engine, app))
|
rg.GET("{"+PATH_VALUE_ROLE+"}", p.GET(engine, app))
|
||||||
|
|||||||
@@ -16,33 +16,33 @@ type DefaultPage[T IPageCollection] struct {
|
|||||||
URL string
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *DefaultPage[T]) Up(app core.App, engine *templating.Engine) error {
|
func (r *DefaultPage[T]) Up(app IApp, engine *templating.Engine) error {
|
||||||
_, err := app.FindCollectionByNameOrId(GeneratePageTableName(r.Name))
|
_, err := app.Core().FindCollectionByNameOrId(GeneratePageTableName(r.Name))
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
collection := r.Record.Collection(r.Name)
|
collection := r.Record.Collection(r.Name)
|
||||||
err = app.Save(collection)
|
err = app.Core().Save(collection)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Logger().Error("Error saving collection", "Name", GeneratePageTableName(r.Name), "Error", err, "Collection", collection)
|
app.Core().Logger().Error("Error saving collection", "Name", GeneratePageTableName(r.Name), "Error", err, "Collection", collection)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
app.Logger().Error("Error finding collection %s: %s", GeneratePageTableName(r.Name), err)
|
app.Core().Logger().Error("Error finding collection %s: %s", GeneratePageTableName(r.Name), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *DefaultPage[T]) Down(app core.App, engine *templating.Engine) error {
|
func (r *DefaultPage[T]) Down(app IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *DefaultPage[T]) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *DefaultPage[T]) Setup(router *router.Router[*core.RequestEvent], app IApp, engine *templating.Engine) error {
|
||||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
|
|
||||||
record := &core.Record{}
|
record := &core.Record{}
|
||||||
err := app.RecordQuery(GeneratePageTableName(p.Name)).
|
err := app.Core().RecordQuery(GeneratePageTableName(p.Name)).
|
||||||
OrderBy("created").
|
OrderBy("created").
|
||||||
One(record)
|
One(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,11 +4,18 @@ import (
|
|||||||
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
"github.com/Theodor-Springmann-Stiftung/musenalm/templating"
|
||||||
"github.com/pocketbase/pocketbase/core"
|
"github.com/pocketbase/pocketbase/core"
|
||||||
"github.com/pocketbase/pocketbase/tools/router"
|
"github.com/pocketbase/pocketbase/tools/router"
|
||||||
|
"log/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IPage interface {
|
type IApp interface {
|
||||||
Up(app core.App, engine *templating.Engine) error
|
Core() core.App
|
||||||
Down(app core.App, engine *templating.Engine) error
|
ResetDataCache()
|
||||||
// TODO: pass the cache here
|
ResetHtmlCache()
|
||||||
Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error
|
Logger() *slog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
type IPage interface {
|
||||||
|
Up(app IApp, engine *templating.Engine) error
|
||||||
|
Down(app IApp, engine *templating.Engine) error
|
||||||
|
Setup(router *router.Router[*core.RequestEvent], app IApp, engine *templating.Engine) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ type StaticPage struct {
|
|||||||
URL string
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], ia IApp, engine *templating.Engine) error {
|
||||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
data["record"] = p
|
data["record"] = p
|
||||||
@@ -22,10 +22,10 @@ func (p *StaticPage) Setup(router *router.Router[*core.RequestEvent], app core.A
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *StaticPage) Up(app core.App, engine *templating.Engine) error {
|
func (p *StaticPage) Up(ia IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *StaticPage) Down(app core.App, engine *templating.Engine) error {
|
func (p *StaticPage) Down(ia IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,15 +52,16 @@ func (r *TextPage) SetText(text string) {
|
|||||||
r.Set(F_TEXT, text)
|
r.Set(F_TEXT, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *TextPage) Up(app core.App, engine *templating.Engine) error {
|
func (r *TextPage) Up(ia IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *TextPage) Down(app core.App, engine *templating.Engine) error {
|
func (r *TextPage) Down(ia IApp, engine *templating.Engine) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *TextPage) Setup(router *router.Router[*core.RequestEvent], app core.App, engine *templating.Engine) error {
|
func (p *TextPage) Setup(router *router.Router[*core.RequestEvent], ia IApp, engine *templating.Engine) error {
|
||||||
|
app := ia.Core()
|
||||||
router.GET(p.URL, func(e *core.RequestEvent) error {
|
router.GET(p.URL, func(e *core.RequestEvent) error {
|
||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,7 @@
|
|||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
{{- range $_, $rca := $rcas -}}
|
{{- range $_, $rca := $rcas -}}
|
||||||
{{- $agent := index $agents $rca.Agent -}}
|
{{- $agent := index $agents $rca.Agent -}}
|
||||||
<div class="font-sans text-base bg-stone-100 px-1 py-0.5 rounded w-max">
|
<div class="font-sans w-max">
|
||||||
<a
|
<a
|
||||||
href="/person/{{- $agent.Id -}}"
|
href="/person/{{- $agent.Id -}}"
|
||||||
class="inline-block {{ if $isPerson }}search-text{{ end }}">
|
class="inline-block {{ if $isPerson }}search-text{{ end }}">
|
||||||
|
|||||||
Reference in New Issue
Block a user