From fd41e5fd7537edb4ece1c671d6ba9c6671db3a16 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 8 Jun 2020 11:16:25 -0400 Subject: [PATCH] Add specific error feedback for disabled straighten operation for multiple selected features --- data/core.yaml | 12 +++++-- dist/locales/en.json | 15 +++++++-- modules/operations/straighten.js | 55 ++++++++++++++++---------------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 2c5babc66..16bc84950 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -174,9 +174,15 @@ en: points: Straightened several points. line: Straightened a line. lines: Straightened several lines. - too_bendy: This can't be straightened because it bends too much. - connected_to_hidden: This can't be straightened because it is connected to a hidden feature. - not_downloaded: This can't be straightened because parts of it have not yet been downloaded. + too_bendy: + single: This can't be straightened because it bends too much. + multiple: These can't be straighted because they bend too much. + connected_to_hidden: + single: This can't be straightened because it is connected to a hidden feature. + multiple: These can't be straightened because some are connected to hidden features. + not_downloaded: + single: This can't be straightened because parts of it have not yet been downloaded. + multiple: These can't be straightened because parts of them have not yet been downloaded. too_large: single: This can't be straightened because not enough of it is currently visible. multiple: These can't be straightened because not enough of them are currently visible. diff --git a/dist/locales/en.json b/dist/locales/en.json index 91aed26e2..8dec84130 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -229,9 +229,18 @@ "line": "Straightened a line.", "lines": "Straightened several lines." }, - "too_bendy": "This can't be straightened because it bends too much.", - "connected_to_hidden": "This can't be straightened because it is connected to a hidden feature.", - "not_downloaded": "This can't be straightened because parts of it have not yet been downloaded.", + "too_bendy": { + "single": "This can't be straightened because it bends too much.", + "multiple": "These can't be straighted because they bend too much." + }, + "connected_to_hidden": { + "single": "This can't be straightened because it is connected to a hidden feature.", + "multiple": "These can't be straightened because some are connected to hidden features." + }, + "not_downloaded": { + "single": "This can't be straightened because parts of it have not yet been downloaded.", + "multiple": "These can't be straightened because parts of them have not yet been downloaded." + }, "too_large": { "single": "This can't be straightened because not enough of it is currently visible.", "multiple": "These can't be straightened because not enough of them are currently visible." diff --git a/modules/operations/straighten.js b/modules/operations/straighten.js index cc6293255..ae2e744dd 100644 --- a/modules/operations/straighten.js +++ b/modules/operations/straighten.js @@ -7,26 +7,27 @@ import { utilArrayDifference, utilGetAllNodes } from '../util/index'; export function operationStraighten(context, selectedIDs) { - var wayIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'w'; }); - var nodeIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'n'; }); + var _wayIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'w'; }); + var _nodeIDs = selectedIDs.filter(function(id) { return id.charAt(0) === 'n'; }); + var _amount = ((_wayIDs.length ? _wayIDs : _nodeIDs).length === 1 ? 'single' : 'multiple'); - var nodes = utilGetAllNodes(selectedIDs, context.graph()); - var coords = nodes.map(function(n) { return n.loc; }); - var extent = nodes.reduce(function(extent, node) { + var _nodes = utilGetAllNodes(selectedIDs, context.graph()); + var _coords = _nodes.map(function(n) { return n.loc; }); + var _extent = _nodes.reduce(function(extent, node) { return extent.extend(node.extent(context.graph())); }, geoExtent()); - var action = chooseAction(); - var geometry; + var _action = chooseAction(); + var _geometry; function chooseAction() { // straighten selected nodes - if (wayIDs.length === 0 && nodeIDs.length > 2) { - geometry = 'points'; - return actionStraightenNodes(nodeIDs, context.projection); + if (_wayIDs.length === 0 && _nodeIDs.length > 2) { + _geometry = 'points'; + return actionStraightenNodes(_nodeIDs, context.projection); // straighten selected ways (possibly between range of 2 selected nodes) - } else if (wayIDs.length > 0 && (nodeIDs.length === 0 || nodeIDs.length === 2)) { + } else if (_wayIDs.length > 0 && (_nodeIDs.length === 0 || _nodeIDs.length === 2)) { var startNodeIDs = []; var endNodeIDs = []; @@ -55,23 +56,23 @@ export function operationStraighten(context, selectedIDs) { utilArrayDifference(endNodeIDs, startNodeIDs).length !== 2) return null; // Ensure path contains at least 3 unique nodes - var wayNodeIDs = utilGetAllNodes(wayIDs, context.graph()) + var wayNodeIDs = utilGetAllNodes(_wayIDs, context.graph()) .map(function(node) { return node.id; }); if (wayNodeIDs.length <= 2) return null; // If range of 2 selected nodes is supplied, ensure nodes lie on the selected path - if (nodeIDs.length === 2 && ( - wayNodeIDs.indexOf(nodeIDs[0]) === -1 || wayNodeIDs.indexOf(nodeIDs[1]) === -1 + if (_nodeIDs.length === 2 && ( + wayNodeIDs.indexOf(_nodeIDs[0]) === -1 || wayNodeIDs.indexOf(_nodeIDs[1]) === -1 )) return null; - if (nodeIDs.length) { + if (_nodeIDs.length) { // If we're only straightenting between two points, we only need that extent visible - extent = utilGetAllNodes(nodeIDs, context.graph()).reduce(function(extent, node) { + _extent = utilGetAllNodes(_nodeIDs, context.graph()).reduce(function(extent, node) { return extent.extend(node.extent(context.graph())); }, geoExtent()); } - geometry = wayIDs.length === 1 ? 'line' : 'lines'; + _geometry = _wayIDs.length === 1 ? 'line' : 'lines'; return actionStraightenWay(selectedIDs, context.projection); } @@ -80,9 +81,9 @@ export function operationStraighten(context, selectedIDs) { function operation() { - if (!action) return; + if (!_action) return; - context.perform(action, operation.annotation()); + context.perform(_action, operation.annotation()); window.setTimeout(function() { context.validator().validate(); @@ -91,16 +92,16 @@ export function operationStraighten(context, selectedIDs) { operation.available = function() { - return Boolean(action); + return Boolean(_action); }; operation.disabled = function() { - var reason = action.disabled(context.graph()); + var reason = _action.disabled(context.graph()); if (reason) { return reason; - } else if (extent.percentContainedIn(context.map().extent()) < 0.8) { - return 'too_large.' + ((wayIDs.length ? wayIDs : nodeIDs).length === 1 ? 'single' : 'multiple'); + } else if (_extent.percentContainedIn(context.map().extent()) < 0.8) { + return 'too_large'; } else if (someMissing()) { return 'not_downloaded'; } else if (selectedIDs.some(context.hasHiddenConnections)) { @@ -114,7 +115,7 @@ export function operationStraighten(context, selectedIDs) { if (context.inIntro()) return false; var osm = context.connection(); if (osm) { - var missing = coords.filter(function(loc) { return !osm.isDataLoaded(loc); }); + var missing = _coords.filter(function(loc) { return !osm.isDataLoaded(loc); }); if (missing.length) { missing.forEach(function(loc) { context.loadTileAtLoc(loc); }); return true; @@ -128,13 +129,13 @@ export function operationStraighten(context, selectedIDs) { operation.tooltip = function() { var disable = operation.disabled(); return disable ? - t('operations.straighten.' + disable) : - t('operations.straighten.description.' + geometry); + t('operations.straighten.' + disable + '.' + _amount) : + t('operations.straighten.description.' + _geometry); }; operation.annotation = function() { - return t('operations.straighten.annotation.' + geometry); + return t('operations.straighten.annotation.' + _geometry); };