mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-19 23:14:47 +02:00
Generalize deprecated_tags validation to outdated_tags validation
Add check for missing addTags go outdated_tags validation (close #6043, close #6042)
This commit is contained in:
@@ -1,88 +0,0 @@
|
||||
import _clone from 'lodash-es/clone';
|
||||
|
||||
import { t } from '../util/locale';
|
||||
import { actionUpgradeTags, actionChangeTags } from '../actions';
|
||||
import { utilDisplayLabel, utilTagText } from '../util';
|
||||
import { validationIssue, validationIssueFix } from '../core/validator';
|
||||
|
||||
export function validationDeprecatedTag() {
|
||||
var type = 'deprecated_tag';
|
||||
|
||||
|
||||
var validation = function(entity, context) {
|
||||
var issues = [];
|
||||
var deprecatedTagsArray = entity.deprecatedTags();
|
||||
if (deprecatedTagsArray.length > 0) {
|
||||
for (var deprecatedTagIndex in deprecatedTagsArray) {
|
||||
var deprecatedTags = deprecatedTagsArray[deprecatedTagIndex];
|
||||
var labelTags = _clone(deprecatedTags.old);
|
||||
for (var key in labelTags) {
|
||||
if (labelTags[key] === '*') {
|
||||
// show the user the actual tag, like color=red instead of color=*
|
||||
labelTags[key] = entity.tags[key];
|
||||
}
|
||||
}
|
||||
var tagsLabel = utilTagText({ tags: labelTags });
|
||||
var featureLabel = utilDisplayLabel(entity, context);
|
||||
var isCombo = Object.keys(deprecatedTags.old).length > 1;
|
||||
var messageObj = { feature: featureLabel };
|
||||
if (isCombo) {
|
||||
messageObj.tags = tagsLabel;
|
||||
} else {
|
||||
messageObj.tag = tagsLabel;
|
||||
}
|
||||
var tagMessageID = isCombo ? 'combination' : 'single';
|
||||
issues.push(new validationIssue({
|
||||
type: type,
|
||||
severity: 'warning',
|
||||
message: t('issues.deprecated_tag.' + tagMessageID + '.message', messageObj),
|
||||
tooltip: t('issues.deprecated_tag.tip'),
|
||||
entities: [entity],
|
||||
hash: tagsLabel,
|
||||
info: {
|
||||
oldTags: deprecatedTags.old,
|
||||
replaceTags: deprecatedTags.replace
|
||||
},
|
||||
fixes: [
|
||||
new validationIssueFix({
|
||||
icon: 'iD-icon-up',
|
||||
title: t('issues.fix.' + (isCombo ? 'upgrade_tag_combo' : 'upgrade_tag') + '.title'),
|
||||
onClick: function() {
|
||||
var oldTags = this.issue.info.oldTags;
|
||||
var replaceTags = this.issue.info.replaceTags;
|
||||
var fixTextID = Object.keys(oldTags).length > 1 ? 'upgrade_tag_combo' : 'upgrade_tag';
|
||||
context.perform(
|
||||
actionUpgradeTags(this.issue.entities[0].id, oldTags, replaceTags),
|
||||
t('issues.fix.' + fixTextID + '.annotation')
|
||||
);
|
||||
}
|
||||
}),
|
||||
new validationIssueFix({
|
||||
icon: 'iD-operation-delete',
|
||||
title: t('issues.fix.' + (isCombo ? 'remove_tags' : 'remove_tag') + '.title'),
|
||||
onClick: function() {
|
||||
var entity = this.issue.entities[0];
|
||||
var tags = _clone(entity.tags);
|
||||
var oldTags = this.issue.info.oldTags;
|
||||
for (var key in oldTags) {
|
||||
delete tags[key];
|
||||
}
|
||||
var fixTextID = Object.keys(oldTags).length > 1 ? 'remove_deprecated_tag_combo' : 'remove_deprecated_tag';
|
||||
context.perform(
|
||||
actionChangeTags(entity.id, tags),
|
||||
t('issues.fix.' + fixTextID + '.annotation')
|
||||
);
|
||||
}
|
||||
})
|
||||
]
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
return issues;
|
||||
};
|
||||
|
||||
validation.type = type;
|
||||
|
||||
return validation;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
export { validationAlmostJunction } from './almost_junction';
|
||||
export { validationCrossingWays } from './crossing_ways';
|
||||
export { validationDeprecatedTag } from './deprecated_tag';
|
||||
export { validationDisconnectedWay } from './disconnected_way';
|
||||
export { validationGenericName } from './generic_name';
|
||||
export { validationManyDeletions } from './many_deletions';
|
||||
@@ -8,4 +7,5 @@ export { validationMaprules } from './maprules';
|
||||
export { validationMissingRole } from './missing_role';
|
||||
export { validationMissingTag } from './missing_tag';
|
||||
export { validationOldMultipolygon } from './old_multipolygon';
|
||||
export { validationOutdatedTags } from './outdated_tags';
|
||||
export { validationTagSuggestsArea } from './tag_suggests_area';
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import _clone from 'lodash-es/clone';
|
||||
|
||||
import { t } from '../util/locale';
|
||||
import { actionUpgradeTags, actionChangeTags } from '../actions';
|
||||
import { utilDisplayLabel } from '../util';
|
||||
import { validationIssue, validationIssueFix } from '../core/validator';
|
||||
|
||||
export function validationOutdatedTags() {
|
||||
var type = 'outdated_tags';
|
||||
|
||||
|
||||
var validation = function(entity, context) {
|
||||
|
||||
var deprecatedTagsArray = entity.deprecatedTags();
|
||||
|
||||
var preset = context.presets().match(entity, context.graph());
|
||||
var missingRecommendedTags = {};
|
||||
if (!preset.isFallback() && preset.tags !== preset.addTags) {
|
||||
missingRecommendedTags = Object.keys(preset.addTags).reduce(function(obj, key) {
|
||||
if (!entity.tags[key]) {
|
||||
obj[key] = preset.addTags[key];
|
||||
}
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
if (deprecatedTagsArray.length === 0 &&
|
||||
Object.keys(missingRecommendedTags).length === 0) return [];
|
||||
|
||||
return [new validationIssue({
|
||||
type: type,
|
||||
severity: 'warning',
|
||||
message: t('issues.outdated_tags.message', { feature: utilDisplayLabel(entity, context) }),
|
||||
tooltip: t('issues.outdated_tags.tip'),
|
||||
entities: [entity],
|
||||
info: {
|
||||
deprecatedTagsArray: deprecatedTagsArray,
|
||||
missingRecommendedTags: missingRecommendedTags
|
||||
},
|
||||
fixes: [
|
||||
new validationIssueFix({
|
||||
icon: 'iD-icon-up',
|
||||
title: t('issues.fix.upgrade_tags.title'),
|
||||
onClick: function() {
|
||||
var deprecatedTagsArray = this.issue.info.deprecatedTagsArray;
|
||||
var missingRecommendedTags = this.issue.info.missingRecommendedTags;
|
||||
var entityID = this.issue.entities[0].id;
|
||||
context.perform(
|
||||
function(graph) {
|
||||
deprecatedTagsArray.forEach(function(deprecatedTags) {
|
||||
graph = actionUpgradeTags(entityID, deprecatedTags.old, deprecatedTags.replace)(graph);
|
||||
});
|
||||
var tags = _clone(graph.entity(entityID).tags);
|
||||
for (var key in missingRecommendedTags) {
|
||||
tags[key] = missingRecommendedTags[key];
|
||||
}
|
||||
graph = actionChangeTags(entityID, tags)(graph);
|
||||
return graph;
|
||||
},
|
||||
t('issues.fix.upgrade_tags.annotation')
|
||||
);
|
||||
}
|
||||
})
|
||||
]
|
||||
})];
|
||||
};
|
||||
|
||||
validation.type = type;
|
||||
|
||||
return validation;
|
||||
}
|
||||
Reference in New Issue
Block a user