Integrate the generic_name validation into the new validations framework

This commit is contained in:
Quincy Morgan
2019-01-24 09:28:59 -05:00
parent 01e2370cbd
commit 981ed9ef8c
6 changed files with 61 additions and 10 deletions
+6
View File
@@ -1163,6 +1163,9 @@ en:
message: "The tag {tag} suggests line should be area, but it is not an area."
deprecated_tags:
message: "Deprecated tags: {tags}"
generic_name:
message: '{feature} has the generic name "{name}".'
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."
@@ -1215,6 +1218,9 @@ en:
connect_almost_junction:
title: Connect the features
undo_redo: Connected two features that were really close.
remove_name:
title: Remove the name
undo_redo: Removed a generic name.
intro:
done: done
ok: OK
+8
View File
@@ -1413,6 +1413,10 @@
"deprecated_tags": {
"message": "Deprecated tags: {tags}"
},
"generic_name": {
"message": "{feature} has the generic name \"{name}\".",
"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."
@@ -1482,6 +1486,10 @@
"connect_almost_junction": {
"title": "Connect the features",
"undo_redo": "Connected two features that were really close."
},
"remove_name": {
"title": "Remove the name",
"undo_redo": "Removed a generic name."
}
}
},
+1
View File
@@ -22,6 +22,7 @@ export { utilKeybinding } from './keybinding';
export { utilNoAuto } from './util';
export { utilPrefixCSSProperty } from './util';
export { utilPrefixDOMProperty } from './util';
export { utilPreset } from './util';
export { utilQsString } from './util';
export { utilRebind } from './rebind';
export { utilSetTransform } from './util';
+6 -1
View File
@@ -129,7 +129,7 @@ export function utilDisplayLabel(entity, context) {
// use the display name if there is one
return displayName;
}
var preset = context.presets().match(entity, context.graph());
var preset = utilPreset(entity, context);
if (preset && preset.name()) {
// use the preset name if there is a match
return preset.name();
@@ -139,6 +139,11 @@ export function utilDisplayLabel(entity, context) {
}
export function utilPreset(entity, context) {
return context.presets().match(entity, context.graph());
}
export function utilEntityRoot(entityType) {
return {
node: 'n',
+39 -9
View File
@@ -1,7 +1,21 @@
import _clone from 'lodash-es/clone';
import { t } from '../util/locale';
import {
utilPreset
} from '../util';
import {
ValidationIssueType,
ValidationIssueSeverity,
validationIssue,
validationIssueFix
} from './validation_issue';
import {
actionChangeTags
} from '../actions';
import { discardNames } from '../../node_modules/name-suggestion-index/config/filters.json';
export function validationGenericName() {
export function validationGenericName(context) {
function isGenericName(entity) {
var name = entity.tags.name;
@@ -31,21 +45,37 @@ export function validationGenericName() {
return function validation(changes) {
var warnings = [];
var issues = [];
for (var i = 0; i < changes.created.length; i++) {
var change = changes.created[i];
var generic = isGenericName(change);
if (generic) {
warnings.push({
id: 'generic_name',
message: t('validations.generic_name'),
tooltip: t('validations.generic_name_tooltip', { name: generic }),
entity: change
});
var preset = utilPreset(change, context);
issues.push(new validationIssue({
type: ValidationIssueType.generic_name,
severity: ValidationIssueSeverity.warning,
message: t('issues.generic_name.message', {feature: preset.name(), name: generic}),
tooltip: t('issues.generic_name.tooltip'),
entities: [change],
fixes: [
new validationIssueFix({
title: t('issues.fix.remove_name.title'),
action: function() {
var entity = this.issue.entities[0];
var tags = _clone(entity.tags);
tags.name = undefined;
context.perform(
actionChangeTags(entity.id, tags),
t('issues.fix.remove_name.undo_redo')
);
}
})
]
}));
}
}
return warnings;
return issues;
};
}
+1
View File
@@ -12,6 +12,7 @@ var ValidationIssueType = Object.freeze({
map_rule_issue: 'map_rule_issue',
crossing_ways: 'crossing_ways',
highway_almost_junction: 'highway_almost_junction',
generic_name: 'generic_name'
});