adds dynamic trail filters
This commit is contained in:
62
db/migrations/1711993630_created_trails_filter.go
Normal file
62
db/migrations/1711993630_created_trails_filter.go
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
jsonData := `{
|
||||||
|
"id": "4wbv9tz5zjdrjh1",
|
||||||
|
"created": "2024-04-01 17:47:10.015Z",
|
||||||
|
"updated": "2024-04-01 17:47:10.015Z",
|
||||||
|
"name": "trails_filter",
|
||||||
|
"type": "view",
|
||||||
|
"system": false,
|
||||||
|
"schema": [
|
||||||
|
{
|
||||||
|
"system": false,
|
||||||
|
"id": "ovledory",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"indexes": [],
|
||||||
|
"listRule": null,
|
||||||
|
"viewRule": null,
|
||||||
|
"createRule": null,
|
||||||
|
"updateRule": null,
|
||||||
|
"deleteRule": null,
|
||||||
|
"options": {
|
||||||
|
"query": "SELECT (ROW_NUMBER() OVER()) as id, MAX(trails.distance) AS max_distance FROM trails;"
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
collection := &models.Collection{}
|
||||||
|
if err := json.Unmarshal([]byte(jsonData), &collection); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return daos.New(db).SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dao.DeleteCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
177
db/migrations/1711993758_updated_trails_filter.go
Normal file
177
db/migrations/1711993758_updated_trails_filter.go
Normal file
@@ -0,0 +1,177 @@
|
|||||||
|
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("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := map[string]any{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"query": "SELECT (ROW_NUMBER() OVER()) as id, MAX(trails.distance) AS max_distance, MAX(trails.elevation_gain) AS max_elevation_gain, MAX(trails.duration) AS max_duration, MIN(trails.distance) AS min_distance, MIN(trails.elevation_gain) AS min_elevation_gain, MIN(trails.duration) AS min_duration FROM trails;"
|
||||||
|
}`), &options)
|
||||||
|
collection.SetOptions(options)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("ovledory")
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "3neuurse",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_distance)
|
||||||
|
collection.Schema.AddField(new_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "oynpksx3",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "tkoppkjw",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_duration)
|
||||||
|
collection.Schema.AddField(new_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "uxc0eimu",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_distance)
|
||||||
|
collection.Schema.AddField(new_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qcktbht6",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qpkhyujt",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_duration)
|
||||||
|
collection.Schema.AddField(new_min_duration)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := map[string]any{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"query": "SELECT (ROW_NUMBER() OVER()) as id, MAX(trails.distance) AS max_distance FROM trails;"
|
||||||
|
}`), &options)
|
||||||
|
collection.SetOptions(options)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "ovledory",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_distance)
|
||||||
|
collection.Schema.AddField(del_max_distance)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("3neuurse")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("oynpksx3")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("tkoppkjw")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("uxc0eimu")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qcktbht6")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qpkhyujt")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
265
db/migrations/1711994239_updated_trails_filter.go
Normal file
265
db/migrations/1711994239_updated_trails_filter.go
Normal file
@@ -0,0 +1,265 @@
|
|||||||
|
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"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.ListRule = types.Pointer("@request.auth.id != \"\"")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("3neuurse")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("oynpksx3")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("tkoppkjw")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("uxc0eimu")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qcktbht6")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qpkhyujt")
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "54a1hvuq",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_distance)
|
||||||
|
collection.Schema.AddField(new_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "stcnunkf",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "bholagx7",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_duration)
|
||||||
|
collection.Schema.AddField(new_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qjrtggwi",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_distance)
|
||||||
|
collection.Schema.AddField(new_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "wtlhqwd2",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "sputfuyq",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_duration)
|
||||||
|
collection.Schema.AddField(new_min_duration)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.ListRule = nil
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "3neuurse",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_distance)
|
||||||
|
collection.Schema.AddField(del_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "oynpksx3",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(del_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "tkoppkjw",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_duration)
|
||||||
|
collection.Schema.AddField(del_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "uxc0eimu",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_distance)
|
||||||
|
collection.Schema.AddField(del_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qcktbht6",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(del_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qpkhyujt",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_duration)
|
||||||
|
collection.Schema.AddField(del_min_duration)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("54a1hvuq")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("stcnunkf")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("bholagx7")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qjrtggwi")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("wtlhqwd2")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("sputfuyq")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
272
db/migrations/1711995679_updated_trails_filter.go
Normal file
272
db/migrations/1711995679_updated_trails_filter.go
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
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("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := map[string]any{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"query": "SELECT users.id, MAX(trails.distance) AS max_distance, MAX(trails.elevation_gain) AS max_elevation_gain, MAX(trails.duration) AS max_duration, MIN(trails.distance) AS min_distance, MIN(trails.elevation_gain) AS min_elevation_gain, MIN(trails.duration) AS min_duration FROM users JOIN trails ON users.id = trails.author GROUP BY users.id;"
|
||||||
|
}`), &options)
|
||||||
|
collection.SetOptions(options)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("54a1hvuq")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("stcnunkf")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("bholagx7")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("qjrtggwi")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("wtlhqwd2")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("sputfuyq")
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "5udo4avx",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_distance)
|
||||||
|
collection.Schema.AddField(new_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "omuxiatj",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "yq4snqnf",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_duration)
|
||||||
|
collection.Schema.AddField(new_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "q8d41loj",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_distance)
|
||||||
|
collection.Schema.AddField(new_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "xsetw0o6",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "n4pq80mu",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_duration)
|
||||||
|
collection.Schema.AddField(new_min_duration)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
options := map[string]any{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"query": "SELECT (ROW_NUMBER() OVER()) as id, MAX(trails.distance) AS max_distance, MAX(trails.elevation_gain) AS max_elevation_gain, MAX(trails.duration) AS max_duration, MIN(trails.distance) AS min_distance, MIN(trails.elevation_gain) AS min_elevation_gain, MIN(trails.duration) AS min_duration FROM trails;"
|
||||||
|
}`), &options)
|
||||||
|
collection.SetOptions(options)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "54a1hvuq",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_distance)
|
||||||
|
collection.Schema.AddField(del_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "stcnunkf",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(del_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "bholagx7",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_duration)
|
||||||
|
collection.Schema.AddField(del_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "qjrtggwi",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_distance)
|
||||||
|
collection.Schema.AddField(del_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "wtlhqwd2",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(del_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "sputfuyq",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_duration)
|
||||||
|
collection.Schema.AddField(del_min_duration)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("5udo4avx")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("omuxiatj")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("yq4snqnf")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("q8d41loj")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("xsetw0o6")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("n4pq80mu")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
269
db/migrations/1711995722_updated_trails_filter.go
Normal file
269
db/migrations/1711995722_updated_trails_filter.go
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
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"
|
||||||
|
"github.com/pocketbase/pocketbase/tools/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.ListRule = nil
|
||||||
|
|
||||||
|
collection.ViewRule = types.Pointer("@request.auth.id = id")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("5udo4avx")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("omuxiatj")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("yq4snqnf")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("q8d41loj")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("xsetw0o6")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("n4pq80mu")
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "nqiuah7b",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_distance)
|
||||||
|
collection.Schema.AddField(new_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "rpzvilry",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "pfppgcfx",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_max_duration)
|
||||||
|
collection.Schema.AddField(new_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "jrqp7c8d",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_distance)
|
||||||
|
collection.Schema.AddField(new_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "xjcpg4su",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(new_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
new_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "cuj9awlq",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), new_min_duration)
|
||||||
|
collection.Schema.AddField(new_min_duration)
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
}, func(db dbx.Builder) error {
|
||||||
|
dao := daos.New(db);
|
||||||
|
|
||||||
|
collection, err := dao.FindCollectionByNameOrId("4wbv9tz5zjdrjh1")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
collection.ListRule = types.Pointer("@request.auth.id != \"\"")
|
||||||
|
|
||||||
|
collection.ViewRule = nil
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "5udo4avx",
|
||||||
|
"name": "max_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_distance)
|
||||||
|
collection.Schema.AddField(del_max_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "omuxiatj",
|
||||||
|
"name": "max_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_elevation_gain)
|
||||||
|
collection.Schema.AddField(del_max_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_max_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "yq4snqnf",
|
||||||
|
"name": "max_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_max_duration)
|
||||||
|
collection.Schema.AddField(del_max_duration)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_distance := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "q8d41loj",
|
||||||
|
"name": "min_distance",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_distance)
|
||||||
|
collection.Schema.AddField(del_min_distance)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_elevation_gain := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "xsetw0o6",
|
||||||
|
"name": "min_elevation_gain",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_elevation_gain)
|
||||||
|
collection.Schema.AddField(del_min_elevation_gain)
|
||||||
|
|
||||||
|
// add
|
||||||
|
del_min_duration := &schema.SchemaField{}
|
||||||
|
json.Unmarshal([]byte(`{
|
||||||
|
"system": false,
|
||||||
|
"id": "n4pq80mu",
|
||||||
|
"name": "min_duration",
|
||||||
|
"type": "json",
|
||||||
|
"required": false,
|
||||||
|
"presentable": false,
|
||||||
|
"unique": false,
|
||||||
|
"options": {
|
||||||
|
"maxSize": 1
|
||||||
|
}
|
||||||
|
}`), del_min_duration)
|
||||||
|
collection.Schema.AddField(del_min_duration)
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("nqiuah7b")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("rpzvilry")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("pfppgcfx")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("jrqp7c8d")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("xjcpg4su")
|
||||||
|
|
||||||
|
// remove
|
||||||
|
collection.Schema.RemoveField("cuj9awlq")
|
||||||
|
|
||||||
|
return dao.SaveCollection(collection)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -99,6 +99,15 @@ interface TrailFilter {
|
|||||||
sortOrder: "+" | "-"
|
sortOrder: "+" | "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TrailFilterValues {
|
||||||
|
min_distance: number,
|
||||||
|
max_distance: number,
|
||||||
|
min_elevation_gain: number,
|
||||||
|
max_elevation_gain: number,
|
||||||
|
min_durtation: number,
|
||||||
|
max_duration: number,
|
||||||
|
}
|
||||||
|
|
||||||
export { Trail };
|
export { Trail };
|
||||||
|
|
||||||
export type { TrailFilter };
|
export type { TrailFilter, TrailFilterValues };
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { SummitLog } from "$lib/models/summit_log";
|
import type { SummitLog } from "$lib/models/summit_log";
|
||||||
import { Trail, type TrailFilter } from "$lib/models/trail";
|
import { Trail, type TrailFilter, type TrailFilterValues } from "$lib/models/trail";
|
||||||
import type { Waypoint } from "$lib/models/waypoint";
|
import type { Waypoint } from "$lib/models/waypoint";
|
||||||
import { pb } from "$lib/pocketbase";
|
import { pb } from "$lib/pocketbase";
|
||||||
import { getFileURL } from "$lib/util/file_util";
|
import { getFileURL } from "$lib/util/file_util";
|
||||||
@@ -349,6 +349,18 @@ export async function trails_delete(trail: Trail) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function trails_get_filter_values(f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch): Promise<TrailFilterValues> {
|
||||||
|
const r = await f('/api/v1/trail/filter', {
|
||||||
|
method: 'GET',
|
||||||
|
})
|
||||||
|
|
||||||
|
if (r.ok) {
|
||||||
|
return await r.json();
|
||||||
|
} else {
|
||||||
|
throw new ClientResponseError(await r.json())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchGPX(trail: Trail, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
export async function fetchGPX(trail: Trail, f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch) {
|
||||||
if (!trail.gpx) {
|
if (!trail.gpx) {
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
12
web/src/routes/api/v1/trail/filter/+server.ts
Normal file
12
web/src/routes/api/v1/trail/filter/+server.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { type TrailFilterValues } from '$lib/models/trail';
|
||||||
|
import { pb } from '$lib/pocketbase';
|
||||||
|
import { error, json, type RequestEvent } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export async function GET(event: RequestEvent) {
|
||||||
|
try {
|
||||||
|
const r = await pb.collection('trails_filter').getOne<TrailFilterValues>(pb.authStore.model!.id)
|
||||||
|
return json(r)
|
||||||
|
} catch (e: any) {
|
||||||
|
throw error(e.status, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,9 +16,20 @@
|
|||||||
|
|
||||||
let loading: boolean = false;
|
let loading: boolean = false;
|
||||||
|
|
||||||
const redirectURL = "/redirect";
|
|
||||||
|
|
||||||
const authProviders = $page.data.authMethods.authProviders;
|
const authProviders = $page.data.authMethods.authProviders;
|
||||||
|
let loginLabel = "";
|
||||||
|
|
||||||
|
if (
|
||||||
|
$page.data.authMethods.usernamePassword &&
|
||||||
|
$page.data.authMethods.emailPassword
|
||||||
|
) {
|
||||||
|
loginLabel = `${$_("username")}/${$_("email")}`;
|
||||||
|
} else if ($page.data.authMethods.usernamePassword) {
|
||||||
|
loginLabel = `${$_("username")}`;
|
||||||
|
} else if ($page.data.authMethods.emailPassword) {
|
||||||
|
loginLabel = `${$_("email")}`;
|
||||||
|
}
|
||||||
|
|
||||||
const { form, errors, handleChange, handleSubmit } = createForm<User>({
|
const { form, errors, handleChange, handleSubmit } = createForm<User>({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
id: "",
|
id: "",
|
||||||
@@ -58,10 +69,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function setProvider(provider: AuthProviderInfo) {
|
function setProvider(provider: AuthProviderInfo) {
|
||||||
localStorage.setItem(
|
localStorage.setItem("provider", JSON.stringify(provider));
|
||||||
"provider",
|
|
||||||
JSON.stringify(provider),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -79,10 +87,11 @@
|
|||||||
<LogoTextTwoLineLight></LogoTextTwoLineLight>
|
<LogoTextTwoLineLight></LogoTextTwoLineLight>
|
||||||
{/if}
|
{/if}
|
||||||
<h4 class="text-xl font-semibold">{$_("slogan")}</h4>
|
<h4 class="text-xl font-semibold">{$_("slogan")}</h4>
|
||||||
|
{#if $page.data.authMethods.usernamePassword || $page.data.authMethods.emailPassword}
|
||||||
<div class="space-y-6 w-80">
|
<div class="space-y-6 w-80">
|
||||||
<TextField
|
<TextField
|
||||||
name="username"
|
name="username"
|
||||||
label="{$_('username')}/{$_('email')}"
|
label={loginLabel}
|
||||||
bind:value={$form.username}
|
bind:value={$form.username}
|
||||||
on:change={handleChange}
|
on:change={handleChange}
|
||||||
error={$errors.username}
|
error={$errors.username}
|
||||||
@@ -110,12 +119,16 @@
|
|||||||
></span
|
></span
|
||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if authProviders.length}
|
{#if authProviders.length}
|
||||||
|
{#if $page.data.authMethods.usernamePassword || $page.data.authMethods.emailPassword}
|
||||||
<div class="flex gap-4 items-center w-full">
|
<div class="flex gap-4 items-center w-full">
|
||||||
<hr class="basis-full border-input-border" />
|
<hr class="basis-full border-input-border" />
|
||||||
<span class="text-gray-500 uppercase">{$_("or")}</span>
|
<span class="text-gray-500 uppercase">{$_("or")}</span>
|
||||||
<hr class="basis-full border-input-border" />
|
<hr class="basis-full border-input-border" />
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
<div class="w-80 space-y-4">
|
<div class="w-80 space-y-4">
|
||||||
{#each authProviders as provider}
|
{#each authProviders as provider}
|
||||||
<a
|
<a
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import type { TrailFilter } from "$lib/models/trail";
|
import type { TrailFilter } from "$lib/models/trail";
|
||||||
import { categories_index } from "$lib/stores/category_store";
|
import { categories_index } from "$lib/stores/category_store";
|
||||||
import { trails } from "$lib/stores/trail_store";
|
import { trails, trails_get_filter_values } from "$lib/stores/trail_store";
|
||||||
import type { ServerLoad } from "@sveltejs/kit";
|
import type { ServerLoad } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load: ServerLoad = async ({ params, locals, fetch }) => {
|
export const load: ServerLoad = async ({ params, locals, fetch }) => {
|
||||||
|
const filterValues = await trails_get_filter_values(fetch);
|
||||||
|
|
||||||
const filter: TrailFilter = {
|
const filter: TrailFilter = {
|
||||||
q: "",
|
q: "",
|
||||||
category: [],
|
category: [],
|
||||||
@@ -12,11 +14,11 @@ export const load: ServerLoad = async ({ params, locals, fetch }) => {
|
|||||||
radius: 2000,
|
radius: 2000,
|
||||||
},
|
},
|
||||||
distanceMin: 0,
|
distanceMin: 0,
|
||||||
distanceMax: 20000,
|
distanceMax: filterValues.max_distance,
|
||||||
distanceLimit: 20000,
|
distanceLimit: filterValues.max_distance,
|
||||||
elevationGainMin: 0,
|
elevationGainMin: 0,
|
||||||
elevationGainMax: 4000,
|
elevationGainMax: filterValues.max_elevation_gain,
|
||||||
elevationGainLimit: 4000,
|
elevationGainLimit: filterValues.max_elevation_gain,
|
||||||
sort: "created",
|
sort: "created",
|
||||||
sortOrder: "+",
|
sortOrder: "+",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import type { TrailFilter } from "$lib/models/trail";
|
import type { TrailFilter } from "$lib/models/trail";
|
||||||
import { categories_index } from "$lib/stores/category_store";
|
import { categories_index } from "$lib/stores/category_store";
|
||||||
import { trails_search_filter } from "$lib/stores/trail_store";
|
import { trails_get_filter_values, trails_search_filter } from "$lib/stores/trail_store";
|
||||||
import type { ServerLoad } from "@sveltejs/kit";
|
import type { ServerLoad } from "@sveltejs/kit";
|
||||||
|
|
||||||
export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
|
export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
|
||||||
|
const filterValues = await trails_get_filter_values(fetch);
|
||||||
|
|
||||||
const filter: TrailFilter = {
|
const filter: TrailFilter = {
|
||||||
q: "",
|
q: "",
|
||||||
category: [],
|
category: [],
|
||||||
@@ -12,11 +14,11 @@ export const load: ServerLoad = async ({ params, locals, url, fetch }) => {
|
|||||||
radius: 2000,
|
radius: 2000,
|
||||||
},
|
},
|
||||||
distanceMin: 0,
|
distanceMin: 0,
|
||||||
distanceMax: 20000,
|
distanceMax: filterValues.max_distance,
|
||||||
distanceLimit: 20000,
|
distanceLimit: filterValues.max_distance,
|
||||||
elevationGainMin: 0,
|
elevationGainMin: 0,
|
||||||
elevationGainMax: 4000,
|
elevationGainMax: filterValues.max_elevation_gain,
|
||||||
elevationGainLimit: 4000,
|
elevationGainLimit: filterValues.max_elevation_gain,
|
||||||
sort: "created",
|
sort: "created",
|
||||||
sortOrder: "+",
|
sortOrder: "+",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user