Skip to content

Commit

Permalink
Replace "Use different layers" non-actionable quick fix with actionab…
Browse files Browse the repository at this point in the history
…le quick fixes for setting a higher or lower layer (close #5943)
  • Loading branch information
quincylvania committed Apr 1, 2019
1 parent 2e7a47d commit d5d4323
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
4 changes: 4 additions & 0 deletions data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
59 changes: 54 additions & 5 deletions modules/validations/crossing_ways.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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')
Expand All @@ -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 = {};
};
Expand Down

0 comments on commit d5d4323

Please sign in to comment.