From 33d02cdba00f2de07ac07e1934d3c0691b53b619 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Wed, 6 Feb 2019 09:38:33 -0500 Subject: [PATCH] Add different messages for no tags vs. no descriptive tags warnings Add warning for relation without a "type" tag --- data/core.yaml | 7 ++- dist/locales/en.json | 10 +++- modules/validations/missing_tag.js | 81 +++++++++++++++++++----------- 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 553d9de12..4b6b67dc3 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1228,7 +1228,12 @@ en: message: "Deleting {n} features: {p} points, {l} lines, {a} areas, and {r} relations." tip: Only redundant or nonexistent features should be deleted. missing_tag: - message: "{feature} has no descriptive tags." + any: + message: "{feature} has no tags." + descriptive: + message: "{feature} has no descriptive tags." + specific: + message: '{feature} has no "{tag}" tag.' tip: Features must have tags that define what they are. old_multipolygon: message: "{multipolygon} has misplaced tags." diff --git a/dist/locales/en.json b/dist/locales/en.json index 5c1fe45c5..af16c735a 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1503,7 +1503,15 @@ "tip": "Only redundant or nonexistent features should be deleted." }, "missing_tag": { - "message": "{feature} has no descriptive tags.", + "any": { + "message": "{feature} has no tags." + }, + "descriptive": { + "message": "{feature} has no descriptive tags." + }, + "specific": { + "message": "{feature} has no \"{tag}\" tag." + }, "tip": "Features must have tags that define what they are." }, "old_multipolygon": { diff --git a/modules/validations/missing_tag.js b/modules/validations/missing_tag.js index 8f0a8c13e..fff0d0811 100644 --- a/modules/validations/missing_tag.js +++ b/modules/validations/missing_tag.js @@ -1,4 +1,5 @@ import _without from 'lodash-es/without'; +import _isEmpty from 'lodash-es/isEmpty'; import { osmIsInterestingTag } from '../osm/tags'; import { t } from '../util/locale'; import { @@ -23,39 +24,59 @@ export function validationMissingTag() { var type = 'missing_tag'; var validation = function(entity, context) { - var types = ['point', 'line', 'area', 'relation']; - var issues = []; + var graph = context.graph(); - var geometry = entity.geometry(graph); - // ignore vertex features - if (types.indexOf(geometry) !== -1 && - !(hasDescriptiveTags(entity) || entity.hasParentRelations(graph))) { - var entityLabel = utilDisplayLabel(entity, context); - issues.push(new validationIssue({ - type: type, - // error if created or modified, else warning - severity: !entity.version || entity.v ? 'error' : 'warning', - message: t('issues.missing_tag.message', { feature: entityLabel }), - tooltip: t('issues.missing_tag.tip'), - entities: [entity], - fixes: [ - new validationIssueFix({ - title: t('issues.fix.select_preset.title'), - onClick: function() { - context.ui().sidebar.showPresetList(); - } - }), - new validationIssueFix({ - title: t('issues.fix.delete_feature.title'), - onClick: function() { - var id = this.issue.entities[0].id; - operationDelete([id], context)(); - } - }) - ] - })); + + // ignore vertex features and relation members + if (entity.geometry(graph) === 'vertex' || entity.hasParentRelations(graph)) { + return []; } + var messageObj = {}, missingTagType; + + if (_isEmpty(entity.tags)) { + missingTagType = 'any'; + + } else if (!hasDescriptiveTags(entity)) { + missingTagType = 'descriptive'; + + } else if (entity.type === 'relation' && !entity.tags.type) { + missingTagType = 'specific'; + messageObj.tag = 'type'; + } + + if (!missingTagType) { + return []; + } + + messageObj.feature = utilDisplayLabel(entity, context); + + var issues = []; + + issues.push(new validationIssue({ + type: type, + // error if created or modified, else warning + severity: !entity.version || entity.v ? 'error' : 'warning', + message: t('issues.missing_tag.'+missingTagType+'.message', messageObj), + tooltip: t('issues.missing_tag.tip'), + entities: [entity], + fixes: [ + new validationIssueFix({ + title: t('issues.fix.select_preset.title'), + onClick: function() { + context.ui().sidebar.showPresetList(); + } + }), + new validationIssueFix({ + title: t('issues.fix.delete_feature.title'), + onClick: function() { + var id = this.issue.entities[0].id; + operationDelete([id], context)(); + } + }) + ] + })); + return issues; };