2023-06-04 00:43:32 +02:00
|
|
|
<script lang="ts">
|
2023-06-14 20:39:36 +02:00
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import { ArrowDownTrayIcon } from "@babeard/svelte-heroicons/mini"
|
|
|
|
import Tr from "../Base/Tr.svelte"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import Loading from "../Base/Loading.svelte"
|
|
|
|
import { Translation } from "../i18n/Translation"
|
|
|
|
import { Utils } from "../../Utils"
|
|
|
|
import type { PriviligedLayerType } from "../../Models/Constants"
|
|
|
|
import { UIEventSource } from "../../Logic/UIEventSource"
|
2023-06-04 00:43:32 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
export let state: SpecialVisualizationState
|
2023-06-04 00:43:32 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
export let extension: string
|
|
|
|
export let mimetype: string
|
2024-04-13 02:40:21 +02:00
|
|
|
export let construct: (title: string, status?: UIEventSource<string>) => Promise<Blob | string>
|
2023-06-14 20:39:36 +02:00
|
|
|
export let mainText: Translation
|
|
|
|
export let helperText: Translation
|
2023-06-04 00:43:32 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
const t = Translations.t.general.download
|
2023-06-04 00:43:32 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
let isExporting = false
|
|
|
|
let isError = false
|
2023-06-04 00:43:32 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
let status: UIEventSource<string> = new UIEventSource<string>(undefined)
|
|
|
|
async function clicked() {
|
|
|
|
isExporting = true
|
2024-04-13 02:40:21 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
const gpsLayer = state.layerState.filteredLayers.get(<PriviligedLayerType>"gps_location")
|
2023-11-14 17:35:50 +01:00
|
|
|
state.userRelatedState.preferencesAsTags.data["__showTimeSensitiveIcons"] = "no"
|
|
|
|
state.userRelatedState.preferencesAsTags.ping()
|
2023-06-14 20:39:36 +02:00
|
|
|
const gpsIsDisplayed = gpsLayer.isDisplayed.data
|
|
|
|
try {
|
|
|
|
gpsLayer.isDisplayed.setData(false)
|
|
|
|
const name = state.layout.id
|
2023-06-04 00:43:32 +02:00
|
|
|
|
2023-06-14 20:39:36 +02:00
|
|
|
const title = `MapComplete_${name}_export_${new Date()
|
|
|
|
.toISOString()
|
|
|
|
.substr(0, 19)}.${extension}`
|
2024-02-21 16:35:49 +01:00
|
|
|
const data: Blob | string = await construct(title, status)
|
2023-06-14 20:39:36 +02:00
|
|
|
if (!data) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
console.log("Got data", data)
|
|
|
|
Utils.offerContentsAsDownloadableFile(data, title, {
|
|
|
|
mimetype,
|
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
isError = true
|
|
|
|
console.error(e)
|
|
|
|
} finally {
|
|
|
|
isExporting = false
|
|
|
|
gpsLayer.isDisplayed.setData(gpsIsDisplayed)
|
2023-11-14 17:35:50 +01:00
|
|
|
state.userRelatedState.preferencesAsTags.data["__showTimeSensitiveIcons"] = "yes"
|
|
|
|
state.userRelatedState.preferencesAsTags.ping()
|
2023-06-04 00:43:32 +02:00
|
|
|
}
|
2023-06-14 20:39:36 +02:00
|
|
|
}
|
2023-06-04 00:43:32 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if isError}
|
2023-06-14 20:39:36 +02:00
|
|
|
<Tr cls="alert" t={Translations.t.general.error} />
|
2023-06-04 00:43:32 +02:00
|
|
|
{:else if isExporting}
|
2023-06-14 20:39:36 +02:00
|
|
|
<Loading>
|
|
|
|
{#if $status}
|
|
|
|
{$status}
|
|
|
|
{:else}
|
|
|
|
<Tr t={t.exporting} />
|
|
|
|
{/if}
|
|
|
|
</Loading>
|
2023-06-04 00:43:32 +02:00
|
|
|
{:else}
|
2024-06-17 04:27:08 +02:00
|
|
|
<button class="w-full" style="justify-content: start" on:click={clicked}>
|
2023-06-14 20:39:36 +02:00
|
|
|
<slot name="image">
|
2023-06-14 20:44:01 +02:00
|
|
|
<ArrowDownTrayIcon class="mr-2 h-12 w-12 shrink-0" />
|
2023-06-14 20:39:36 +02:00
|
|
|
</slot>
|
|
|
|
<span class="flex flex-col items-start">
|
|
|
|
<Tr t={mainText} />
|
|
|
|
<Tr t={helperText} cls="subtle" />
|
|
|
|
</span>
|
|
|
|
</button>
|
2023-06-04 00:43:32 +02:00
|
|
|
{/if}
|