adds trail date field

This commit is contained in:
Christian Beutel
2024-04-05 16:39:50 +02:00
parent 8f71952a71
commit 2a2a49fd94
18 changed files with 176 additions and 10 deletions

View File

@@ -0,0 +1,34 @@
package migrations
import (
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/tools/types"
)
func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("_pb_users_auth_")
if err != nil {
return err
}
collection.ListRule = types.Pointer("@request.auth.id != \"\"")
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("_pb_users_auth_")
if err != nil {
return err
}
collection.ListRule = types.Pointer("id = @request.auth.id")
return dao.SaveCollection(collection)
})
}

View File

@@ -0,0 +1,34 @@
package migrations
import (
"github.com/pocketbase/dbx"
"github.com/pocketbase/pocketbase/daos"
m "github.com/pocketbase/pocketbase/migrations"
"github.com/pocketbase/pocketbase/tools/types"
)
func init() {
m.Register(func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("_pb_users_auth_")
if err != nil {
return err
}
collection.ViewRule = types.Pointer("@request.auth.id != \"\"")
return dao.SaveCollection(collection)
}, func(db dbx.Builder) error {
dao := daos.New(db);
collection, err := dao.FindCollectionByNameOrId("_pb_users_auth_")
if err != nil {
return err
}
collection.ViewRule = types.Pointer("id = @request.auth.id")
return dao.SaveCollection(collection)
})
}

View File

@@ -0,0 +1,54 @@
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_date := &schema.SchemaField{}
if err := json.Unmarshal([]byte(`{
"system": false,
"id": "hovyvbtt",
"name": "date",
"type": "date",
"required": false,
"presentable": false,
"unique": false,
"options": {
"min": "",
"max": ""
}
}`), new_date); err != nil {
return err
}
collection.Schema.AddField(new_date)
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("hovyvbtt")
return dao.SaveCollection(collection)
})
}

View File

@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
export let name: string = ""; export let name: string = "";
export let value: string | number | Date = ""; export let value: string | Date = "";
export let label: string = ""; export let label: string = "";
export let error: string = ""; export let error: string = "";
</script> </script>

View File

@@ -14,10 +14,9 @@
let editedComment = comment.text; let editedComment = comment.text;
const avatarSrc = const avatarSrc = comment.expand?.author.avatar
comment.expand && comment.expand.author ? getFileURL(comment.expand.author, comment.expand.author.avatar)
? getFileURL(comment.expand?.author, comment.expand?.author.avatar) : `https://api.dicebear.com/7.x/initials/svg?seed=${comment.expand?.author.username ?? ""}&backgroundType=gradientLinear`;
: "https://api.dicebear.com/7.x/initials/svg?seed=comment&backgroundType=gradientLinear";
function deleteComment() { function deleteComment() {
dispatch("delete", comment); dispatch("delete", comment);
@@ -31,7 +30,11 @@
} }
</script> </script>
<div class="flex gap-4 items-center" in:fade={{duration: 150}} out:fade={{duration: 150}}> <div
class="flex gap-4 items-center"
in:fade={{ duration: 150 }}
out:fade={{ duration: 150 }}
>
<img class="rounded-full w-10 aspect-square" src={avatarSrc} alt="avatar" /> <img class="rounded-full w-10 aspect-square" src={avatarSrc} alt="avatar" />
<div> <div>
<div class="flex items-center"> <div class="flex items-center">

View File

@@ -27,6 +27,17 @@
<div class="p-4"> <div class="p-4">
<div> <div>
<h4 class="font-semibold text-lg">{trail.name}</h4> <h4 class="font-semibold text-lg">{trail.name}</h4>
{#if trail.date}
<p class="text-xs text-gray-500 mb-3">
{new Date(
trail.date,
).toLocaleDateString(undefined, {
month: "long",
day: "2-digit",
year: "numeric",
})}
</p>
{/if}
<div class="flex gap-x-4"> <div class="flex gap-x-4">
{#if trail.location} {#if trail.location}
<h5> <h5>
@@ -40,7 +51,7 @@
</h5> </h5>
</div> </div>
</div> </div>
<div class="flex mt-2 gap-4 text-sm text-gray-500 whitespace-nowrap"> <div class="flex mt-1 gap-4 text-sm text-gray-500 whitespace-nowrap">
<span <span
><i class="fa fa-left-right mr-2"></i>{formatDistance( ><i class="fa fa-left-right mr-2"></i>{formatDistance(
trail.distance, trail.distance,

View File

@@ -41,7 +41,7 @@
$_("waypoints"), $_("waypoints"),
$_("photos"), $_("photos"),
$_("summit-book"), $_("summit-book"),
$_("comments"), $_("comment", { values: { n: 2 } }),
]; ];
let map: Map; let map: Map;

View File

@@ -23,6 +23,15 @@
</div> </div>
<div class="min-w-0 basis-full"> <div class="min-w-0 basis-full">
<h4 class="font-semibold text-lg">{trail.name}</h4> <h4 class="font-semibold text-lg">{trail.name}</h4>
{#if trail.date}
<p class="text-xs text-gray-500 mb-3">
{new Date(trail.date).toLocaleDateString(undefined, {
month: "long",
day: "2-digit",
year: "numeric",
})}
</p>
{/if}
<div class="flex flex-wrap gap-x-8"> <div class="flex flex-wrap gap-x-8">
{#if trail.location} {#if trail.location}
<h5><i class="fa fa-location-dot mr-3"></i>{trail.location}</h5> <h5><i class="fa fa-location-dot mr-3"></i>{trail.location}</h5>
@@ -34,7 +43,7 @@
</h5> </h5>
</div> </div>
<div class="flex mt-2 gap-4 text-sm text-gray-500"> <div class="flex mt-1 gap-4 text-sm text-gray-500">
<span <span
><i class="fa fa-left-right mr-2"></i>{formatDistance( ><i class="fa fa-left-right mr-2"></i>{formatDistance(
trail.distance, trail.distance,

View File

@@ -18,6 +18,7 @@
"change": "Ändern", "change": "Ändern",
"changelog": "Changelog", "changelog": "Changelog",
"chinese": "Chinesisch (vereinfacht)", "chinese": "Chinesisch (vereinfacht)",
"comment": "{n, Plural, =1 {Kommentar} other {Kommentare}}",
"completed": "Abgeschlossen", "completed": "Abgeschlossen",
"completion-status": "Abschlussstatus", "completion-status": "Abschlussstatus",
"contribute": "Mitwirken", "contribute": "Mitwirken",

View File

@@ -18,6 +18,7 @@
"change": "Change", "change": "Change",
"changelog": "Changelog", "changelog": "Changelog",
"chinese": "Chinese (simplified)", "chinese": "Chinese (simplified)",
"comment": "{n, plural, =1 {Comment} other {Comments}}",
"completed": "Completed", "completed": "Completed",
"completion-status": "Completion Status", "completion-status": "Completion Status",
"contribute": "Contribute", "contribute": "Contribute",

View File

@@ -18,6 +18,7 @@
"change": "Changement", "change": "Changement",
"changelog": "Journal des modifications", "changelog": "Journal des modifications",
"chinese": "Chinois (simplifié)", "chinese": "Chinois (simplifié)",
"comment": "{n, plural, =1 {Commentaire} other {Commentaires}}",
"completed": "Compléter", "completed": "Compléter",
"completion-status": "L'état d'achèvement", "completion-status": "L'état d'achèvement",
"contribute": "Contribuer", "contribute": "Contribuer",

View File

@@ -18,6 +18,7 @@
"change": "Változás", "change": "Változás",
"changelog": "Változás napló", "changelog": "Változás napló",
"chinese": "Kínai (egyszerűsítve)", "chinese": "Kínai (egyszerűsítve)",
"comment": "{n, plural, =1 {Megjegyzés} other {Megjegyzés}}",
"completed": "Teljesítve", "completed": "Teljesítve",
"completion-status": "Befejezés állapota", "completion-status": "Befejezés állapota",
"contribute": "Hozzájárulás", "contribute": "Hozzájárulás",

View File

@@ -18,6 +18,7 @@
"change": "Aanpassen", "change": "Aanpassen",
"changelog": "Changelog", "changelog": "Changelog",
"chinese": "Versimpeld Chinees", "chinese": "Versimpeld Chinees",
"comment": "{n, plural, =1 {Opmerking} other {Opmerkingen}}",
"completed": "Voltooid", "completed": "Voltooid",
"completion-status": "Voltooiingsstatus", "completion-status": "Voltooiingsstatus",
"contribute": "Bijdragen", "contribute": "Bijdragen",

View File

@@ -18,6 +18,7 @@
"change": "Zmień", "change": "Zmień",
"changelog": "Dziennik zmian", "changelog": "Dziennik zmian",
"chinese": "Uproszczony chiński", "chinese": "Uproszczony chiński",
"comment": "{n, plural, =1 {Komentarz} other {Komentarze}}",
"completed": "Zakończono", "completed": "Zakończono",
"completion-status": "Stan ukończenia", "completion-status": "Stan ukończenia",
"contribute": "Kontrybuuj", "contribute": "Kontrybuuj",

View File

@@ -18,6 +18,7 @@
"change": "Alterar", "change": "Alterar",
"changelog": "Registo de alterações", "changelog": "Registo de alterações",
"chinese": "Chinês (simplificado)", "chinese": "Chinês (simplificado)",
"comment": "{n, plural, =1 {Comentário} other {Comentários}}",
"completed": "Completada", "completed": "Completada",
"completion-status": "Status de conclusão", "completion-status": "Status de conclusão",
"contribute": "Contribuir", "contribute": "Contribuir",

View File

@@ -18,7 +18,7 @@
"change": "更换", "change": "更换",
"changelog": "变更日志", "changelog": "变更日志",
"chinese": "华人", "chinese": "华人",
"comments": "", "comment": "{n, plural, =1 {评论} other {评论}}",
"completed": "已完成", "completed": "已完成",
"completion-status": "完成状态", "completion-status": "完成状态",
"contribute": "贡献", "contribute": "贡献",

View File

@@ -7,6 +7,7 @@ class Trail {
id?: string; id?: string;
name: string; name: string;
location?: string; location?: string;
date?: string;
public: boolean; public: boolean;
distance?: number; distance?: number;
elevation_gain?: number; elevation_gain?: number;
@@ -36,6 +37,7 @@ class Trail {
params?: { params?: {
id?: string, id?: string,
location?: string, location?: string,
date?: string,
public?: boolean, public?: boolean,
distance?: number, distance?: number,
elevation_gain?: number, elevation_gain?: number,
@@ -59,6 +61,7 @@ class Trail {
this.id = params?.id; this.id = params?.id;
this.name = name; this.name = name;
this.location = params?.location; this.location = params?.location;
this.date = params?.date;
this.public = params?.public ?? false this.public = params?.public ?? false
this.distance = params?.distance; this.distance = params?.distance;
this.elevation_gain = params?.elevation_gain; this.elevation_gain = params?.elevation_gain;

View File

@@ -1,5 +1,6 @@
<script lang="ts"> <script lang="ts">
import Button from "$lib/components/base/button.svelte"; import Button from "$lib/components/base/button.svelte";
import Datepicker from "$lib/components/base/datepicker.svelte";
import Select from "$lib/components/base/select.svelte"; import Select from "$lib/components/base/select.svelte";
import TextField from "$lib/components/base/text_field.svelte"; import TextField from "$lib/components/base/text_field.svelte";
import Textarea from "$lib/components/base/textarea.svelte"; import Textarea from "$lib/components/base/textarea.svelte";
@@ -262,6 +263,15 @@
$form.duration = Math.round( $form.duration = Math.round(
e.target.get_total_time() / 1000 / 60, e.target.get_total_time() / 1000 / 60,
); );
if ($form.duration) {
$form.date = e.target
.get_start_time()
.toISOString()
.substring(0, 10);
} else {
$form.date = new Date().toISOString().substring(0, 10);
}
resolve(); resolve();
}) })
.on("error", reject) .on("error", reject)
@@ -544,6 +554,7 @@
error={$errors.location} error={$errors.location}
bind:value={$form.location} bind:value={$form.location}
></TextField> ></TextField>
<Datepicker label="Date" bind:value={$form.date}></Datepicker>
<Textarea <Textarea
name="description" name="description"
label={$_("describe-your-trail")} label={$_("describe-your-trail")}