2023-12-09 16:52:15 +01:00
|
|
|
<script lang="ts">
|
2023-12-19 22:08:00 +01:00
|
|
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
|
|
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
|
|
|
import Loading from "../../assets/svg/Loading.svelte"
|
|
|
|
import Tr from "../Base/Tr.svelte"
|
|
|
|
import Translations from "../i18n/Translations"
|
|
|
|
import Icon from "../Map/Icon.svelte"
|
|
|
|
import Maproulette from "../../Logic/Maproulette"
|
2023-12-09 16:52:15 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A UI-element to change the status of a maproulette-task
|
|
|
|
*/
|
2023-12-19 22:08:00 +01:00
|
|
|
export let state: SpecialVisualizationState
|
|
|
|
export let tags: UIEventSource<Record<string, string>>
|
|
|
|
export let message: string
|
|
|
|
export let image: string
|
|
|
|
export let message_closed: string
|
|
|
|
export let statusToSet: string
|
|
|
|
export let maproulette_id_key: string
|
2023-12-09 16:52:15 +01:00
|
|
|
|
2023-12-19 22:08:00 +01:00
|
|
|
let applying = false
|
|
|
|
let failed = false
|
2023-12-09 16:52:15 +01:00
|
|
|
|
|
|
|
/** Current status of the task*/
|
|
|
|
let status: Store<number> = tags
|
|
|
|
.map((tgs) => {
|
|
|
|
if (tgs["status"]) {
|
2023-12-19 22:08:00 +01:00
|
|
|
return tgs["status"]
|
2023-12-09 16:52:15 +01:00
|
|
|
}
|
2023-12-19 22:08:00 +01:00
|
|
|
return Maproulette.codeToIndex(tgs["mr_taskStatus"])
|
|
|
|
})
|
|
|
|
.map(Number)
|
2023-12-09 16:52:15 +01:00
|
|
|
|
|
|
|
async function apply() {
|
2023-12-19 22:08:00 +01:00
|
|
|
const maproulette_id = tags.data[maproulette_id_key] ?? tags.data.mr_taskId ?? tags.data.id
|
2023-12-09 16:52:15 +01:00
|
|
|
try {
|
2023-12-19 22:08:00 +01:00
|
|
|
await Maproulette.singleton.closeTask(Number(maproulette_id), Number(statusToSet), {
|
|
|
|
tags: `MapComplete MapComplete:${state.layout.id}`,
|
|
|
|
})
|
|
|
|
tags.data["mr_taskStatus"] = Maproulette.STATUS_MEANING[Number(statusToSet)]
|
|
|
|
tags.data.status = statusToSet
|
|
|
|
tags.ping()
|
2023-12-09 16:52:15 +01:00
|
|
|
} catch (e) {
|
2023-12-19 22:08:00 +01:00
|
|
|
console.error(e)
|
|
|
|
failed = true
|
2023-12-09 16:52:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if failed}
|
2023-12-19 22:08:00 +01:00
|
|
|
<div class="alert">ERROR - could not close the MapRoulette task</div>
|
2023-12-09 16:52:15 +01:00
|
|
|
{:else if applying}
|
|
|
|
<Loading>
|
|
|
|
<Tr t={Translations.t.general.loading} />
|
|
|
|
</Loading>
|
|
|
|
{:else if $status === Maproulette.STATUS_OPEN}
|
2023-12-19 22:08:00 +01:00
|
|
|
<button class="no-image-background w-full p-4" on:click={() => apply()}>
|
2023-12-09 16:52:15 +01:00
|
|
|
<Icon clss="w-8 h-8 mr-2" icon={image} />
|
|
|
|
{message}
|
|
|
|
</button>
|
|
|
|
{:else}
|
|
|
|
{message_closed}
|
|
|
|
{/if}
|