First version of a delete button, is working
This commit is contained in:
parent
de5f8f95bb
commit
e4c29ce660
13 changed files with 309 additions and 136 deletions
47
Customizations/JSON/DeleteConfig.ts
Normal file
47
Customizations/JSON/DeleteConfig.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import {DeleteConfigJson} from "./DeleteConfigJson";
|
||||
import {Translation} from "../../UI/i18n/Translation";
|
||||
import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
||||
import Translations from "../../UI/i18n/Translations";
|
||||
import {FromJSON} from "./FromJSON";
|
||||
|
||||
export default class DeleteConfig {
|
||||
public readonly extraDeleteReasons?: {
|
||||
explanation: Translation,
|
||||
changesetMessage: string
|
||||
}[]
|
||||
|
||||
public readonly nonDeleteMappings?: { if: TagsFilter, then: Translation }[]
|
||||
|
||||
public readonly softDeletionTags?: TagsFilter
|
||||
public readonly neededChangesets?: number
|
||||
|
||||
constructor(json: DeleteConfigJson, context: string) {
|
||||
|
||||
this.extraDeleteReasons = json.extraDeleteReasons?.map((reason, i) => {
|
||||
const ctx = `${context}.extraDeleteReasons[${i}]`
|
||||
if ((reason.changesetMessage ?? "").length <= 5) {
|
||||
throw `${ctx}.explanation is too short, needs at least 4 characters`
|
||||
}
|
||||
return {
|
||||
explanation: Translations.T(reason.explanation, ctx + ".explanation"),
|
||||
changesetMessage: reason.changesetMessage
|
||||
}
|
||||
})
|
||||
this.nonDeleteMappings = json.nonDeleteMappings?.map((nonDelete, i) => {
|
||||
const ctx = `${context}.extraDeleteReasons[${i}]`
|
||||
return {
|
||||
if: FromJSON.Tag(nonDelete.if, ctx + ".if"),
|
||||
then: Translations.T(nonDelete.then, ctx + ".then")
|
||||
}
|
||||
})
|
||||
|
||||
this.softDeletionTags = null;
|
||||
if(json.softDeletionTags !== undefined){
|
||||
this.softDeletionTags = FromJSON.Tag(json.softDeletionTags,`${context}.softDeletionTags`)
|
||||
|
||||
}
|
||||
this.neededChangesets = json.neededChangesets
|
||||
}
|
||||
|
||||
|
||||
}
|
66
Customizations/JSON/DeleteConfigJson.ts
Normal file
66
Customizations/JSON/DeleteConfigJson.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
|
||||
export interface DeleteConfigJson {
|
||||
|
||||
/***
|
||||
* By default, three reasons to delete a point are shown:
|
||||
*
|
||||
* - The point does not exist anymore
|
||||
* - The point was a testing point
|
||||
* - THe point could not be found
|
||||
*
|
||||
* However, for some layers, there might be different or more specific reasons for deletion which can be user friendly to set, e.g.:
|
||||
*
|
||||
* - the shop has closed
|
||||
* - the climbing route has been closed of for nature conservation reasons
|
||||
* - ...
|
||||
*
|
||||
* These reasons can be stated here and will be shown in the list of options the user can choose from
|
||||
*/
|
||||
extraDeleteReasons?: {
|
||||
/**
|
||||
* The text that will be shown to the user - translatable
|
||||
*/
|
||||
explanation: string | any,
|
||||
/**
|
||||
* The text that will be uploaded into the changeset or will be used in the fixme in case of a soft deletion
|
||||
* Should be a few words, in english
|
||||
*/
|
||||
changesetMessage: string
|
||||
}[]
|
||||
|
||||
/**
|
||||
* In some cases, a (starting) contributor might wish to delete a feature even though deletion is not appropriate.
|
||||
* (The most relevant case are small paths running over private property. These should be marked as 'private' instead of deleted, as the community might trace the path again from aerial imagery, gettting us back to the original situation).
|
||||
*
|
||||
* By adding a 'nonDeleteMapping', an option can be added into the list which will retag the feature.
|
||||
* It is important that the feature will be retagged in such a way that it won't be picked up by the layer anymore!
|
||||
*/
|
||||
nonDeleteMappings?: { if: AndOrTagConfigJson, then: string | any }[],
|
||||
|
||||
/**
|
||||
* In some cases, the contributor is not allowed to delete the current feature (e.g. because it isn't a point, the point is referenced by a relation or the user isn't experienced enough).
|
||||
* To still offer the user a 'delete'-option, the feature is retagged with these tags. This is a soft deletion, as the point isn't actually removed from OSM but rather marked as 'disused'
|
||||
* It is important that the feature will be retagged in such a way that it won't be picked up by the layer anymore!
|
||||
*
|
||||
* Example (note that "amenity=" erases the 'amenity'-key alltogether):
|
||||
* ```
|
||||
* {
|
||||
* "and": ["disussed:amenity=public_bookcase", "amenity="]
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* or (notice the use of the ':='-tag to copy the old value of 'shop=*' into 'disused:shop='):
|
||||
* ```
|
||||
* {
|
||||
* "and": ["disused:shop:={shop}", "shop="]
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
softDeletionTags?: AndOrTagConfigJson | string,
|
||||
/***
|
||||
* By default, the contributor needs 20 previous changesets to delete points edited by others.
|
||||
* For some small features (e.g. bicycle racks) this is too much and this requirement can be lowered or dropped, which can be done here.
|
||||
*/
|
||||
neededChangesets?: number
|
||||
}
|
|
@ -9,8 +9,11 @@ import SubstitutingTag from "../../Logic/Tags/SubstitutingTag";
|
|||
|
||||
export class FromJSON {
|
||||
|
||||
public static SimpleTag(json: string): Tag {
|
||||
public static SimpleTag(json: string, context?: string): Tag {
|
||||
const tag = Utils.SplitFirst(json, "=");
|
||||
if(tag.length !== 2){
|
||||
throw `Invalid tag: no (or too much) '=' found (in ${context ?? "unkown context"})`
|
||||
}
|
||||
return new Tag(tag[0], tag[1]);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import {TagsFilter} from "../../Logic/Tags/TagsFilter";
|
|||
import {Tag} from "../../Logic/Tags/Tag";
|
||||
import BaseUIElement from "../../UI/BaseUIElement";
|
||||
import {Unit} from "./Denomination";
|
||||
import DeleteConfig from "./DeleteConfig";
|
||||
|
||||
export default class LayerConfig {
|
||||
|
||||
|
@ -47,6 +48,7 @@ export default class LayerConfig {
|
|||
dashArray: TagRenderingConfig;
|
||||
wayHandling: number;
|
||||
public readonly units: Unit[];
|
||||
public readonly deletion: DeleteConfig | null
|
||||
|
||||
presets: {
|
||||
title: Translation,
|
||||
|
@ -240,6 +242,15 @@ export default class LayerConfig {
|
|||
this.width = tr("width", "7");
|
||||
this.rotation = tr("rotation", "0");
|
||||
this.dashArray = tr("dashArray", "");
|
||||
|
||||
this.deletion = null;
|
||||
if(json.deletion === true){
|
||||
json.deletion = {
|
||||
}
|
||||
}
|
||||
if(json.deletion !== undefined && json.deletion !== false){
|
||||
this.deletion = new DeleteConfig(json.deletion, `${context}.deletion`)
|
||||
}
|
||||
|
||||
|
||||
if (json["showIf"] !== undefined) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {TagRenderingConfigJson} from "./TagRenderingConfigJson";
|
||||
import {AndOrTagConfigJson} from "./TagConfigJson";
|
||||
import {DeleteConfigJson} from "./DeleteConfigJson";
|
||||
|
||||
/**
|
||||
* Configuration for a single layer
|
||||
|
@ -14,7 +15,7 @@ export interface LayerConfigJson {
|
|||
/**
|
||||
* The name of this layer
|
||||
* Used in the layer control panel and the 'Personal theme'.
|
||||
*
|
||||
*
|
||||
* If not given, will be hidden (and thus not toggable) in the layer control
|
||||
*/
|
||||
name?: string | any
|
||||
|
@ -31,28 +32,28 @@ export interface LayerConfigJson {
|
|||
* There are some options:
|
||||
*
|
||||
* # Query OSM directly
|
||||
* source: {osmTags: "key=value"}
|
||||
* source: {osmTags: "key=value"}
|
||||
* will fetch all objects with given tags from OSM.
|
||||
* Currently, this will create a query to overpass and fetch the data - in the future this might fetch from the OSM API
|
||||
*
|
||||
*
|
||||
* # Query OSM Via the overpass API with a custom script
|
||||
* source: {overpassScript: "<custom overpass tags>"} when you want to do special things. _This should be really rare_.
|
||||
* This means that the data will be pulled from overpass with this script, and will ignore the osmTags for the query
|
||||
* However, for the rest of the pipeline, the OsmTags will _still_ be used. This is important to enable layers etc...
|
||||
*
|
||||
*
|
||||
* # A single geojson-file
|
||||
* source: {geoJson: "https://my.source.net/some-geo-data.geojson"}
|
||||
* # A single geojson-file
|
||||
* source: {geoJson: "https://my.source.net/some-geo-data.geojson"}
|
||||
* fetches a geojson from a third party source
|
||||
*
|
||||
*
|
||||
* # A tiled geojson source
|
||||
* source: {geoJson: "https://my.source.net/some-tile-geojson-{layer}-{z}-{x}-{y}.geojson", geoJsonZoomLevel: 14}
|
||||
* source: {geoJson: "https://my.source.net/some-tile-geojson-{layer}-{z}-{x}-{y}.geojson", geoJsonZoomLevel: 14}
|
||||
* to use a tiled geojson source. The web server must offer multiple geojsons. {z}, {x} and {y} are substituted by the location; {layer} is substituted with the id of the loaded layer
|
||||
*
|
||||
*
|
||||
* Note that both geojson-options might set a flag 'isOsmCache' indicating that the data originally comes from OSM too
|
||||
*
|
||||
*
|
||||
*
|
||||
* Note that both geojson-options might set a flag 'isOsmCache' indicating that the data originally comes from OSM too
|
||||
*
|
||||
*
|
||||
* NOTE: the previous format was 'overpassTags: AndOrTagCOnfigJson | string', which is interpreted as a shorthand for source: {osmTags: "key=value"}
|
||||
* While still supported, this is considered deprecated
|
||||
*/
|
||||
|
@ -123,7 +124,7 @@ export interface LayerConfigJson {
|
|||
* As a result, on could use a generic pin, then overlay it with a specific icon.
|
||||
* To make things even more practical, one can use all svgs from the folder "assets/svg" and _substitute the color_ in it.
|
||||
* E.g. to draw a red pin, use "pin:#f00", to have a green circle with your icon on top, use `circle:#0f0;<path to my icon.svg>`
|
||||
*
|
||||
*
|
||||
*/
|
||||
icon?: string | TagRenderingConfigJson;
|
||||
|
||||
|
@ -148,14 +149,14 @@ export interface LayerConfigJson {
|
|||
*/
|
||||
rotation?: string | TagRenderingConfigJson;
|
||||
/**
|
||||
* A HTML-fragment that is shown below the icon, for example:
|
||||
* A HTML-fragment that is shown below the icon, for example:
|
||||
* <div style="background: white; display: block">{name}</div>
|
||||
*
|
||||
*
|
||||
* If the icon is undefined, then the label is shown in the center of the feature.
|
||||
* Note that, if the wayhandling hides the icon then no label is shown as well.
|
||||
*/
|
||||
label?: string | TagRenderingConfigJson ;
|
||||
|
||||
label?: string | TagRenderingConfigJson;
|
||||
|
||||
/**
|
||||
* The color for way-elements and SVG-elements.
|
||||
* If the value starts with "--", the style of the body element will be queried for the corresponding variable instead
|
||||
|
@ -230,7 +231,54 @@ export interface LayerConfigJson {
|
|||
* A special value is 'questions', which indicates the location of the questions box. If not specified, it'll be appended to the bottom of the featureInfobox.
|
||||
*
|
||||
*/
|
||||
tagRenderings?: (string | TagRenderingConfigJson) []
|
||||
tagRenderings?: (string | TagRenderingConfigJson) [],
|
||||
|
||||
/**
|
||||
* This block defines under what circumstances the delete dialog is shown for objects of this layer.
|
||||
* If set, a dialog is shown to the user to (soft) delete the point.
|
||||
* The dialog is built to be user friendly and to prevent mistakes.
|
||||
* If deletion is not possible, the dialog will hide itself and show the reason of non-deletability instead.
|
||||
*
|
||||
* To configure, the following values are possible:
|
||||
*
|
||||
* - false: never ever show the delete button
|
||||
* - true: show the default delete button
|
||||
* - undefined: use the mapcomplete default to show deletion or not. Currently, this is the same as 'false' but this will change in the future
|
||||
* - or: a hash with options (see below)
|
||||
*
|
||||
* The delete dialog
|
||||
* =================
|
||||
*
|
||||
*
|
||||
*
|
||||
#### Hard deletion if enough experience
|
||||
|
||||
A feature can only be deleted from OpenStreetMap by mapcomplete if:
|
||||
|
||||
- It is a node
|
||||
- No ways or relations use the node
|
||||
- The logged-in user has enough experience OR the user is the only one to have edited the point previously
|
||||
- The logged-in user has no unread messages (or has a ton of experience)
|
||||
- The user did not select one of the 'non-delete-options' (see below)
|
||||
|
||||
In all other cases, a 'soft deletion' is used.
|
||||
|
||||
#### Soft deletion
|
||||
|
||||
A 'soft deletion' is when the point isn't deleted from OSM but retagged so that it'll won't how up in the mapcomplete theme anymore.
|
||||
This makes it look like it was deleted, without doing damage. A fixme will be added to the point.
|
||||
|
||||
Note that a soft deletion is _only_ possible if these tags are provided by the theme creator, as they'll be different for every theme
|
||||
|
||||
#### No-delete options
|
||||
|
||||
In some cases, the contributor might want to delete something for the wrong reason (e.g. someone who wants to have a path removed "because the path is on their private property").
|
||||
However, the path exists in reality and should thus be on OSM - otherwise the next contributor will pass by and notice "hey, there is a path missing here! Let me redraw it in OSM!)
|
||||
|
||||
The correct approach is to retag the feature in such a way that it is semantically correct *and* that it doesn't show up on the theme anymore.
|
||||
A no-delete option is offered as 'reason to delete it', but secretly retags.
|
||||
|
||||
*/
|
||||
deletion?: boolean | DeleteConfigJson
|
||||
|
||||
}
|
|
@ -32,6 +32,14 @@ export class ChangesetHandler {
|
|||
// @ts-ignore
|
||||
for (const node of nodes) {
|
||||
const oldId = parseInt(node.attributes.old_id.value);
|
||||
if (node.attributes.new_id === undefined) {
|
||||
// We just removed this point!
|
||||
const element = allElements.getEventSourceById("node/" + oldId);
|
||||
element.data._deleted = "yes"
|
||||
element.ping();
|
||||
continue;
|
||||
}
|
||||
|
||||
const newId = parseInt(node.attributes.new_id.value);
|
||||
if (oldId !== undefined && newId !== undefined &&
|
||||
!isNaN(oldId) && !isNaN(newId)) {
|
||||
|
@ -138,7 +146,7 @@ export class ChangesetHandler {
|
|||
changes +=
|
||||
`<delete><${object.type} id="${object.id}" version="${object.version}" changeset="${csId}" lat="${lat}" lon="${lon}" /></delete>`;
|
||||
changes += "</osmChange>";
|
||||
|
||||
continuation()
|
||||
return changes;
|
||||
|
||||
}
|
||||
|
@ -152,10 +160,10 @@ export class ChangesetHandler {
|
|||
|
||||
const self = this;
|
||||
this.OpenChangeset(layout, (csId: string) => {
|
||||
|
||||
|
||||
// The cs is open - let us actually upload!
|
||||
const changes = generateChangeXML(csId)
|
||||
|
||||
|
||||
self.AddChange(csId, changes, allElements, (csId) => {
|
||||
console.log("Successfully deleted ", object.id)
|
||||
self.CloseChangeset(csId, continuation)
|
||||
|
@ -203,8 +211,8 @@ export class ChangesetHandler {
|
|||
let comment = `Adding data with #MapComplete for theme #${layout.id}${commentExtra}`
|
||||
if (isDeletionCS) {
|
||||
comment = `Deleting a point with #MapComplete for theme #${layout.id}${commentExtra}`
|
||||
if(deletionReason){
|
||||
comment += ": "+deletionReason;
|
||||
if (deletionReason) {
|
||||
comment += ": " + deletionReason;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,8 @@ import {AndOrTagConfigJson} from "../../Customizations/JSON/TagConfigJson";
|
|||
import BaseUIElement from "../BaseUIElement";
|
||||
import {Changes} from "../../Logic/Osm/Changes";
|
||||
import {And} from "../../Logic/Tags/And";
|
||||
|
||||
import Constants from "../../Models/Constants";
|
||||
import DeleteConfig from "../../Customizations/JSON/DeleteConfig";
|
||||
|
||||
export default class DeleteWizard extends Toggle {
|
||||
/**
|
||||
|
@ -39,18 +40,12 @@ export default class DeleteWizard extends Toggle {
|
|||
* @param options softDeletionTags: the tags to apply if the user doesn't have permission to delete, e.g. 'disused:amenity=public_bookcase', 'amenity='. After applying, the element should not be picked up on the map anymore. If undefined, the wizard will only show up if the point can be (hard) deleted
|
||||
*/
|
||||
constructor(id: string,
|
||||
options?: {
|
||||
noDeleteOptions?: { if: Tag[], then: Translation }[]
|
||||
softDeletionTags?: Tag[],
|
||||
neededChangesets?: number
|
||||
}) {
|
||||
options: DeleteConfig) {
|
||||
|
||||
options = options ?? {}
|
||||
const deleteAction = new DeleteAction(id, options.neededChangesets);
|
||||
const tagsSource = State.state.allElements.getEventSourceById(id)
|
||||
|
||||
let softDeletionTags = options.softDeletionTags ?? []
|
||||
const allowSoftDeletion = softDeletionTags.length > 0
|
||||
const allowSoftDeletion = !!options.softDeletionTags
|
||||
|
||||
const confirm = new UIEventSource<boolean>(false)
|
||||
|
||||
|
@ -80,7 +75,7 @@ export default class DeleteWizard extends Toggle {
|
|||
});
|
||||
return
|
||||
} else {
|
||||
// This is an injected tagging
|
||||
// This is a 'non-delete'-option that was selected
|
||||
softDelete(undefined, tgs)
|
||||
}
|
||||
|
||||
|
@ -89,46 +84,60 @@ export default class DeleteWizard extends Toggle {
|
|||
|
||||
const t = Translations.t.delete
|
||||
const cancelButton = t.cancel.Clone().SetClass("block btn btn-secondary").onClick(() => confirm.setData(false));
|
||||
const config = DeleteWizard.generateDeleteTagRenderingConfig(softDeletionTags, options.noDeleteOptions)
|
||||
const question = new TagRenderingQuestion(
|
||||
tagsSource,
|
||||
config,
|
||||
{
|
||||
cancelButton: cancelButton,
|
||||
/*Using a custom save button constructor erases all logic to actually save, so we have to listen for the click!*/
|
||||
saveButtonConstr: (v) => DeleteWizard.constructConfirmButton(v).onClick(() => {
|
||||
doDelete(v.data)
|
||||
}),
|
||||
bottomText: (v) => DeleteWizard.constructExplanation(v, deleteAction)
|
||||
}
|
||||
)
|
||||
const question = new VariableUiElement(tagsSource.map(currentTags => {
|
||||
const config = DeleteWizard.generateDeleteTagRenderingConfig(options.softDeletionTags, options.nonDeleteMappings, options.extraDeleteReasons, currentTags)
|
||||
return new TagRenderingQuestion(
|
||||
tagsSource,
|
||||
config,
|
||||
{
|
||||
cancelButton: cancelButton,
|
||||
/*Using a custom save button constructor erases all logic to actually save, so we have to listen for the click!*/
|
||||
saveButtonConstr: (v) => DeleteWizard.constructConfirmButton(v).onClick(() => {
|
||||
doDelete(v.data)
|
||||
}),
|
||||
bottomText: (v) => DeleteWizard.constructExplanation(v, deleteAction)
|
||||
}
|
||||
)
|
||||
}))
|
||||
|
||||
|
||||
/**
|
||||
* The button which is shown first. Opening it will trigger the check for deletions
|
||||
*/
|
||||
const deleteButton = new SubtleButton(Svg.delete_icon_svg(), t.delete).onClick(
|
||||
const deleteButton = new SubtleButton(
|
||||
Svg.delete_icon_ui().SetStyle("width: 2rem; height: 2rem;"), t.delete.Clone()).onClick(
|
||||
() => {
|
||||
deleteAction.CheckDeleteability(true)
|
||||
confirm.setData(true);
|
||||
}
|
||||
);
|
||||
).SetClass("w-1/2 float-right");
|
||||
|
||||
const isShown = new UIEventSource<boolean>(id.indexOf("-")< 0)
|
||||
|
||||
super(
|
||||
new Toggle(
|
||||
new Combine([Svg.delete_icon_svg().SetClass("h-16 w-16 p-2 m-2 block bg-gray-300 rounded-full"),
|
||||
t.isDeleted.Clone()]).SetClass("flex m-2 rounded-full"),
|
||||
new Toggle(
|
||||
new Toggle(
|
||||
new Toggle(
|
||||
question,
|
||||
new Toggle(
|
||||
question,
|
||||
new SubtleButton(Svg.envelope_ui(), t.readMessages.Clone()),
|
||||
State.state.osmConnection.userDetails.map(ud => ud.csCount > Constants.userJourney.addNewPointWithUnreadMessagesUnlock || ud.unreadMessages == 0)
|
||||
),
|
||||
|
||||
deleteButton,
|
||||
confirm),
|
||||
new VariableUiElement(deleteAction.canBeDeleted.map(cbd => new Combine([cbd.reason.Clone(), t.useSomethingElse]))),
|
||||
new VariableUiElement(deleteAction.canBeDeleted.map(cbd => new Combine([cbd.reason.Clone(), t.useSomethingElse.Clone()]))),
|
||||
deleteAction.canBeDeleted.map(cbd => allowSoftDeletion || cbd.canBeDeleted !== false)),
|
||||
|
||||
t.loginToDelete.Clone().onClick(State.state.osmConnection.AttemptLogin),
|
||||
State.state.osmConnection.isLoggedIn
|
||||
),
|
||||
deleteAction.isDeleted)
|
||||
deleteAction.isDeleted),
|
||||
undefined,
|
||||
isShown)
|
||||
|
||||
}
|
||||
|
||||
|
@ -163,7 +172,7 @@ export default class DeleteWizard extends Toggle {
|
|||
if (currentTags === undefined) {
|
||||
return t.explanations.selectReason.Clone().SetClass("subtle");
|
||||
}
|
||||
|
||||
|
||||
const hasDeletionTag = currentTags.asChange(currentTags).some(kv => kv.k === "_delete_reason")
|
||||
|
||||
if (cbd.canBeDeleted && hasDeletionTag) {
|
||||
|
@ -179,23 +188,32 @@ export default class DeleteWizard extends Toggle {
|
|||
)).SetClass("block")
|
||||
}
|
||||
|
||||
private static generateDeleteTagRenderingConfig(softDeletionTags: Tag[], nonDeleteOptions: {
|
||||
if: Tag[],
|
||||
then: Translation
|
||||
}[]) {
|
||||
private static generateDeleteTagRenderingConfig(softDeletionTags: TagsFilter,
|
||||
nonDeleteOptions: { if: TagsFilter; then: Translation }[],
|
||||
extraDeleteReasons: { explanation: Translation; changesetMessage: string }[],
|
||||
currentTags: any) {
|
||||
const t = Translations.t.delete
|
||||
nonDeleteOptions = nonDeleteOptions ?? []
|
||||
const softDeletionTagsStr = (softDeletionTags ?? []).map(t => t.asHumanString(false, false))
|
||||
const nonDeleteOptionsStr: { if: AndOrTagConfigJson, then: any }[] = []
|
||||
let softDeletionTagsStr = []
|
||||
if (softDeletionTags !== undefined) {
|
||||
softDeletionTags.asChange(currentTags)
|
||||
}
|
||||
const extraOptionsStr: { if: AndOrTagConfigJson, then: any }[] = []
|
||||
for (const nonDeleteOption of nonDeleteOptions) {
|
||||
const newIf: string[] = nonDeleteOption.if.map(tag => tag.asHumanString())
|
||||
const newIf: string[] = nonDeleteOption.if.asChange({}).map(kv => kv.k + "=" + kv.v)
|
||||
|
||||
nonDeleteOptionsStr.push({
|
||||
extraOptionsStr.push({
|
||||
if: {and: newIf},
|
||||
then: nonDeleteOption.then
|
||||
})
|
||||
}
|
||||
|
||||
for (const extraDeleteReason of (extraDeleteReasons ?? [])) {
|
||||
extraOptionsStr.push({
|
||||
if: {and: ["_delete_reason=" + extraDeleteReason.changesetMessage]},
|
||||
then: extraDeleteReason.explanation
|
||||
})
|
||||
}
|
||||
return new TagRenderingConfig(
|
||||
{
|
||||
question: t.whyDelete,
|
||||
|
@ -206,7 +224,7 @@ export default class DeleteWizard extends Toggle {
|
|||
},
|
||||
mappings: [
|
||||
|
||||
...nonDeleteOptionsStr,
|
||||
...extraOptionsStr,
|
||||
|
||||
{
|
||||
if: {
|
||||
|
|
|
@ -12,6 +12,7 @@ import Constants from "../../Models/Constants";
|
|||
import SharedTagRenderings from "../../Customizations/SharedTagRenderings";
|
||||
import BaseUIElement from "../BaseUIElement";
|
||||
import {VariableUiElement} from "../Base/VariableUIElement";
|
||||
import DeleteWizard from "./DeleteWizard";
|
||||
|
||||
export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||
|
||||
|
@ -21,7 +22,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
) {
|
||||
super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig),
|
||||
() => FeatureInfoBox.GenerateContent(tags, layerConfig),
|
||||
tags.data.id);
|
||||
undefined);
|
||||
|
||||
if (layerConfig === undefined) {
|
||||
throw "Undefined layerconfig";
|
||||
|
@ -69,19 +70,31 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
if (!hasMinimap) {
|
||||
renderings.push(new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("minimap")))
|
||||
}
|
||||
|
||||
|
||||
if (layerConfig.deletion) {
|
||||
renderings.push(
|
||||
new VariableUiElement(tags.map(tags => tags.id).map(id =>
|
||||
new DeleteWizard(
|
||||
id,
|
||||
layerConfig.deletion
|
||||
))
|
||||
))
|
||||
}
|
||||
|
||||
renderings.push(
|
||||
new VariableUiElement(
|
||||
State.state.osmConnection.userDetails.map(userdetails => {
|
||||
if (userdetails.csCount <= Constants.userJourney.historyLinkVisible
|
||||
&& State.state.featureSwitchIsDebugging.data == false
|
||||
&& State.state.featureSwitchIsTesting.data === false) {
|
||||
return undefined
|
||||
}
|
||||
State.state.osmConnection.userDetails
|
||||
.map(ud => ud.csCount)
|
||||
.map(csCount => {
|
||||
if (csCount <= Constants.userJourney.historyLinkVisible
|
||||
&& State.state.featureSwitchIsDebugging.data == false
|
||||
&& State.state.featureSwitchIsTesting.data === false) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("last_edit"));
|
||||
return new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("last_edit"));
|
||||
|
||||
}, [State.state.featureSwitchIsDebugging])
|
||||
}, [State.state.featureSwitchIsDebugging, State.state.featureSwitchIsTesting])
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ export default class ShowDataLayer {
|
|||
const allFeats = features.data.map(ff => ff.feature);
|
||||
geoLayer = self.CreateGeojsonLayer();
|
||||
for (const feat of allFeats) {
|
||||
if(feat === undefined){
|
||||
if (feat === undefined) {
|
||||
continue
|
||||
}
|
||||
// @ts-ignore
|
||||
|
@ -79,11 +79,11 @@ export default class ShowDataLayer {
|
|||
}
|
||||
|
||||
if (zoomToFeatures) {
|
||||
try{
|
||||
|
||||
mp.fitBounds(geoLayer.getBounds())
|
||||
try {
|
||||
|
||||
}catch(e){
|
||||
mp.fitBounds(geoLayer.getBounds())
|
||||
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,6 @@ export default class ShowDataLayer {
|
|||
})
|
||||
});
|
||||
}
|
||||
|
||||
private postProcessFeature(feature, leafletLayer: L.Layer) {
|
||||
const layer: LayerConfig = this._layerDict[feature._matching_layer_id];
|
||||
if (layer === undefined) {
|
||||
|
@ -161,6 +160,7 @@ export default class ShowDataLayer {
|
|||
|
||||
leafletLayer.on("popupopen", () => {
|
||||
State.state.selectedElement.setData(feature)
|
||||
|
||||
if (infobox === undefined) {
|
||||
const tags = State.state.allElements.getEventSourceById(feature.properties.id);
|
||||
infobox = new FeatureInfoBox(tags, layer);
|
||||
|
@ -175,11 +175,11 @@ export default class ShowDataLayer {
|
|||
|
||||
|
||||
infobox.AttachTo(id)
|
||||
infobox.Activate();
|
||||
infobox.Activate();
|
||||
});
|
||||
const self = this;
|
||||
State.state.selectedElement.addCallbackAndRunD(selected => {
|
||||
if ( self._leafletMap.data === undefined) {
|
||||
if (self._leafletMap.data === undefined) {
|
||||
return;
|
||||
}
|
||||
if (leafletLayer.getPopup().isOpen()) {
|
||||
|
@ -187,8 +187,10 @@ export default class ShowDataLayer {
|
|||
}
|
||||
if (selected.properties.id === feature.properties.id) {
|
||||
// A small sanity check to prevent infinite loops:
|
||||
// If a feature is rendered both as way and as point, opening one popup might trigger the other to open, which might trigger the one to open again
|
||||
if (selected.geometry.type === feature.geometry.type) {
|
||||
if (selected.geometry.type === feature.geometry.type // If a feature is rendered both as way and as point, opening one popup might trigger the other to open, which might trigger the one to open again
|
||||
|
||||
&& feature.id === feature.properties.id // the feature might have as id 'node/-1' and as 'feature.properties.id' = 'the newly assigned id'. That is no good too
|
||||
) {
|
||||
leafletLayer.openPopup()
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import Histogram from "./BigComponents/Histogram";
|
|||
import Loc from "../Models/Loc";
|
||||
import {Utils} from "../Utils";
|
||||
import BaseLayer from "../Models/BaseLayer";
|
||||
import DeleteWizard from "./Popup/DeleteWizard";
|
||||
import Constants from "../Models/Constants";
|
||||
|
||||
export interface SpecialVisualization {
|
||||
funcName: string,
|
||||
|
@ -38,8 +36,6 @@ export interface SpecialVisualization {
|
|||
export default class SpecialVisualizations {
|
||||
|
||||
|
||||
public static specialVisualisationsByName: Map<string, SpecialVisualization> = SpecialVisualizations.byName();
|
||||
static HelpMessage: BaseUIElement = SpecialVisualizations.GenHelpMessage();
|
||||
static constructMiniMap: (options?: {
|
||||
background?: UIEventSource<BaseLayer>,
|
||||
location?: UIEventSource<Loc>,
|
||||
|
@ -380,57 +376,10 @@ export default class SpecialVisualizations {
|
|||
[state.layoutToUse])
|
||||
)
|
||||
}
|
||||
},
|
||||
{
|
||||
funcName: "delete",
|
||||
docs: `Offers a dialog to (soft) delete the point. The dialog is built to be user friendly and to prevent mistakes. If deletion is not possible, the dialog will hide itself.
|
||||
|
||||
#### Hard deletion if enough experience
|
||||
|
||||
A feature can only be deleted by mapcomplete if:
|
||||
|
||||
- It is a node
|
||||
- No ways or relations use the node
|
||||
- The logged-in user has enough experience (at least ${Constants.userJourney.deletePointsOfOthersUnlock} changesets) OR the user is the only one to have edited the point previously
|
||||
- The user did not select one of the 'non-delete-options' (see below)
|
||||
|
||||
In all other cases, a 'soft deletion' is used.
|
||||
|
||||
#### Soft deletion
|
||||
|
||||
A 'soft deletion' is when the point isn't deleted from OSM but retagged so that it'll won't how up in the mapcomplete theme anymore.
|
||||
This makes it look like it was deleted, without doing damage. A fixme will be added to the point.
|
||||
|
||||
Note that a soft deletion is _only_ possible if these tags are provided by the theme creator, as they'll be different for every theme
|
||||
|
||||
#### No-delete options
|
||||
|
||||
In some cases, the contributor might want to delete something for the wrong reason (e.g. someone who wants to have a path removed "because the path is on their private property").
|
||||
However, the path exists in reality and should thus be on OSM - otherwise the next contributor will pass by and notice "hey, there is a path missing here! Let me redraw it in OSM!)
|
||||
|
||||
The correct approach is to retag the feature in such a way that it is semantically correct *and* that it doesn't show up on the theme anymore.
|
||||
A no-delete option is offered as 'reason to delete it', but secretly retags.
|
||||
|
||||
`,
|
||||
args: [],
|
||||
constr: (state, tagSource, args) => {
|
||||
return new VariableUiElement(tagSource.map(tags => tags.id).map(id =>
|
||||
new DeleteWizard(id)))
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
private static byName(): Map<string, SpecialVisualization> {
|
||||
const result = new Map<string, SpecialVisualization>();
|
||||
|
||||
for (const specialVisualization of SpecialVisualizations.specialVisualizations) {
|
||||
result.set(specialVisualization.funcName, specialVisualization)
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static HelpMessage: BaseUIElement = SpecialVisualizations.GenHelpMessage();
|
||||
private static GenHelpMessage() {
|
||||
|
||||
const helpTexts =
|
||||
|
|
|
@ -374,5 +374,12 @@
|
|||
"type": "url"
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"deletion": {
|
||||
"softDeletionTags": {"and":[
|
||||
"disused:amenity=public_bookcase",
|
||||
"amenity="
|
||||
]},
|
||||
"neededChangesets": 5
|
||||
}
|
||||
}
|
|
@ -49,7 +49,8 @@
|
|||
"selectReason": "Please, select why this feature should be deleted",
|
||||
"hardDelete": "This point will be deleted in OpenStreetMap. It can be recovered by an experienced contributor",
|
||||
"softDelete": "This feature will be updated and hidden from this application. <span class='subtle'>{reason}</span>"
|
||||
}
|
||||
},
|
||||
"readMessages": "You have unread messages. Read these before deleting a point - someone might have feedback"
|
||||
},
|
||||
"general": {
|
||||
"loginWithOpenStreetMap": "Login with OpenStreetMap",
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
"generate:layouts": "ts-node scripts/generateLayouts.ts",
|
||||
"generate:docs": "ts-node scripts/generateDocs.ts && ts-node scripts/generateTaginfoProjectFiles.ts",
|
||||
"generate:cache:speelplekken": "npm run generate:layeroverview && ts-node scripts/generateCache.ts speelplekken 14 ../pietervdvn.github.io/speelplekken_cache/ 51.20 4.35 51.09 4.56",
|
||||
"generate:layeroverview": "ts-node scripts/generateLayerOverview.ts --no-fail",
|
||||
"generate:layeroverview": "echo {\\\"layers\\\":[], \\\"themes\\\":[]} > ./assets/generated/known_layers_and_themes.json && ts-node scripts/generateLayerOverview.ts --no-fail",
|
||||
"generate:licenses": "ts-node scripts/generateLicenseInfo.ts --no-fail",
|
||||
"generate:report": "cd Docs/Tools && ./compileStats.sh && git commit . -m 'New statistics ands graphs' && git push",
|
||||
"generate:contributor-list": "git log --pretty='%aN' | sort | uniq -c | sort -hr | sed 's/ *\\([0-9]*\\) \\(.*\\)$/{\"contributor\":\"\\2\", \"commits\":\\1}/' | tr '\\n' ',' | sed 's/^/{\"contributors\":[/' | sed 's/,$/]}/' > assets/contributors.json",
|
||||
|
|
Loading…
Reference in a new issue