diff --git a/db/main.go b/db/main.go index 24eded11..439df3fe 100644 --- a/db/main.go +++ b/db/main.go @@ -29,6 +29,7 @@ func indexRecord(r *models.Record, client *meilisearch.Client) error { "distance": r.GetFloat("distance"), "elevation_gain": r.GetFloat("elevation_gain"), "duration": r.GetFloat("duration"), + "difficulty": r.Get("difficulty"), "category": r.Get("category"), "completed": len(r.GetStringSlice("summit_logs")) > 0, "created": r.GetDateTime("created"), diff --git a/db/migrations/1710073788_updated_trails.go b/db/migrations/1710073788_updated_trails.go new file mode 100644 index 00000000..0df41445 --- /dev/null +++ b/db/migrations/1710073788_updated_trails.go @@ -0,0 +1,56 @@ +package migrations + +import ( + "encoding/json" + + "github.com/pocketbase/dbx" + "github.com/pocketbase/pocketbase/daos" + m "github.com/pocketbase/pocketbase/migrations" + "github.com/pocketbase/pocketbase/models/schema" +) + +func init() { + m.Register(func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4") + if err != nil { + return err + } + + // add + new_difficulty := &schema.SchemaField{} + json.Unmarshal([]byte(`{ + "system": false, + "id": "dywtnynw", + "name": "difficulty", + "type": "select", + "required": false, + "presentable": false, + "unique": false, + "options": { + "maxSelect": 1, + "values": [ + "easy", + "moderate", + "difficult" + ] + } + }`), new_difficulty) + collection.Schema.AddField(new_difficulty) + + return dao.SaveCollection(collection) + }, func(db dbx.Builder) error { + dao := daos.New(db); + + collection, err := dao.FindCollectionByNameOrId("e864strfxo14pm4") + if err != nil { + return err + } + + // remove + collection.Schema.RemoveField("dywtnynw") + + return dao.SaveCollection(collection) + }) +} diff --git a/docker-compose.yml b/docker-compose.yml index 222b3176..68a0602e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,27 +32,36 @@ services: build: ./db environment: <<: *cenv + depends_on: + bootstrap: + condition: service_completed_successfully ports: - "8090:8090" networks: - wanderer restart: unless-stopped volumes: - - ./data/pb_data:/pb_data - + - wanderer-db:/pb_data web: build: ./web environment: + <<: *cenv + MEILI_API_TOKEN: ORIGIN: http://localhost:8080 - PUBLIC_MEILISEARCH_URL: http://search:7700 - PUBLIC_MEILISEARCH_API_TOKEN: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhcGlLZXlVaWQiOiIyMjk3NDg3Yy0zMjFlLTQ5MmEtYmRiNS1iZmYwZGYzZjc2NTYiLCJzZWFyY2hSdWxlcyI6eyJ0cmFpbHMiOnsiZmlsdGVyIjoicHVibGljPXRydWUifSwiY2l0aWVzNTAwIjp7fX0sImV4cCI6bnVsbH0.CuIlkiWAec8TGyZI5X37JTjQvcnvFAFZAuA4xpbXJ8o PUBLIC_POCKETBASE_URL: http://db:8090 ports: - "8080:3000" + depends_on: + bootstrap: + condition: service_completed_successfully networks: - wanderer restart: unless-stopped +volumes: + wanderer-db: + + networks: wanderer: driver: bridge diff --git a/search/bootstrap.py b/search/bootstrap.py index 8dbf75ba..3edc95b2 100644 --- a/search/bootstrap.py +++ b/search/bootstrap.py @@ -37,8 +37,8 @@ def init_indices(): client.create_index('trails', {'primaryKey': 'id'}) client.index('trails').update_settings({ - 'sortableAttributes': ['name', 'distance', 'elevation_gain', 'created',], - 'filterableAttributes': ['category', 'distance', 'elevation_gain', 'completed', '_geo', 'public', 'author'] + 'sortableAttributes': ['name', 'distance', 'elevation_gain', 'difficulty', 'created',], + 'filterableAttributes': ['category', 'difficulty', 'distance', 'elevation_gain', 'completed', '_geo', 'public', 'author'] }) diff --git a/web/src/lib/components/trail/trail_filter_panel.svelte b/web/src/lib/components/trail/trail_filter_panel.svelte index af7c206d..c8716e7f 100644 --- a/web/src/lib/components/trail/trail_filter_panel.svelte +++ b/web/src/lib/components/trail/trail_filter_panel.svelte @@ -11,22 +11,11 @@ import RadioGroup from "../base/radio_group.svelte"; import Search, { type SearchItem } from "../base/search.svelte"; import Slider from "../base/slider.svelte"; + import type { SelectItem } from "../base/select.svelte"; export let categories: Category[]; export let filterExpanded: boolean = true; - export let filter: TrailFilter = { - q: "", - category: [], - near: { - radius: 2000, - }, - distanceMin: 0, - distanceMax: 20000, - elevationGainMin: 0, - elevationGainMax: 4000, - sort: "created", - sortOrder: "+", - }; + export let filter: TrailFilter; export let showTrailSearch: boolean = true; export let showCitySearch: boolean = true; @@ -38,6 +27,12 @@ { text: $_("no-preference"), value: "no_preference" }, ]; + const difficultyItems: SelectItem[] = [ + { text: $_("easy"), value: "easy" }, + { text: $_("moderate"), value: "moderate" }, + { text: $_("difficult"), value: "difficult" }, + ]; + let searchDropdownItems: SearchItem[] = []; let citySearchQuery: string = ""; @@ -59,6 +54,19 @@ update(); } + function setDifficultyFilter(difficulty: "easy" | "moderate" | "difficult") { + const difficultyIndex = filter.difficulty.findIndex( + (d) => d == difficulty, + ); + if (difficultyIndex !== -1) { + filter.difficulty.splice(difficultyIndex, 1); + } else { + filter.difficulty.push(difficulty); + } + + update(); + } + function setCompletedFilter(item: RadioItem) { switch (item.value) { case "no_preference": @@ -150,6 +158,24 @@ {/each}
+

{$_("difficulty")}

+ {#each difficultyItems as difficulty, i} +
+ setDifficultyFilter(difficulty.value)} + /> + +
+ {/each} +
{#if showCitySearch}

{$_("near")}

diff --git a/web/src/lib/components/trail/trail_list.svelte b/web/src/lib/components/trail/trail_list.svelte index 61ba6e2d..59387384 100644 --- a/web/src/lib/components/trail/trail_list.svelte +++ b/web/src/lib/components/trail/trail_list.svelte @@ -1,13 +1,12 @@