From b21dd1d5d60198b3d9e995fc745d7b343b450644 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Thu, 24 Jan 2019 14:09:12 -0500 Subject: [PATCH] Add tooltip and updated message to deprecated_tags validation issue Add a quick fix to upgrade deprecated tags Add more deprecated tag data --- data/core.yaml | 8 ++- data/deprecated.json | 94 ++++++++++++++++++++++++++- dist/locales/en.json | 7 +- modules/osm/entity.js | 4 +- modules/validations/deprecated_tag.js | 79 ++++++++++++++++++---- 5 files changed, 174 insertions(+), 18 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index f1e9ffb0f..eada4050f 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1162,10 +1162,11 @@ en: tag_suggests_area: message: "The tag {tag} suggests line should be area, but it is not an area." deprecated_tags: - message: "Deprecated tags: {tags}" + message: '{feature} has outdated tags: {tags}' + tooltip: Some tags become deprecated over time and should be replaced. generic_name: message: '{feature} has the generic name "{name}".' - tooltip: 'Names should be the official, on-the-ground titles of features.' + tooltip: Names should be the official, on-the-ground titles of features. building-building_crossing: message: "{building} intersect {building1} on the same layer." tooltip: "Buildings should not intersect except on separate layers." @@ -1224,6 +1225,9 @@ en: move_tags: title: Move the tags undo_redo: Moved tags. + upgrade_tags: + title: Upgrade tags + undo_redo: Upgraded tags. intro: done: done ok: OK diff --git a/data/deprecated.json b/data/deprecated.json index bd05fe8c2..0102260e1 100644 --- a/data/deprecated.json +++ b/data/deprecated.json @@ -1,9 +1,53 @@ { "dataDeprecated": [ + { + "old": {"amenity": "advertising"}, + "replace": {"advertising": "*"} + }, + { + "old": {"amenity": "artwork"}, + "replace": {"tourism": "artwork"} + }, + { + "old": {"amenity": "car_repair"}, + "replace": {"shop": "car_repair"} + }, + { + "old": {"amenity": "citymap_post"}, + "replace": {"tourism": "information"} + }, + { + "old": {"amenity": "community_center"}, + "replace": {"amenity": "community_centre"} + }, { "old": {"amenity": "firepit"}, "replace": {"leisure": "firepit"} }, + { + "old": {"amenity": "register_office"}, + "replace": {"office": "government", "government": "register_office"} + }, + { + "old": {"amenity": "sauna"}, + "replace": {"leisure": "sauna"} + }, + { + "old": {"amenity": "scrapyard"}, + "replace": {"landuse": "industrial", "industrial": "scrap_yard"} + }, + { + "old": {"amenity": "shop"}, + "replace": {"shop": "*"} + }, + { + "old": {"amenity": "swimming_pool"}, + "replace": {"leisure": "swimming_pool"} + }, + { + "old": {"amenity": "vending_machine", "vending": "news_papers"}, + "replace": {"amenity": "vending_machine", "vending": "newspapers"} + }, { "old": {"barrier": "wire_fence"}, "replace": {"barrier": "fence", "fence_type": "chain"} @@ -12,9 +56,33 @@ "old": {"barrier": "wood_fence"}, "replace": {"barrier": "fence", "fence_type": "wood"} }, + { + "old": {"building": "entrance"}, + "replace": {"entrance": "*"} + }, + { + "old": {"building:type": "*"}, + "replace": {"building": "$1"} + }, + { + "old": {"color": "*"}, + "replace": {"colour": "$1"} + }, + { + "old": {"craft": "jeweler"}, + "replace": {"shop": "jewelery"} + }, + { + "old": {"craft": "optician"}, + "replace": {"shop": "optician"} + }, + { + "old": {"escalator": "*"}, + "replace": {"highway": "steps", "conveying": "$1"} + }, { "old": {"highway": "ford"}, - "replace": {"ford": "yes"} + "replace": {"ford": "*"} }, { "old": {"highway": "stile"}, @@ -32,6 +100,14 @@ "old": {"highway": "unsurfaced"}, "replace": {"highway": "road", "incline": "unpaved"} }, + { + "old": {"landuse": "farm"}, + "replace": {"landuse": "farmland"} + }, + { + "old": {"landuse": "pond"}, + "replace": {"natural": "water", "water": "pond"} + }, { "old": {"landuse": "wood"}, "replace": {"landuse": "forest", "natural": "wood"} @@ -40,6 +116,14 @@ "old": {"natural": "marsh"}, "replace": {"natural": "wetland", "wetland": "marsh"} }, + { + "old": {"office": "administrative"}, + "replace": {"office": "government"} + }, + { + "old": {"power": "sub_station"}, + "replace": {"power": "substation"} + }, { "old": {"power_source": "*"}, "replace": {"generator:source": "$1"} @@ -51,6 +135,14 @@ { "old": {"shop": "organic"}, "replace": {"shop": "supermarket", "organic": "only"} + }, + { + "old": {"shop": "fishmonger"}, + "replace": {"shop": "seafood"} + }, + { + "old": {"shop": "furnace"}, + "replace": {"shop": "fireplace"} } ] } diff --git a/dist/locales/en.json b/dist/locales/en.json index 2a90d352b..a93abebf8 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1411,7 +1411,8 @@ "message": "The tag {tag} suggests line should be area, but it is not an area." }, "deprecated_tags": { - "message": "Deprecated tags: {tags}" + "message": "{feature} has outdated tags: {tags}", + "tooltip": "Some tags become deprecated over time and should be replaced." }, "generic_name": { "message": "{feature} has the generic name \"{name}\".", @@ -1494,6 +1495,10 @@ "move_tags": { "title": "Move the tags", "undo_redo": "Moved tags." + }, + "upgrade_tags": { + "title": "Upgrade tags", + "undo_redo": "Upgraded tags." } } }, diff --git a/modules/osm/entity.js b/modules/osm/entity.js index aa7d417c1..446fcd35c 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -166,14 +166,14 @@ osmEntity.prototype = { deprecatedTags: function() { var tags = _toPairs(this.tags); - var deprecated = {}; + var deprecated = []; dataDeprecated.forEach(function(d) { var match = _toPairs(d.old)[0]; tags.forEach(function(t) { if (t[0] === match[0] && (t[1] === match[1] || match[1] === '*')) { - deprecated[t[0]] = t[1]; + deprecated.push(d); } }); }); diff --git a/modules/validations/deprecated_tag.js b/modules/validations/deprecated_tag.js index eeda2a574..676bd1b03 100644 --- a/modules/validations/deprecated_tag.js +++ b/modules/validations/deprecated_tag.js @@ -1,30 +1,85 @@ import _isEmpty from 'lodash-es/isEmpty'; - +import _clone from 'lodash-es/clone'; import { t } from '../util/locale'; -import { utilTagText } from '../util/index'; +import { + utilDisplayLabel, + utilTagText +} from '../util'; import { ValidationIssueType, ValidationIssueSeverity, validationIssue, + validationIssueFix } from './validation_issue'; +import { + actionChangeTags +} from '../actions'; -export function validationDeprecatedTag() { +export function validationDeprecatedTag(context) { var validation = function(changes) { var issues = []; for (var i = 0; i < changes.created.length; i++) { var change = changes.created[i]; - var deprecatedTags = change.deprecatedTags(); + var deprecatedTagsArray = change.deprecatedTags(); - if (!_isEmpty(deprecatedTags)) { - var tags = utilTagText({ tags: deprecatedTags }); - issues.push(new validationIssue({ - type: ValidationIssueType.deprecated_tags, - severity: ValidationIssueSeverity.warning, - message: t('issues.deprecated_tags.message', { tags: tags }), - entities: [change], - })); + if (!_isEmpty(deprecatedTagsArray)) { + for (var deprecatedTagIndex in deprecatedTagsArray) { + var deprecatedTags = deprecatedTagsArray[deprecatedTagIndex]; + var tagsLabel = utilTagText({ tags: deprecatedTags.old }); + var featureLabel = utilDisplayLabel(change, context); + issues.push(new validationIssue({ + type: ValidationIssueType.deprecated_tags, + severity: ValidationIssueSeverity.warning, + message: t('issues.deprecated_tags.message', { feature: featureLabel, tags: tagsLabel }), + tooltip: t('issues.deprecated_tags.tooltip'), + entities: [change], + info: { + oldTags: deprecatedTags.old, + replaceTags: deprecatedTags.replace + }, + fixes: [ + new validationIssueFix({ + title: t('issues.fix.upgrade_tags.title'), + action: function() { + var entity = this.issue.entities[0]; + var tags = _clone(entity.tags); + var replaceTags = this.issue.info.replaceTags; + var oldTags = this.issue.info.oldTags; + var transferValue; + for (var oldTagKey in oldTags) { + if (oldTags[oldTagKey] === '*') { + transferValue = tags[oldTagKey]; + } + delete tags[oldTagKey]; + } + for (var replaceKey in replaceTags) { + var replaceValue = replaceTags[replaceKey]; + if (replaceValue === '*') { + if (tags[replaceKey]) { + // any value is okay and there already + // is one, so don't update it + continue; + } else { + // otherwise assume `yes` is okay + tags[replaceKey] = 'yes'; + } + } else if (replaceValue === '$1') { + tags[replaceKey] = transferValue; + } else { + tags[replaceKey] = replaceValue; + } + } + context.perform( + actionChangeTags(entity.id, tags), + t('issues.fix.upgrade_tags.undo_redo') + ); + } + }) + ] + })); + } } }