2022-09-11 01:25:56 +02:00
|
|
|
import {OsmObject} from "../OsmObject"
|
2021-10-04 03:12:42 +02:00
|
|
|
import OsmChangeAction from "./OsmChangeAction"
|
2022-09-11 01:25:56 +02:00
|
|
|
import {Changes} from "../Changes"
|
|
|
|
import {ChangeDescription} from "./ChangeDescription"
|
2021-10-04 03:12:42 +02:00
|
|
|
import ChangeTagAction from "./ChangeTagAction"
|
2022-09-11 01:25:56 +02:00
|
|
|
import {TagsFilter} from "../../Tags/TagsFilter"
|
|
|
|
import {And} from "../../Tags/And"
|
|
|
|
import {Tag} from "../../Tags/Tag"
|
2022-09-12 20:33:41 +02:00
|
|
|
import {Utils} from "../../../Utils";
|
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"
|
|
|
|
}
|
2021-06-30 18:48:23 +02:00
|
|
|
private readonly _id: string
|
2021-10-04 03:12:42 +02:00
|
|
|
private _hardDelete: boolean
|
2022-09-08 21:40:48 +02:00
|
|
|
|
2021-10-04 03:12:42 +02:00
|
|
|
constructor(
|
|
|
|
id: string,
|
|
|
|
softDeletionTags: TagsFilter,
|
|
|
|
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-11 01:25:56 +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-12 20:33:41 +02:00
|
|
|
this._softDeletionTags = new And(Utils.NoNull([
|
2022-09-11 01:25:56 +02:00
|
|
|
softDeletionTags,
|
|
|
|
new Tag(
|
|
|
|
"fixme",
|
|
|
|
`A mapcomplete user marked this feature to be deleted (${meta.specialMotivation})`
|
|
|
|
),
|
2022-09-12 20:33:41 +02:00
|
|
|
]))
|
2022-09-11 01:25:56 +02:00
|
|
|
}
|
2021-07-01 02:26:45 +02:00
|
|
|
}
|
2021-06-30 18:48:23 +02:00
|
|
|
|
2021-12-23 03:36:03 +01:00
|
|
|
public async CreateChangeDescriptions(changes: Changes): Promise<ChangeDescription[]> {
|
2021-10-04 03:12:42 +02:00
|
|
|
const osmObject = await OsmObject.DownloadObjectAsync(this._id)
|
|
|
|
|
|
|
|
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",
|
|
|
|
}).CreateChangeDescriptions(changes)
|
2021-06-30 18:48:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|