Skip to content

Commit

Permalink
chore: update fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
blackfyre committed Jan 31, 2025
1 parent b72af0f commit fca5017
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 335 deletions.
22 changes: 13 additions & 9 deletions handlers/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/blackfyre/wga/assets/templ/error_pages"
"github.com/blackfyre/wga/assets/templ/pages"
tmplUtils "github.com/blackfyre/wga/assets/templ/utils"
"github.com/blackfyre/wga/models"
"github.com/blackfyre/wga/utils"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
Expand Down Expand Up @@ -50,7 +49,7 @@ func registerStatic(app *pocketbase.PocketBase) {
slug := c.Request.PathValue("slug")
fullUrl := tmplUtils.AssetUrl("/pages/" + slug)

page, err := models.FindStaticPageBySlug(app.Dao(), slug)
page, err := app.FindFirstRecordByData("static_pages", "slug", slug)

if err != nil {
app.Logger().Error("Error retrieving static page", "page", slug, "error", err)
Expand All @@ -59,17 +58,22 @@ func registerStatic(app *pocketbase.PocketBase) {
}

content := pages.StaticPageDTO{
Title: page.Title,
Content: page.Content,
Url: "/pages/" + page.Slug,
Title: page.GetString("title"),
Content: page.GetString("content"),
Url: "/pages/" + page.GetString("slug"),
}

ctx := tmplUtils.DecorateContext(context.Background(), tmplUtils.TitleKey, page.Title)
ctx = tmplUtils.DecorateContext(ctx, tmplUtils.DescriptionKey, page.Content)
ctx := tmplUtils.DecorateContext(context.Background(), tmplUtils.TitleKey, page.GetString("title"))
ctx = tmplUtils.DecorateContext(ctx, tmplUtils.DescriptionKey, page.GetString("content"))
ctx = tmplUtils.DecorateContext(ctx, tmplUtils.CanonicalUrlKey, fullUrl)

c.Response().Header().Set("HX-Push-Url", fullUrl)
return pages.StaticPage(content).Render(ctx, c.Response().Writer)
c.Response.Header().Set("HX-Push-Url", fullUrl)

var buf bytes.Buffer

pages.StaticPage(content).Render(ctx, &buf)

return c.HTML(200, buf.String())

})

Expand Down
15 changes: 7 additions & 8 deletions hooks/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package hooks

import (
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
)

func registerStringsUpdate(app *pocketbase.PocketBase) {
app.OnModelBeforeUpdate("strings").Add(func(e *core.ModelEvent) error {
// app.OnServe("strings").Add(func(e *core.ModelEvent) error {

// record, _ := e.Model.(*models.Record)
// content := record.Get("content").(string)
// // record, _ := e.Model.(*models.Record)
// // content := record.Get("content").(string)

// content = content + "<p>!!!</p>"
// record.Set("content", content)
// // content = content + "<p>!!!</p>"
// // record.Set("content", content)

return nil
})
// return nil
// })
}
11 changes: 1 addition & 10 deletions migrations/1695117058_strings_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,7 @@ func init() {
// return err
}, func(app core.App) error {

c, err := app.FindCollectionByNameOrId("strings")
return deleteCollection(app, "strings")

if err != nil {
return err
}

if c == nil {
return nil
}

return app.Delete(c)
})
}
11 changes: 1 addition & 10 deletions migrations/1695699035_add_schools_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ func init() {

return nil
}, func(app core.App) error {
c, err := app.FindCollectionByNameOrId("schools")

if err != nil {
return err
}

if c == nil {
return nil
}
return app.Delete(c)
return deleteCollection(app, "schools")
})
}
10 changes: 1 addition & 9 deletions migrations/1695699036_artists_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,6 @@ func init() {

return nil
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("artists")

if err != nil {
return err
}

err = app.Delete(collection)

return nil
return deleteCollection(app, "artists")
})
}
10 changes: 1 addition & 9 deletions migrations/1695699092_glossary_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ func init() {

return nil
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("glossary")

if err != nil {
return err
}

err = app.Delete(collection)

return err
return deleteCollection(app, "glossary")
})
}
8 changes: 1 addition & 7 deletions migrations/1695699127_guestbook_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ func init() {
return nil
}
}, func(app core.App) error {
c, err := app.FindCollectionByNameOrId("guestbook")

if err != nil {
return err
}

return app.Delete(c)
return deleteCollection(app, "guestbook")
})
}
8 changes: 1 addition & 7 deletions migrations/1696390260_add_art_periods_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ func init() {

return nil
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("art_periods")

if err != nil {
return err
}

return app.Delete(collection)
return deleteCollection(app, tId)
})
}
8 changes: 1 addition & 7 deletions migrations/1696400261_add_art_forms_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ func init() {

return nil
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId(tName)

if err != nil {
return err
}

return app.Delete(collection)
return deleteCollection(app, tId)
})
}
8 changes: 1 addition & 7 deletions migrations/1696479673_add_art_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ func init() {

return nil
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("art_types")

if err != nil {
return err
}

return app.Delete(collection)
return deleteCollection(app, tId)
})
}
10 changes: 1 addition & 9 deletions migrations/1696479790_add_art_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,6 @@ func init() {

return nil
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("artworks")

if err != nil {
return err
}

err = app.Delete(collection)

return err
return deleteCollection(app, "artworks")
})
}
37 changes: 14 additions & 23 deletions migrations/1697514430_create_postcards_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func init() {

collection.Fields.Add(
&core.TextField{
Id: "postcard_sender_name",
Name: "sender_name",
Required: true,
Id: "postcard_sender_name",
Name: "sender_name",
Required: true,
Presentable: true,
},
&core.EmailField{
Expand All @@ -40,38 +40,29 @@ func init() {
Name: "image_id",
CollectionId: "artworks",
MinSelect: 1,
MaxSelect: 1,
MaxSelect: 1,
},
&core.BoolField{
Id: "postcard_notify_sender",
Name: "notify_sender",
Id: "postcard_notify_sender",
Name: "notify_sender",
},
&core.SelectField{
Id: "postcard_status",
Name: "status",
Values: []string{"queued", "sent", "received"},
MaxSelect: 1,
Required: true,
Id: "postcard_status",
Name: "status",
Values: []string{"queued", "sent", "received"},
MaxSelect: 1,
Required: true,
Presentable: true,
},
&core.DateField{
Id: "postcard_sent_at",
Name: "sent_at",
Id: "postcard_sent_at",
Name: "sent_at",
},
)

return app.Save(collection)

}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("postcards")

if err != nil {
// collection not found, probably already deleted
// so nothing to do
return nil
}

return app.Delete(collection)

return deleteCollection(app, "postcards")
})
}
66 changes: 26 additions & 40 deletions migrations/1697713164_create_feedbacks_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,64 @@ package migrations
import (
"os"

"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/models"
"github.com/pocketbase/pocketbase/models/schema"
)

func init() {

tId := "feedbacks"
tName := "Feedbacks"

m.Register(func(db dbx.Builder) error {
dao := daos.New(db)
m.Register(func(app core.App) error {

collection := &models.Collection{}

collection := core.NewBaseCollection(tName)

collection.Name = tName
collection.Id = tId
collection.Type = models.CollectionTypeBase
collection.System = false
collection.MarkAsNew()

collection.Schema = schema.NewSchema(
&schema.SchemaField{
collection.Fields.Add(
&core.TextField{
Id: tId + "_name",
Name: "name",
Type: schema.FieldTypeText,
Options: &schema.TextOptions{},
Presentable: true,
Required: true,
},
&schema.SchemaField{
&core.EmailField{
Id: tId + "_email",
Name: "email",
Type: schema.FieldTypeEmail,
Options: &schema.EmailOptions{},
Required: true,
},
&schema.SchemaField{
Id: tId + "_refer_to",
Name: "refer_to",
Type: schema.FieldTypeUrl,
Options: &schema.UrlOptions{
OnlyDomains: []string{os.Getenv("WGA_HOSTNAME")},
},
Required: true,
&core.URLField{
Id: tId + "_refer_to",
Name: "refer_to",
OnlyDomains: []string{os.Getenv("WGA_HOSTNAME")},
Required: true,
},
&schema.SchemaField{
Id: tId + "_message",
Name: "message",
Type: schema.FieldTypeEditor,
Options: &schema.EditorOptions{
ConvertUrls: true,
},
&core.EditorField{
Id: tId + "_message",
Name: "message",
Required: true,
ConvertURLs: true,
},
&schema.SchemaField{
Id: tId + "_handled",
Name: "handled",
Type: schema.FieldTypeBool,
Options: &schema.BoolOptions{},
&core.BoolField{
Id: tId + "_handled",
Name: "handled",
Presentable: true,
},
)

return dao.SaveCollection(collection)
return app.Save(collection)

}, func(db dbx.Builder) error {
q := db.DropTable(tId)
_, err := q.Execute()
}, func(app core.App) error {
c, err := app.FindCollectionByNameOrId(tId)
if err != nil {
return nil
}

return err
return app.Delete(c)
})
}
Loading

0 comments on commit fca5017

Please sign in to comment.