From d5d4323c02be86f2133f340113933341ae5d2c37 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 1 Apr 2019 11:52:04 -0400 Subject: [PATCH] Replace "Use different layers" non-actionable quick fix with actionable quick fixes for setting a higher or lower layer (close #5943) --- data/core.yaml | 4 ++ dist/locales/en.json | 6 +++ modules/validations/crossing_ways.js | 59 +++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 07dccc87c..1f04f2d41 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1363,6 +1363,10 @@ en: tag_as_disconnected: title: Tag as disconnected annotation: Tagged very close features as disconnected. + tag_this_as_higher: + title: Tag this as higher + tag_this_as_lower: + title: Tag this as lower upgrade_tags: title: Upgrade the tags annotation: Upgraded old tags. diff --git a/dist/locales/en.json b/dist/locales/en.json index fb4e60742..e587ef77d 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1685,6 +1685,12 @@ "title": "Tag as disconnected", "annotation": "Tagged very close features as disconnected." }, + "tag_this_as_higher": { + "title": "Tag this as higher" + }, + "tag_this_as_lower": { + "title": "Tag this as lower" + }, "upgrade_tags": { "title": "Upgrade the tags", "annotation": "Upgraded old tags." diff --git a/modules/validations/crossing_ways.js b/modules/validations/crossing_ways.js index b3cfeb31a..ac27778a9 100644 --- a/modules/validations/crossing_ways.js +++ b/modules/validations/crossing_ways.js @@ -1,4 +1,4 @@ -import { actionAddMidpoint, actionMergeNodes } from '../actions'; +import { actionAddMidpoint, actionChangeTags, actionMergeNodes } from '../actions'; import { geoExtent, geoLineIntersection, geoSphericalClosestNode } from '../geo'; import { osmNode } from '../osm'; import { t } from '../util/locale'; @@ -482,10 +482,15 @@ export function validationCrossingWays() { } else { useFixID = 'use_different_layers'; } - fixes.push(new validationIssueFix({ - icon: useFixIcon, - title: t('issues.fix.' + useFixID + '.title') - })); + if (useFixID === 'use_different_layers') { + fixes.push(makeChangeLayerFix('higher', context)); + fixes.push(makeChangeLayerFix('lower', context)); + } else { + fixes.push(new validationIssueFix({ + icon: useFixIcon, + title: t('issues.fix.' + useFixID + '.title') + })); + } fixes.push(new validationIssueFix({ icon: 'iD-operation-move', title: t('issues.fix.reposition_features.title') @@ -502,6 +507,50 @@ export function validationCrossingWays() { }); } + function makeChangeLayerFix(higherOrLower, context) { + return new validationIssueFix({ + icon: 'iD-icon-' + (higherOrLower === 'higher' ? 'up' : 'down'), + title: t('issues.fix.tag_this_as_' + higherOrLower + '.title'), + onClick: function() { + + var mode = context.mode(); + if (!mode || mode.id !== 'select') return; + + var selectedIDs = mode.selectedIDs(); + if (selectedIDs.length !== 1) return; + + var selectedID = selectedIDs[0]; + if (!this.issue.entities.some(function(entity) { + return entity.id === selectedID; + })) return; + + var entity = context.hasEntity(selectedID); + if (!entity) return; + + var tags = Object.assign({}, entity.tags); // shallow copy + var layer = tags.layer && Number(tags.layer); + if (layer && !isNaN(layer)) { + if (higherOrLower === 'higher') { + layer += 1; + } else { + layer -= 1; + } + } else { + if (higherOrLower === 'higher') { + layer = 1; + } else { + layer = -1; + } + } + tags.layer = layer; + context.perform( + actionChangeTags(entity.id, tags), + t('operations.change_tags.annotation') + ); + } + }); + } + validation.reset = function() { issueCache = {}; };