diff --git a/db/main.go b/db/main.go index 46183266..87e47be6 100644 --- a/db/main.go +++ b/db/main.go @@ -130,7 +130,7 @@ func createTrailHandler(client meilisearch.ServiceManager) func(e *core.RecordEv if err != nil { return err } - if err := util.IndexTrail(record, author, client); err != nil { + if err := util.IndexTrail(e.App, record, author, client); err != nil { return err } @@ -160,7 +160,7 @@ func updateTrailHandler(client meilisearch.ServiceManager) func(e *core.RecordEv if err != nil { return err } - err = util.UpdateTrail(record, author, client) + err = util.UpdateTrail(e.App, record, author, client) if err != nil { return err } @@ -789,7 +789,7 @@ func bootstrapMeilisearchTrails(app core.App, client meilisearch.ServiceManager) if err != nil { return err } - if err := util.IndexTrail(trail, author, client); err != nil { + if err := util.IndexTrail(app, trail, author, client); err != nil { return err } diff --git a/db/migrations/1742167033_init_meilisearch.go b/db/migrations/1742167033_init_meilisearch.go index 6229687b..3e75d45c 100644 --- a/db/migrations/1742167033_init_meilisearch.go +++ b/db/migrations/1742167033_init_meilisearch.go @@ -29,7 +29,7 @@ func init() { } _, err = client.Index("trails").UpdateFilterableAttributes(&[]string{ - "_geo", "author", "category", "completed", "date", "difficulty", "distance", "elevation_gain", "elevation_loss", "public", "shares", + "_geo", "author", "category", "completed", "date", "difficulty", "distance", "elevation_gain", "elevation_loss", "public", "shares", "tags", }) if err != nil { diff --git a/db/migrations/1742409454_created_tags.go b/db/migrations/1742409454_created_tags.go new file mode 100644 index 00000000..a40e319e --- /dev/null +++ b/db/migrations/1742409454_created_tags.go @@ -0,0 +1,89 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + jsonData := `{ + "createRule": null, + "deleteRule": null, + "fields": [ + { + "autogeneratePattern": "[a-z0-9]{15}", + "hidden": false, + "id": "text3208210256", + "max": 15, + "min": 15, + "name": "id", + "pattern": "^[a-z0-9]+$", + "presentable": false, + "primaryKey": true, + "required": true, + "system": true, + "type": "text" + }, + { + "autogeneratePattern": "", + "hidden": false, + "id": "text1579384326", + "max": 0, + "min": 0, + "name": "name", + "pattern": "", + "presentable": false, + "primaryKey": false, + "required": false, + "system": false, + "type": "text" + }, + { + "hidden": false, + "id": "autodate2990389176", + "name": "created", + "onCreate": true, + "onUpdate": false, + "presentable": false, + "system": false, + "type": "autodate" + }, + { + "hidden": false, + "id": "autodate3332085495", + "name": "updated", + "onCreate": true, + "onUpdate": true, + "presentable": false, + "system": false, + "type": "autodate" + } + ], + "id": "pbc_1219621782", + "indexes": [], + "listRule": null, + "name": "tags", + "system": false, + "type": "base", + "updateRule": null, + "viewRule": null + }` + + collection := &core.Collection{} + if err := json.Unmarshal([]byte(jsonData), &collection); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1219621782") + if err != nil { + return err + } + + return app.Delete(collection) + }) +} diff --git a/db/migrations/1742411241_updated_tags.go b/db/migrations/1742411241_updated_tags.go new file mode 100644 index 00000000..b9ce1f42 --- /dev/null +++ b/db/migrations/1742411241_updated_tags.go @@ -0,0 +1,44 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1219621782") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "createRule": "@request.auth.id != \"\"", + "listRule": "", + "viewRule": "" + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1219621782") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "createRule": null, + "listRule": null, + "viewRule": null + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }) +} diff --git a/db/migrations/1742411270_updated_tags.go b/db/migrations/1742411270_updated_tags.go new file mode 100644 index 00000000..e11b9113 --- /dev/null +++ b/db/migrations/1742411270_updated_tags.go @@ -0,0 +1,42 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1219621782") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "listRule": "@request.auth.id != \"\"", + "viewRule": "@request.auth.id != \"\"" + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("pbc_1219621782") + if err != nil { + return err + } + + // update collection data + if err := json.Unmarshal([]byte(`{ + "listRule": "", + "viewRule": "" + }`), &collection); err != nil { + return err + } + + return app.Save(collection) + }) +} diff --git a/db/migrations/1742412356_updated_trails.go b/db/migrations/1742412356_updated_trails.go new file mode 100644 index 00000000..72d87e9f --- /dev/null +++ b/db/migrations/1742412356_updated_trails.go @@ -0,0 +1,44 @@ +package migrations + +import ( + "github.com/pocketbase/pocketbase/core" + m "github.com/pocketbase/pocketbase/migrations" +) + +func init() { + m.Register(func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4") + if err != nil { + return err + } + + // add field + if err := collection.Fields.AddMarshaledJSONAt(14, []byte(`{ + "cascadeDelete": false, + "collectionId": "pbc_1219621782", + "hidden": false, + "id": "relation1874629670", + "maxSelect": 999, + "minSelect": 0, + "name": "tags", + "presentable": false, + "required": false, + "system": false, + "type": "relation" + }`)); err != nil { + return err + } + + return app.Save(collection) + }, func(app core.App) error { + collection, err := app.FindCollectionByNameOrId("e864strfxo14pm4") + if err != nil { + return err + } + + // remove field + collection.Fields.RemoveById("relation1874629670") + + return app.Save(collection) + }) +} diff --git a/db/util/meilisearch.go b/db/util/meilisearch.go index 731f6c3d..658840dc 100644 --- a/db/util/meilisearch.go +++ b/db/util/meilisearch.go @@ -2,6 +2,7 @@ package util import ( "errors" + "fmt" "log" "github.com/meilisearch/meilisearch-go" @@ -19,6 +20,13 @@ func documentFromTrailRecord(r *core.Record, author *core.Record, includeShares thumbnail = photos[thumbnailIndex] } + tagRecords := r.ExpandedAll("tags") + tags := make([]string, len(tagRecords)) + + for i, v := range tagRecords { + tags[i] = v.GetString("name") + } + document := map[string]interface{}{ "id": r.Id, "author": r.GetString("author"), @@ -39,6 +47,7 @@ func documentFromTrailRecord(r *core.Record, author *core.Record, includeShares "public": r.GetBool("public"), "thumbnail": thumbnail, "gpx": r.GetString("gpx"), + "tags": tags, "_geo": map[string]float64{ "lat": r.GetFloat("lat"), "lng": r.GetFloat("lon"), @@ -70,7 +79,12 @@ func documentFromListRecord(r *core.Record, includeShares bool) map[string]inter return document } -func IndexTrail(r *core.Record, author *core.Record, client meilisearch.ServiceManager) error { +func IndexTrail(app core.App, r *core.Record, author *core.Record, client meilisearch.ServiceManager) error { + errs := app.ExpandRecord(r, []string{"tags"}, nil) + if len(errs) > 0 { + return fmt.Errorf("failed to expand: %v", errs) + } + documents := []map[string]interface{}{documentFromTrailRecord(r, author, true)} if _, err := client.Index("trails").AddDocuments(documents); err != nil { @@ -80,7 +94,12 @@ func IndexTrail(r *core.Record, author *core.Record, client meilisearch.ServiceM return nil } -func UpdateTrail(r *core.Record, author *core.Record, client meilisearch.ServiceManager) error { +func UpdateTrail(app core.App, r *core.Record, author *core.Record, client meilisearch.ServiceManager) error { + errs := app.ExpandRecord(r, []string{"tags"}, nil) + if len(errs) > 0 { + return fmt.Errorf("failed to expand: %v", errs) + } + documents := documentFromTrailRecord(r, author, false) if _, err := client.Index("trails").UpdateDocuments(documents); err != nil { diff --git a/web/src/lib/components/base/chip.svelte b/web/src/lib/components/base/chip.svelte new file mode 100644 index 00000000..d6e67c66 --- /dev/null +++ b/web/src/lib/components/base/chip.svelte @@ -0,0 +1,30 @@ + + +
{item.text}
{/each} diff --git a/web/src/lib/components/base/multi_select.svelte b/web/src/lib/components/base/multi_select.svelte index 96b46d6a..1783a2b4 100644 --- a/web/src/lib/components/base/multi_select.svelte +++ b/web/src/lib/components/base/multi_select.svelte @@ -1,6 +1,7 @@+
{$_("by")}
{/if}
-