Skip to content

Commit

Permalink
Add tooltip and updated message to deprecated_tags validation issue
Browse files Browse the repository at this point in the history
Add a quick fix to upgrade deprecated tags
Add more deprecated tag data
  • Loading branch information
quincylvania committed Jan 24, 2019
1 parent 33ae009 commit b21dd1d
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 18 deletions.
8 changes: 6 additions & 2 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand Down
94 changes: 93 additions & 1 deletion data/deprecated.json
Original file line number Diff line number Diff line change
@@ -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"}
Expand All @@ -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"},
Expand All @@ -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"}
Expand All @@ -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"}
Expand All @@ -51,6 +135,14 @@
{
"old": {"shop": "organic"},
"replace": {"shop": "supermarket", "organic": "only"}
},
{
"old": {"shop": "fishmonger"},
"replace": {"shop": "seafood"}
},
{
"old": {"shop": "furnace"},
"replace": {"shop": "fireplace"}
}
]
}
7 changes: 6 additions & 1 deletion dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}\".",
Expand Down Expand Up @@ -1494,6 +1495,10 @@
"move_tags": {
"title": "Move the tags",
"undo_redo": "Moved tags."
},
"upgrade_tags": {
"title": "Upgrade tags",
"undo_redo": "Upgraded tags."
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions modules/osm/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
Expand Down
79 changes: 67 additions & 12 deletions modules/validations/deprecated_tag.js
Original file line number Diff line number Diff line change
@@ -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')
);
}
})
]
}));
}
}
}

Expand Down

0 comments on commit b21dd1d

Please sign in to comment.