From b47d0f8c6add387af6d903b76a9ac74eeda24608 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 11 Dec 2024 22:41:33 +0100 Subject: [PATCH] Feature: include username of the person closing a maproulette note --- src/Logic/Maproulette.ts | 13 ++++++++++--- src/UI/MapRoulette/MaprouletteSetStatus.svelte | 3 +-- src/UI/Popup/ImportButtons/PointImportFlowState.ts | 6 ++---- src/UI/Popup/TagApplyButton.ts | 2 +- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Logic/Maproulette.ts b/src/Logic/Maproulette.ts index 87c56c9d3..fd561ede7 100644 --- a/src/Logic/Maproulette.ts +++ b/src/Logic/Maproulette.ts @@ -1,9 +1,12 @@ import Constants from "../Models/Constants" +import { SpecialVisualizationState } from "../UI/SpecialVisualization" + export interface MaprouletteTask { name: string description: string instruction: string } + export default class Maproulette { public static readonly defaultEndpoint = "https://maproulette.org/api/v2" @@ -24,7 +27,7 @@ export default class Maproulette { 4: "Deleted", 5: "Already fixed", 6: "Too_Hard", - 9: "Disabled", + 9: "Disabled" } public static singleton = new Maproulette() /* @@ -78,6 +81,7 @@ export default class Maproulette { async closeTask( taskId: number, status = Maproulette.STATUS_FIXED, + state: SpecialVisualizationState, options?: { comment?: string tags?: string @@ -86,13 +90,16 @@ export default class Maproulette { } ): Promise { console.log("Maproulette: setting", `${this.endpoint}/task/${taskId}/${status}`, options) + options ??= {} + const userdetails = state.osmConnection.userDetails.data + options.tags = `MapComplete MapComplete:${state.theme.id}; userid: ${userdetails?.uid}; username: ${userdetails?.name}` const response = await fetch(`${this.endpoint}/task/${taskId}/${status}`, { method: "PUT", headers: { "Content-Type": "application/json", - apiKey: this.apiKey, + apiKey: this.apiKey }, - body: options !== undefined ? JSON.stringify(options) : undefined, + body: JSON.stringify(options) }) if (response.status !== 204) { console.log(`Failed to close task: ${response.status}`) diff --git a/src/UI/MapRoulette/MaprouletteSetStatus.svelte b/src/UI/MapRoulette/MaprouletteSetStatus.svelte index f91835378..3ea6056e2 100644 --- a/src/UI/MapRoulette/MaprouletteSetStatus.svelte +++ b/src/UI/MapRoulette/MaprouletteSetStatus.svelte @@ -38,8 +38,7 @@ async function apply() { const maproulette_id = tags.data[maproulette_id_key] ?? tags.data.mr_taskId ?? tags.data.id try { - await Maproulette.singleton.closeTask(Number(maproulette_id), Number(statusToSet), { - tags: `MapComplete MapComplete:${state.theme.id}`, + await Maproulette.singleton.closeTask(Number(maproulette_id), Number(statusToSet), state, { comment: feedback, }) tags.data["mr_taskStatus"] = Maproulette.STATUS_MEANING[Number(statusToSet)] diff --git a/src/UI/Popup/ImportButtons/PointImportFlowState.ts b/src/UI/Popup/ImportButtons/PointImportFlowState.ts index d71ef2b8c..925eeea54 100644 --- a/src/UI/Popup/ImportButtons/PointImportFlowState.ts +++ b/src/UI/Popup/ImportButtons/PointImportFlowState.ts @@ -19,7 +19,6 @@ export interface PointImportFlowArguments extends ImportFlowArguments { export class PointImportFlowState extends ImportFlow { public readonly startCoordinate: [number, number] - private readonly _originalFeature: Feature constructor( state: SpecialVisualizationState, @@ -29,7 +28,6 @@ export class PointImportFlowState extends ImportFlow { originalFeatureTags: UIEventSource> ) { super(state, args, tagsToApply, originalFeatureTags) - this._originalFeature = originalFeature this.startCoordinate = GeoOperations.centerpointCoordinates(originalFeature) } @@ -80,7 +78,7 @@ export class PointImportFlowState extends ImportFlow { originalFeatureTags.ping() } - let maproulette_id = originalFeatureTags.data[this.args.maproulette_id] + const maproulette_id = originalFeatureTags.data[this.args.maproulette_id] if (maproulette_id !== undefined) { if (this.state.featureSwitchIsTesting.data) { console.log( @@ -90,7 +88,7 @@ export class PointImportFlowState extends ImportFlow { ) } else { console.log("Marking maproulette task as fixed") - await Maproulette.singleton.closeTask(Number(maproulette_id)) + await Maproulette.singleton.closeTask(Number(maproulette_id), Maproulette.STATUS_FIXED, this.state) originalFeatureTags.data["mr_taskStatus"] = "Fixed" originalFeatureTags.ping() } diff --git a/src/UI/Popup/TagApplyButton.ts b/src/UI/Popup/TagApplyButton.ts index 7389dd0de..8571274a3 100644 --- a/src/UI/Popup/TagApplyButton.ts +++ b/src/UI/Popup/TagApplyButton.ts @@ -159,7 +159,7 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization const maproulette_id = tags.data[maproulette_id_key] const maproulette_feature = state.indexedFeatures.featuresById.data.get(maproulette_id) const maproulette_task_id = Number(maproulette_feature.properties.mr_taskId) - await Maproulette.singleton.closeTask(maproulette_task_id, Maproulette.STATUS_FIXED, { + await Maproulette.singleton.closeTask(maproulette_task_id, Maproulette.STATUS_FIXED, state, { comment: "Tags are copied onto " + targetId + " with MapComplete", }) maproulette_feature.properties["mr_taskStatus"] = "Fixed"