forked from MapComplete/MapComplete
		
	SpecialViz: tag_apply_button now works with a generic MR-id
This commit is contained in:
		
							parent
							
								
									a70336ee16
								
							
						
					
					
						commit
						f8644dd4ad
					
				
					 1 changed files with 23 additions and 16 deletions
				
			
		|  | @ -18,6 +18,9 @@ import { IndexedFeatureSource } from "../../Logic/FeatureSource/FeatureSource" | |||
| import { Feature } from "geojson" | ||||
| import LayerConfig from "../../Models/ThemeConfig/LayerConfig" | ||||
| import Maproulette from "../../Logic/Maproulette" | ||||
| import SvelteUIElement from "../Base/SvelteUIElement" | ||||
| import Icon from "../Map/Icon.svelte" | ||||
| import { Map } from "maplibre-gl" | ||||
| 
 | ||||
| export default class TagApplyButton implements AutoAction, SpecialVisualization { | ||||
|     public readonly funcName = "tag_apply" | ||||
|  | @ -45,9 +48,9 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
|             doc: "If specified, applies the the tags onto _another_ object. The id will be read from properties[id_of_object_to_apply_this_one] of the selected object. The tags are still calculated based on the tags of the _selected_ element", | ||||
|         }, | ||||
|         { | ||||
|             name: "maproulette_task_id", | ||||
|             name: "maproulette_id", | ||||
|             defaultValue: undefined, | ||||
|             doc: "If specified, this maproulette-challenge will be closed when the tags are applied", | ||||
|             doc: "If specified, this maproulette-challenge will be closed when the tags are applied. This should be the ID of the task, _not_ the task_id.", | ||||
|         }, | ||||
|     ] | ||||
|     public readonly example = | ||||
|  | @ -81,7 +84,7 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
|             for (const [key, value] of tgsSpec) { | ||||
|                 if (value.indexOf("$") >= 0) { | ||||
|                     let parts = value.split("$") | ||||
|                     // THe first of the split won't start with a '$', so no substitution needed
 | ||||
|                     // The first item of the split won't start with a '$', so no substitution needed
 | ||||
|                     let actualValue = parts[0] | ||||
|                     parts.shift() | ||||
| 
 | ||||
|  | @ -111,7 +114,6 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
| 
 | ||||
|         while (spec.length > 0) { | ||||
|             const [part] = spec.match(/((\\;)|[^;])*/) | ||||
|             console.log("Spec is", part, spec) | ||||
|             spec = spec.substring(part.length + 1) // +1 to remove the pending ';' as well
 | ||||
|             const kv = part.split("=").map((s) => s.trim().replace("\\;", ";")) | ||||
|             if (kv.length == 2) { | ||||
|  | @ -133,12 +135,8 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
|     } | ||||
| 
 | ||||
|     public async applyActionOn( | ||||
|         feature: Feature, | ||||
|         state: { | ||||
|             layout: LayoutConfig | ||||
|             changes: Changes | ||||
|             indexedFeatures: IndexedFeatureSource | ||||
|         }, | ||||
|         _: Feature, | ||||
|         state: SpecialVisualizationState, | ||||
|         tags: UIEventSource<any>, | ||||
|         args: string[] | ||||
|     ): Promise<void> { | ||||
|  | @ -156,14 +154,22 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
|             } | ||||
|         ) | ||||
|         await state.changes.applyAction(changeAction) | ||||
|         try { | ||||
|             state.selectedElement.setData(state.indexedFeatures.featuresById.data.get(targetId)) | ||||
|         }catch (e) { | ||||
|             console.error(e) | ||||
|         } | ||||
|         const maproulette_id_key = args[4] | ||||
|         if (maproulette_id_key) { | ||||
|             const maproulette_id = Number(tags.data[maproulette_id_key]) | ||||
|             await Maproulette.singleton.closeTask(maproulette_id, Maproulette.STATUS_FIXED, { | ||||
|             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, { | ||||
|                 comment: "Tags are copied onto " + targetId + " with MapComplete", | ||||
|             }) | ||||
|             tags.data["mr_taskStatus"] = "Fixed" | ||||
|             tags.ping() | ||||
|             maproulette_feature.properties["mr_taskStatus"] = "Fixed" | ||||
|             state.featureProperties.getStore(maproulette_id).ping() | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -180,6 +186,7 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
|         if (image === "" || image === "undefined") { | ||||
|             image = undefined | ||||
|         } | ||||
| 
 | ||||
|         const targetIdKey = args[3] | ||||
|         const t = Translations.t.general.apply_button | ||||
| 
 | ||||
|  | @ -195,9 +202,9 @@ export default class TagApplyButton implements AutoAction, SpecialVisualization | |||
|             }) | ||||
|         ).SetClass("subtle") | ||||
|         const self = this | ||||
|         const applied = new UIEventSource(tags?.data?.["mr_taskStatus"] !== "Created") // This will default to 'false' for non-maproulette challenges
 | ||||
|         const applied = new UIEventSource(tags?.data?.["mr_taskStatus"] !== undefined && tags?.data?.["mr_taskStatus"] !== "Created") // This will default to 'false' for non-maproulette challenges
 | ||||
|         const applyButton = new SubtleButton( | ||||
|             image, | ||||
|             new SvelteUIElement(Icon, {icon: image}), | ||||
|             new Combine([msg, tagsExplanation]).SetClass("flex flex-col") | ||||
|         ).onClick(async () => { | ||||
|             applied.setData(true) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue