komoot planned vs completed
This commit is contained in:
@@ -36,7 +36,10 @@ func SyncKomoot(app *pocketbase.PocketBase) error {
|
|||||||
|
|
||||||
userId := i.GetString("user")
|
userId := i.GetString("user")
|
||||||
komootString := i.GetString("komoot")
|
komootString := i.GetString("komoot")
|
||||||
var komootIntegration KomootIntegration
|
komootIntegration := KomootIntegration{
|
||||||
|
Planned: true,
|
||||||
|
Completed: true,
|
||||||
|
}
|
||||||
json.Unmarshal([]byte(komootString), &komootIntegration)
|
json.Unmarshal([]byte(komootString), &komootIntegration)
|
||||||
|
|
||||||
if !komootIntegration.Active || komootIntegration.Email == "" || komootIntegration.Password == "" {
|
if !komootIntegration.Active || komootIntegration.Email == "" || komootIntegration.Password == "" {
|
||||||
@@ -67,7 +70,7 @@ func SyncKomoot(app *pocketbase.PocketBase) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
hasNewTours, err = syncTrailWithTours(app, k, userId, tours)
|
hasNewTours, err = syncTrailWithTours(app, k, komootIntegration, userId, tours)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warning := fmt.Sprintf("error syncing komoot tours with trails: %v\n", err)
|
warning := fmt.Sprintf("error syncing komoot tours with trails: %v\n", err)
|
||||||
fmt.Print(warning)
|
fmt.Print(warning)
|
||||||
@@ -172,14 +175,14 @@ func (k *KomootApi) fetchDetailedTour(tour KomootTour) (*DetailedKomootTour, err
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncTrailWithTours(app *pocketbase.PocketBase, k *KomootApi, user string, tours []KomootTour) (bool, error) {
|
func syncTrailWithTours(app *pocketbase.PocketBase, k *KomootApi, i KomootIntegration, user string, tours []KomootTour) (bool, error) {
|
||||||
hasNewTours := false
|
hasNewTours := false
|
||||||
for _, tour := range tours {
|
for _, tour := range tours {
|
||||||
trails, err := app.Dao().FindRecordsByFilter("trails", "external_id = {:id}", "", 1, 0, dbx.Params{"id": strconv.Itoa(int(tour.ID))})
|
trails, err := app.Dao().FindRecordsByFilter("trails", "external_id = {:id}", "", 1, 0, dbx.Params{"id": strconv.Itoa(int(tour.ID))})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return hasNewTours, err
|
return hasNewTours, err
|
||||||
}
|
}
|
||||||
if len(trails) != 0 {
|
if len(trails) != 0 || (tour.Type == "tour_planned" && !i.Planned) || (tour.Type == "tour_recorded" && !i.Completed) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hasNewTours = true
|
hasNewTours = true
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ type KomootIntegration struct {
|
|||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
Planned bool `json:"planned"`
|
||||||
|
Completed bool `json:"completed"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginResponse struct {
|
type LoginResponse struct {
|
||||||
|
|||||||
@@ -735,7 +735,10 @@ func bootstrapMeilisearchTrails(app *pocketbase.PocketBase, client meilisearch.S
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Index("trails").DeleteAllDocuments()
|
_, err := client.Index("trails").DeleteAllDocuments()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
for _, trail := range trails {
|
for _, trail := range trails {
|
||||||
author, err := app.Dao().FindRecordById("users", trail.GetString(("author")))
|
author, err := app.Dao().FindRecordById("users", trail.GetString(("author")))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Modal from "$lib/components/base/modal.svelte";
|
import Modal from "$lib/components/base/modal.svelte";
|
||||||
import TextField from "$lib/components/base/text_field.svelte";
|
import TextField from "$lib/components/base/text_field.svelte";
|
||||||
|
import Toggle from "$lib/components/base/toggle.svelte";
|
||||||
import { KomootSchema } from "$lib/models/api/integration_schema";
|
import { KomootSchema } from "$lib/models/api/integration_schema";
|
||||||
import type {
|
import type {
|
||||||
Integration,
|
Integration,
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
let modal: Modal;
|
let modal: Modal;
|
||||||
|
|
||||||
export function openModal() {
|
export function openModal() {
|
||||||
errors.set({})
|
errors.set({});
|
||||||
modal.openModal();
|
modal.openModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,13 +33,15 @@
|
|||||||
initialValues: {
|
initialValues: {
|
||||||
email: integration?.komoot?.email ?? "",
|
email: integration?.komoot?.email ?? "",
|
||||||
password: integration?.komoot?.password ?? "",
|
password: integration?.komoot?.password ?? "",
|
||||||
|
completed: integration?.komoot?.completed ?? true,
|
||||||
|
planned: integration?.komoot?.planned ?? true,
|
||||||
active: integration?.komoot?.active ?? false,
|
active: integration?.komoot?.active ?? false,
|
||||||
},
|
},
|
||||||
extend: validator({
|
extend: validator({
|
||||||
schema: KomootSchema,
|
schema: KomootSchema,
|
||||||
}),
|
}),
|
||||||
onSubmit: async (form) => {
|
onSubmit: async (form) => {
|
||||||
form.active = integration?.komoot?.active ?? form.active
|
form.active = integration?.komoot?.active ?? form.active;
|
||||||
onsave?.(form);
|
onsave?.(form);
|
||||||
modal.closeModal();
|
modal.closeModal();
|
||||||
},
|
},
|
||||||
@@ -66,6 +69,14 @@
|
|||||||
type="password"
|
type="password"
|
||||||
error={$errors.password}
|
error={$errors.password}
|
||||||
></TextField>
|
></TextField>
|
||||||
|
<div class="flex gap-x-4">
|
||||||
|
<Toggle name="planned" label={$_("completed-tours", { values: { n: 2 } })}
|
||||||
|
></Toggle>
|
||||||
|
<Toggle
|
||||||
|
name="completed"
|
||||||
|
label={$_("planned-tours", { values: { n: 2 } })}
|
||||||
|
></Toggle>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
{#snippet footer()}
|
{#snippet footer()}
|
||||||
|
|||||||
Reference in New Issue
Block a user