mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 01:05:32 +00:00
Bilder & Vorschau / Tabellen für die Satrtseite
This commit is contained in:
7
pagemodels/common.go
Normal file
7
pagemodels/common.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package pagemodels
|
||||
|
||||
const PAGE_DB_PREFIX = "page_"
|
||||
|
||||
func GeneratePageTableName(pagename, tablename string) string {
|
||||
return PAGE_DB_PREFIX + pagename + "_" + tablename
|
||||
}
|
||||
105
pagemodels/index.go
Normal file
105
pagemodels/index.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package pagemodels
|
||||
|
||||
import (
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/filesystem"
|
||||
)
|
||||
|
||||
const (
|
||||
P_INDEX_NAME = "index"
|
||||
T_INDEX_BILDER = "bilder"
|
||||
T_INDEX_TEXTE = "texte"
|
||||
|
||||
F_INDEX_BILDER_TITEL = "Titel"
|
||||
F_INDEX_BILDER_BESCHREIBUNG = "Beschreibung"
|
||||
F_INDEX_BILDER_BILD = "Bild"
|
||||
F_INDEX_BILDER_VORSCHAU = "Vorschau"
|
||||
|
||||
F_INDEX_TEXTE_TITEL = "Titel"
|
||||
F_INDEX_TEXTE_ABS1 = "Abs1"
|
||||
F_INDEX_TEXTE_ABS2 = "Abs2"
|
||||
)
|
||||
|
||||
type IndexBilder struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
|
||||
func (b *IndexBilder) TableName() string {
|
||||
return GeneratePageTableName(P_INDEX_NAME, T_INDEX_BILDER)
|
||||
}
|
||||
|
||||
func NewIndexBilder(record *core.Record) *IndexBilder {
|
||||
i := &IndexBilder{}
|
||||
i.SetProxyRecord(record)
|
||||
return i
|
||||
}
|
||||
|
||||
func (b *IndexBilder) Titel() string {
|
||||
return b.GetString(F_INDEX_BILDER_TITEL)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) SetTitel(titel string) {
|
||||
b.Set(F_INDEX_BILDER_TITEL, titel)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) Beschreibung() string {
|
||||
return b.GetString(F_INDEX_BILDER_BESCHREIBUNG)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) SetBeschreibung(beschreibung string) {
|
||||
b.Set(F_INDEX_BILDER_BESCHREIBUNG, beschreibung)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) Bild() string {
|
||||
return b.GetString(F_INDEX_BILDER_BILD)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) SetBild(bild *filesystem.File) {
|
||||
b.Set(F_INDEX_BILDER_BILD, bild)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) Vorschau() string {
|
||||
return b.GetString(F_INDEX_BILDER_VORSCHAU)
|
||||
}
|
||||
|
||||
func (b *IndexBilder) SetVorschau(vorschau *filesystem.File) {
|
||||
b.Set(F_INDEX_BILDER_VORSCHAU, vorschau)
|
||||
}
|
||||
|
||||
type IndexTexte struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
|
||||
func (t *IndexTexte) TableName() string {
|
||||
return GeneratePageTableName(P_INDEX_NAME, T_INDEX_TEXTE)
|
||||
}
|
||||
|
||||
func NewIndexTexte(record *core.Record) *IndexTexte {
|
||||
i := &IndexTexte{}
|
||||
i.SetProxyRecord(record)
|
||||
return i
|
||||
}
|
||||
|
||||
func (t *IndexTexte) Titel() string {
|
||||
return t.GetString(F_INDEX_TEXTE_TITEL)
|
||||
}
|
||||
|
||||
func (t *IndexTexte) SetTitel(titel string) {
|
||||
t.Set(F_INDEX_TEXTE_TITEL, titel)
|
||||
}
|
||||
|
||||
func (t *IndexTexte) Abs1() string {
|
||||
return t.GetString(F_INDEX_TEXTE_ABS1)
|
||||
}
|
||||
|
||||
func (t *IndexTexte) SetAbs1(abs1 string) {
|
||||
t.Set(F_INDEX_TEXTE_ABS1, abs1)
|
||||
}
|
||||
|
||||
func (t *IndexTexte) Abs2() string {
|
||||
return t.GetString(F_INDEX_TEXTE_ABS2)
|
||||
}
|
||||
|
||||
func (t *IndexTexte) SetAbs2(abs2 string) {
|
||||
t.Set(F_INDEX_TEXTE_ABS2, abs2)
|
||||
}
|
||||
@@ -6,10 +6,6 @@ import (
|
||||
"github.com/pocketbase/pocketbase/tools/router"
|
||||
)
|
||||
|
||||
const (
|
||||
PAGE_DB_PREFIX = "page_"
|
||||
)
|
||||
|
||||
type IPage interface {
|
||||
Up(app core.App) error
|
||||
Down(app core.App) error
|
||||
@@ -19,52 +15,5 @@ type IPage interface {
|
||||
|
||||
type Page struct {
|
||||
// WARNING: this is not thread safe, just set this once in setup
|
||||
Tables []string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (p *Page) TableExists(app core.App, name string) bool {
|
||||
coll, _ := app.FindCollectionByNameOrId(p.generateName(name))
|
||||
if coll != nil {
|
||||
p.Tables = append(p.Tables, coll.Name)
|
||||
}
|
||||
return coll != nil
|
||||
}
|
||||
|
||||
func (p *Page) CreateTable(app core.App, collection *core.Collection) error {
|
||||
collection.Name = p.generateName(collection.Name)
|
||||
err := app.Save(collection)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error creating table", "error", err, "collection", collection, "name", p.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
p.Tables = append(p.Tables, collection.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) DropTable(app core.App, name string) error {
|
||||
coll, _ := app.FindCollectionByNameOrId(p.generateName(name))
|
||||
if coll != nil {
|
||||
err := app.Delete(coll)
|
||||
if err != nil {
|
||||
app.Logger().Error("Error deleting table", "error", err, "collection", coll, "name", p.Name)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) DropTables(app core.App) error {
|
||||
for _, table := range p.Tables {
|
||||
err := p.DropTable(app, table)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Page) generateName(name string) string {
|
||||
return PAGE_DB_PREFIX + p.Name + "_" + name
|
||||
Name string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user