Add links to the main error object in KeepRight error messages

re: https://github.com/openstreetmap/iD/issues/5679#issuecomment-452281850
This commit is contained in:
Bryan Housel
2019-01-10 17:38:09 -05:00
parent 98c08a02ef
commit 7f321abbaf
6 changed files with 381 additions and 236 deletions
+41 -3
View File
@@ -109,8 +109,11 @@ function tokenReplacements(d) {
capture = parseError(capture, idType);
} else if (htmlRegex.test(capture)) { // escape any html in non-IDs
capture = '\\' + capture + '\\';
} else if (localizeStrings[capture]) { // some replacement strings can be localized
capture = t('QA.keepRight.error_parts.' + localizeStrings[capture]);
} else {
var compare = capture.toLowerCase();
if (localizeStrings[compare]) { // some replacement strings can be localized
capture = t('QA.keepRight.error_parts.' + localizeStrings[compare]);
}
}
replacements['var' + i] = capture;
@@ -121,9 +124,18 @@ function tokenReplacements(d) {
function parseError(capture, idType) {
var compare = capture.toLowerCase();
if (localizeStrings[compare]) { // some replacement strings can be localized
capture = t('QA.keepRight.error_parts.' + localizeStrings[compare]);
}
switch (idType) {
// simple case just needs a linking span
// link a string like "this node"
case 'this':
capture = linkErrorObject(capture);
break;
// link an entity ID
case 'n':
case 'w':
case 'r':
@@ -151,6 +163,10 @@ function parseError(capture, idType) {
return capture;
function linkErrorObject(d) {
return '<a class="kr_error_object_link">' + d + '</a>';
}
function linkEntity(d) {
return '<a class="kr_error_entity_link">' + d + '</a>';
}
@@ -305,6 +321,28 @@ export default {
// try to handle error type directly, fallback to parent error type.
var whichType = errorTemplate ? errorType : parentErrorType;
// Rewrite a few of the errors at this point..
// This is done to make them easier to linkify and translate.
switch (whichType) {
case '170':
props.description = 'This feature has a FIXME tag: ' + props.description;
break;
case '292':
case '293':
props.description = props.description.replace('A turn-', 'This turn-');
break;
case '294':
case '295':
case '296':
case '297':
case '298':
props.description = 'This turn-restriction~' + props.description;
break;
case '300':
props.description = 'This highway is missing a maxspeed tag';
break;
}
// - move markers slightly so it doesn't obscure the geometry,
// - then move markers away from other coincident markers
var coincident = false;
+19 -6
View File
@@ -6,7 +6,7 @@ import {
import { dataEn } from '../../data';
import { modeSelect } from '../modes';
import { t } from '../util/locale';
import { utilDisplayName, utilEntityOrMemberSelector } from '../util';
import { utilDisplayName, utilEntityOrMemberSelector, utilEntityRoot } from '../util';
export function uiKeepRightDetails(context) {
@@ -31,7 +31,8 @@ export function uiKeepRightDetails(context) {
} else {
detail = unknown;
}
return detail.substr(0, 1).toUpperCase() + detail.substr(1);
return detail;
}
@@ -65,10 +66,13 @@ export function uiKeepRightDetails(context) {
.html(errorDetail);
// If there are entity links in the error message..
descriptionEnter.selectAll('.kr_error_entity_link')
descriptionEnter.selectAll('.kr_error_entity_link, .kr_error_object_link')
.each(function() {
var link = d3_select(this);
var entityID = this.innerText;
var isObjectLink = link.classed('kr_error_object_link');
var entityID = isObjectLink ?
(utilEntityRoot(_error.object_type) + _error.object_id)
: this.textContent;
var entity = context.hasEntity(entityID);
// Add click handler
@@ -87,15 +91,24 @@ export function uiKeepRightDetails(context) {
if (!osmlayer.enabled()) {
osmlayer.enabled(true);
}
context.map().centerZoom(_error.loc, 20);
context.enter(modeSelect(context, [entityID]));
if (entity) {
context.enter(modeSelect(context, [entityID]));
} else {
context.loadEntity(entityID, function() {
context.enter(modeSelect(context, [entityID]));
});
}
});
// Replace with friendly name if possible
// (The entity may not yet be loaded into the graph)
if (entity) {
var name = utilDisplayName(entity); // try to use common name
if (!name) {
if (!name && !isObjectLink) {
var preset = context.presets().match(entity, context.graph());
name = preset && !preset.isFallback() && preset.name(); // fallback to preset name
}