2024-01-13 05:24:56 +01:00
|
|
|
<script lang="ts">
|
2024-04-09 15:12:18 +02:00
|
|
|
import LinkableImage from "../Image/LinkableImage.svelte"
|
2024-04-22 18:16:19 +02:00
|
|
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
2024-04-09 15:12:18 +02:00
|
|
|
import type { OsmTags } from "../../Models/OsmFeature"
|
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import type { Feature } from "geojson"
|
|
|
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
|
|
|
import ComparisonAction from "./ComparisonAction.svelte"
|
|
|
|
import Party from "../../assets/svg/Party.svelte"
|
|
|
|
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"
|
|
|
|
import { Tag } from "../../Logic/Tags/Tag"
|
|
|
|
import { And } from "../../Logic/Tags/And"
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import AttributedImage from "../Image/AttributedImage.svelte"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import Tr from "../Base/Tr.svelte"
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-22 18:16:19 +02:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
export let externalProperties: Record<string, string>
|
2024-04-22 18:16:19 +02:00
|
|
|
delete externalProperties["@context"]
|
|
|
|
console.log("External properties are", externalProperties)
|
2024-04-09 15:12:18 +02:00
|
|
|
export let sourceUrl: string
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
export let tags: UIEventSource<OsmTags>
|
|
|
|
export let state: SpecialVisualizationState
|
|
|
|
export let feature: Feature
|
|
|
|
export let layer: LayerConfig
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
export let readonly = false
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
const t = Translations.t.external
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
let externalKeys: string[] = Object.keys(externalProperties).sort()
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
const imageKeyRegex = /image|image:[0-9]+/
|
2024-04-22 18:16:19 +02:00
|
|
|
let knownImages: Store<Set<string>> = tags.map(osmProperties => new Set(
|
2024-04-09 15:12:18 +02:00
|
|
|
Object.keys(osmProperties)
|
|
|
|
.filter((k) => k.match(imageKeyRegex))
|
|
|
|
.map((k) => osmProperties[k])
|
2024-04-22 18:16:19 +02:00
|
|
|
))
|
|
|
|
let unknownImages: Store<string[]> = knownImages.map(images => externalKeys
|
2024-04-09 15:12:18 +02:00
|
|
|
.filter((k) => k.match(imageKeyRegex))
|
|
|
|
.map((k) => externalProperties[k])
|
2024-04-22 18:16:19 +02:00
|
|
|
.filter((i) => !images.has(i)))
|
|
|
|
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-09 15:12:18 +02:00
|
|
|
let propertyKeysExternal = externalKeys.filter((k) => k.match(imageKeyRegex) === null)
|
2024-04-22 18:16:19 +02:00
|
|
|
let missing: Store<string[]> = tags.map(osmProperties => propertyKeysExternal.filter((k) => {
|
2024-04-10 14:10:28 +02:00
|
|
|
if (k.startsWith("_")) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return osmProperties[k] === undefined && typeof externalProperties[k] === "string"
|
2024-04-22 18:16:19 +02:00
|
|
|
}))
|
2024-04-09 15:12:18 +02:00
|
|
|
// let same = propertyKeysExternal.filter((key) => osmProperties[key] === externalProperties[key])
|
2024-04-22 18:16:19 +02:00
|
|
|
let different: Store<string[]> = tags.map(osmProperties => propertyKeysExternal.filter((key) => {
|
2024-04-13 02:40:21 +02:00
|
|
|
if (key.startsWith("_")) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (osmProperties[key] === undefined) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (typeof externalProperties[key] !== "string") {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (osmProperties[key] === externalProperties[key]) {
|
|
|
|
return false
|
|
|
|
}
|
2024-02-20 13:33:38 +01:00
|
|
|
|
2024-04-13 02:40:21 +02:00
|
|
|
if (key === "website") {
|
|
|
|
const osmCanon = new URL(osmProperties[key]).toString()
|
|
|
|
const externalCanon = new URL(externalProperties[key]).toString()
|
|
|
|
if (osmCanon === externalCanon) {
|
|
|
|
return false
|
2024-04-09 15:12:18 +02:00
|
|
|
}
|
2024-03-01 00:50:19 +01:00
|
|
|
}
|
2024-04-13 02:40:21 +02:00
|
|
|
|
|
|
|
return true
|
2024-04-22 18:16:19 +02:00
|
|
|
}))
|
|
|
|
|
|
|
|
let hasDifferencesAtStart = (different.data.length + missing.data.length + unknownImages.data.length) > 0
|
2024-04-09 15:12:18 +02:00
|
|
|
|
|
|
|
let currentStep: "init" | "applying_all" | "all_applied" = "init"
|
|
|
|
let applyAllHovered = false
|
|
|
|
|
|
|
|
async function applyAllMissing() {
|
|
|
|
currentStep = "applying_all"
|
2024-04-22 18:16:19 +02:00
|
|
|
const tagsToApply = missing.data.map((k) => new Tag(k, externalProperties[k]))
|
2024-04-09 15:12:18 +02:00
|
|
|
const change = new ChangeTagAction(tags.data.id, new And(tagsToApply), tags.data, {
|
|
|
|
theme: state.layout.id,
|
2024-04-22 18:16:19 +02:00
|
|
|
changeType: "import"
|
2024-04-09 15:12:18 +02:00
|
|
|
})
|
|
|
|
await state.changes.applyChanges(await change.CreateChangeDescriptions())
|
|
|
|
currentStep = "all_applied"
|
|
|
|
}
|
2024-03-01 00:50:19 +01:00
|
|
|
</script>
|
2024-04-22 18:16:19 +02:00
|
|
|
{#if propertyKeysExternal.length === 0 && $knownImages.size + $unknownImages.length === 0}
|
2024-04-10 14:10:28 +02:00
|
|
|
<Tr cls="subtle" t={t.noDataLoaded} />
|
2024-04-22 18:16:19 +02:00
|
|
|
{:else if !hasDifferencesAtStart}
|
|
|
|
<span class="subtle text-sm">
|
|
|
|
<Tr t={t.allIncluded.Subs({source:sourceUrl})}/>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
{:else if $unknownImages.length === 0 && $missing.length === 0 && $different.length === 0}
|
2024-02-20 13:33:38 +01:00
|
|
|
<div class="thanks m-0 flex items-center gap-x-2 px-2">
|
2024-04-22 18:16:19 +02:00
|
|
|
<Party class="h-8 w-8 shrink-0" />
|
|
|
|
<Tr t={t.allIncluded.Subs({source: sourceUrl})} />
|
2024-01-13 05:24:56 +01:00
|
|
|
</div>
|
2024-03-01 00:50:19 +01:00
|
|
|
{:else}
|
2024-04-13 02:40:21 +02:00
|
|
|
<div class="low-interaction border-interactive p-1">
|
2024-04-05 17:49:31 +02:00
|
|
|
{#if !readonly}
|
2024-04-13 02:40:21 +02:00
|
|
|
<Tr t={t.loadedFrom.Subs({ url: sourceUrl, source: sourceUrl })} />
|
2024-04-05 17:49:31 +02:00
|
|
|
<h3>
|
|
|
|
<Tr t={t.conflicting.title} />
|
|
|
|
</h3>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<div class="flex flex-col" class:gap-y-8={!readonly}>
|
|
|
|
{#if !readonly}
|
|
|
|
<Tr t={t.conflicting.intro} />
|
|
|
|
{/if}
|
2024-04-22 18:16:19 +02:00
|
|
|
{#if $different.length > 0}
|
|
|
|
{#each $different as key}
|
2024-03-01 00:50:19 +01:00
|
|
|
<div class="mx-2 rounded-2xl">
|
2024-04-13 02:40:21 +02:00
|
|
|
<ComparisonAction
|
|
|
|
{key}
|
|
|
|
{state}
|
|
|
|
{tags}
|
|
|
|
{externalProperties}
|
|
|
|
{layer}
|
|
|
|
{feature}
|
|
|
|
{readonly}
|
|
|
|
/>
|
2024-03-01 00:50:19 +01:00
|
|
|
</div>
|
2024-01-16 04:21:11 +01:00
|
|
|
{/each}
|
2024-03-01 00:50:19 +01:00
|
|
|
{/if}
|
|
|
|
|
2024-04-22 18:16:19 +02:00
|
|
|
{#if $missing.length > 0}
|
2024-03-01 00:50:19 +01:00
|
|
|
{#if currentStep === "init"}
|
2024-04-22 18:16:19 +02:00
|
|
|
{#each $missing as key}
|
2024-03-01 00:50:19 +01:00
|
|
|
<div class:glowing-shadow={applyAllHovered} class="mx-2 rounded-2xl">
|
2024-04-13 02:40:21 +02:00
|
|
|
<ComparisonAction
|
|
|
|
{key}
|
|
|
|
{state}
|
|
|
|
{tags}
|
|
|
|
{externalProperties}
|
|
|
|
{layer}
|
|
|
|
{feature}
|
|
|
|
{readonly}
|
|
|
|
/>
|
2024-03-01 00:50:19 +01:00
|
|
|
</div>
|
|
|
|
{/each}
|
2024-04-22 18:16:19 +02:00
|
|
|
{#if !readonly && $missing.length > 1}
|
2024-04-13 02:40:21 +02:00
|
|
|
<button
|
|
|
|
on:click={() => applyAllMissing()}
|
|
|
|
on:mouseover={() => (applyAllHovered = true)}
|
|
|
|
on:focus={() => (applyAllHovered = true)}
|
|
|
|
on:blur={() => (applyAllHovered = false)}
|
|
|
|
on:mouseout={() => (applyAllHovered = false)}
|
2024-03-01 00:50:19 +01:00
|
|
|
>
|
|
|
|
<Tr t={t.applyAll} />
|
|
|
|
</button>
|
|
|
|
{/if}
|
|
|
|
{:else if currentStep === "applying_all"}
|
2024-04-05 17:49:31 +02:00
|
|
|
<Loading />
|
2024-03-01 00:50:19 +01:00
|
|
|
{:else if currentStep === "all_applied"}
|
|
|
|
<div class="thanks">
|
|
|
|
<Tr t={t.allAreApplied} />
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/if}
|
2024-01-16 04:21:11 +01:00
|
|
|
</div>
|
2024-03-01 00:50:19 +01:00
|
|
|
|
2024-04-22 18:16:19 +02:00
|
|
|
{#if $unknownImages.length > 0}
|
2024-03-01 00:50:19 +01:00
|
|
|
{#if readonly}
|
|
|
|
<div class="w-full overflow-x-auto">
|
|
|
|
<div class="flex h-32 w-max gap-x-2">
|
2024-04-22 18:16:19 +02:00
|
|
|
{#each $unknownImages as image}
|
2024-03-01 00:50:19 +01:00
|
|
|
<AttributedImage
|
|
|
|
imgClass="h-32 w-max shrink-0"
|
|
|
|
image={{ url: image }}
|
|
|
|
previewedImage={state.previewedImage}
|
|
|
|
/>
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{:else}
|
2024-04-22 18:16:19 +02:00
|
|
|
{#each $unknownImages as image}
|
2024-03-01 00:50:19 +01:00
|
|
|
<LinkableImage
|
|
|
|
{tags}
|
|
|
|
{state}
|
|
|
|
image={{
|
2024-04-13 02:40:21 +02:00
|
|
|
pictureUrl: image,
|
|
|
|
provider: "Velopark",
|
|
|
|
thumbUrl: image,
|
|
|
|
details: undefined,
|
|
|
|
coordinates: undefined,
|
|
|
|
osmTags: { image },
|
|
|
|
}}
|
2024-03-01 00:50:19 +01:00
|
|
|
{feature}
|
|
|
|
{layer}
|
|
|
|
/>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
{/if}
|
2024-04-10 14:10:28 +02:00
|
|
|
{#if externalProperties["_last_edit_timestamp"] !== undefined}
|
|
|
|
<span class="subtle text-sm">
|
2024-04-13 02:40:21 +02:00
|
|
|
External data has been last modified on {externalProperties["_last_edit_timestamp"]}
|
2024-04-10 14:10:28 +02:00
|
|
|
</span>
|
|
|
|
{/if}
|
2024-03-01 00:50:19 +01:00
|
|
|
</div>
|
2024-01-13 05:24:56 +01:00
|
|
|
{/if}
|