| 
									
										
										
										
											2022-09-14 13:39:52 +02:00
										 |  |  | import { OsmObject } from "../OsmObject" | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  | import OsmChangeAction from "./OsmChangeAction" | 
					
						
							| 
									
										
										
										
											2022-09-14 13:39:52 +02:00
										 |  |  | import { Changes } from "../Changes" | 
					
						
							|  |  |  | import { ChangeDescription } from "./ChangeDescription" | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  | import ChangeTagAction from "./ChangeTagAction" | 
					
						
							| 
									
										
										
										
											2022-10-27 01:50:41 +02:00
										 |  |  | import { TagsFilter } from "../../Tags/TagsFilter" | 
					
						
							|  |  |  | import { And } from "../../Tags/And" | 
					
						
							|  |  |  | import { Tag } from "../../Tags/Tag" | 
					
						
							|  |  |  | import { OsmId } from "../../../Models/OsmFeature" | 
					
						
							| 
									
										
										
										
											2022-09-14 13:39:52 +02:00
										 |  |  | import { Utils } from "../../../Utils" | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | import OsmObjectDownloader from "../OsmObjectDownloader" | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class DeleteAction extends OsmChangeAction { | 
					
						
							|  |  |  |     private readonly _softDeletionTags: TagsFilter | 
					
						
							|  |  |  |     private readonly meta: { | 
					
						
							|  |  |  |         theme: string | 
					
						
							|  |  |  |         specialMotivation: string | 
					
						
							|  |  |  |         changeType: "deletion" | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-12 21:23:57 +02:00
										 |  |  |     private readonly _id: OsmId | 
					
						
							|  |  |  |     private readonly _hardDelete: boolean | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |     constructor( | 
					
						
							| 
									
										
										
										
											2022-09-12 21:23:57 +02:00
										 |  |  |         id: OsmId, | 
					
						
							|  |  |  |         softDeletionTags: TagsFilter | undefined, | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |         meta: { | 
					
						
							|  |  |  |             theme: string | 
					
						
							|  |  |  |             specialMotivation: string | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         hardDelete: boolean | 
					
						
							|  |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |         super(id, true) | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |         this._id = id | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |         this._hardDelete = hardDelete | 
					
						
							| 
									
										
										
										
											2022-09-14 13:39:52 +02:00
										 |  |  |         this.meta = { ...meta, changeType: "deletion" } | 
					
						
							| 
									
										
										
										
											2022-09-12 20:33:41 +02:00
										 |  |  |         if (softDeletionTags?.usedKeys()?.indexOf("fixme") >= 0) { | 
					
						
							| 
									
										
										
										
											2022-09-11 01:25:56 +02:00
										 |  |  |             this._softDeletionTags = softDeletionTags | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2022-09-14 13:39:52 +02:00
										 |  |  |             this._softDeletionTags = new And( | 
					
						
							|  |  |  |                 Utils.NoNull([ | 
					
						
							|  |  |  |                     softDeletionTags, | 
					
						
							| 
									
										
										
										
											2022-10-27 01:50:41 +02:00
										 |  |  |                     new Tag( | 
					
						
							|  |  |  |                         "fixme", | 
					
						
							|  |  |  |                         `A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})` | 
					
						
							|  |  |  |                     ), | 
					
						
							|  |  |  |                 ]) | 
					
						
							|  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2022-09-11 01:25:56 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-07-01 02:26:45 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-12 21:23:57 +02:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * import {OsmNode} from "../OsmObject" | 
					
						
							| 
									
										
										
										
											2023-04-13 20:58:49 +02:00
										 |  |  |      * import { ImmutableStore } from "../../UIEventSource"; | 
					
						
							|  |  |  |      * import { OsmConnection } from "../OsmConnection"; | 
					
						
							| 
									
										
										
										
											2022-09-12 21:23:57 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * const obj : OsmNode= new OsmNode(1) | 
					
						
							|  |  |  |      * obj.tags = {id:"node/1",name:"Monte Piselli - San Giacomo"} | 
					
						
							|  |  |  |      * const da = new DeleteAction("node/1", new Tag("man_made",""), {theme: "test", specialMotivation: "Testcase"}, true) | 
					
						
							| 
									
										
										
										
											2023-04-13 20:58:49 +02:00
										 |  |  |      * const state = { dryRun: new ImmutableStore(true), osmConnection: new OsmConnection() } | 
					
						
							|  |  |  |      * const descr = await da.CreateChangeDescriptions(new Changes(state), obj) | 
					
						
							| 
									
										
										
										
											2022-09-12 21:23:57 +02:00
										 |  |  |      * descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase",changeType: "deletion"}, type: "node",id: 1 }
 | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * // Must not crash if softDeletionTags are undefined
 | 
					
						
							|  |  |  |      * const da = new DeleteAction("node/1", undefined, {theme: "test", specialMotivation: "Testcase"}, true) | 
					
						
							|  |  |  |      * const obj : OsmNode= new OsmNode(1) | 
					
						
							|  |  |  |      * obj.tags = {id:"node/1",name:"Monte Piselli - San Giacomo"} | 
					
						
							| 
									
										
										
										
											2023-04-13 20:58:49 +02:00
										 |  |  |      * const state = { dryRun: new ImmutableStore(true), osmConnection: new OsmConnection() } | 
					
						
							|  |  |  |      * const descr = await da.CreateChangeDescriptions(new Changes(state), obj) | 
					
						
							| 
									
										
										
										
											2022-09-12 21:23:57 +02:00
										 |  |  |      * descr[0] // => {doDelete: true, meta: {theme: "test", specialMotivation: "Testcase", changeType: "deletion"}, type: "node",id: 1 }
 | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2022-10-27 01:50:41 +02:00
										 |  |  |     public async CreateChangeDescriptions( | 
					
						
							|  |  |  |         changes: Changes, | 
					
						
							|  |  |  |         object?: OsmObject | 
					
						
							|  |  |  |     ): Promise<ChangeDescription[]> { | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         const osmObject = | 
					
						
							|  |  |  |             object ?? | 
					
						
							|  |  |  |             (await new OsmObjectDownloader(changes.backend, changes).DownloadObjectAsync(this._id)) | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         if (osmObject === "deleted") { | 
					
						
							| 
									
										
										
										
											2023-04-20 03:58:31 +02:00
										 |  |  |             // already deleted in the meantime - no more changes necessary
 | 
					
						
							|  |  |  |             return [] | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |         if (this._hardDelete) { | 
					
						
							|  |  |  |             return [ | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     meta: this.meta, | 
					
						
							|  |  |  |                     doDelete: true, | 
					
						
							|  |  |  |                     type: osmObject.type, | 
					
						
							|  |  |  |                     id: osmObject.id, | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |                 }, | 
					
						
							|  |  |  |             ] | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |             return await new ChangeTagAction(this._id, this._softDeletionTags, osmObject.tags, { | 
					
						
							| 
									
										
										
										
											2022-01-26 21:40:38 +01:00
										 |  |  |                 ...this.meta, | 
					
						
							| 
									
										
										
										
											2021-10-04 03:12:42 +02:00
										 |  |  |                 changeType: "soft-delete", | 
					
						
							| 
									
										
										
										
											2023-04-07 03:54:11 +02:00
										 |  |  |             }).CreateChangeDescriptions() | 
					
						
							| 
									
										
										
										
											2021-06-30 18:48:23 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |