mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Flag and upgrade deprecated tags in a semicolon-delimited tag value (close #6038)
This commit is contained in:
@@ -8,8 +8,17 @@ export function actionUpgradeTags(entityId, oldTags, replaceTags) {
|
||||
for (var oldTagKey in oldTags) {
|
||||
if (oldTags[oldTagKey] === '*') {
|
||||
transferValue = tags[oldTagKey];
|
||||
delete tags[oldTagKey];
|
||||
} else {
|
||||
var vals = tags[oldTagKey].split(';').filter(Boolean);
|
||||
var oldIndex = vals.indexOf(oldTags[oldTagKey]);
|
||||
if (vals.length === 1 || oldIndex === -1) {
|
||||
delete tags[oldTagKey];
|
||||
} else {
|
||||
vals.splice(oldIndex, 1);
|
||||
tags[oldTagKey] = vals.join(';');
|
||||
}
|
||||
}
|
||||
delete tags[oldTagKey];
|
||||
}
|
||||
if (replaceTags) {
|
||||
for (var replaceKey in replaceTags) {
|
||||
|
||||
@@ -173,7 +173,12 @@ osmEntity.prototype = {
|
||||
var deprecated = [];
|
||||
dataDeprecated.forEach(function(d) {
|
||||
var matchesDeprecatedTags = _every(Object.keys(d.old), function(key) {
|
||||
return tags[key] && (d.old[key] === tags[key] || d.old[key] === '*');
|
||||
if (!tags[key]) return false;
|
||||
if (d.old[key] === '*') return true;
|
||||
|
||||
var vals = tags[key].split(';').filter(Boolean);
|
||||
if (!vals.length) return false;
|
||||
return vals.indexOf(d.old[key]) !== -1;
|
||||
});
|
||||
if (matchesDeprecatedTags) {
|
||||
deprecated.push(d);
|
||||
|
||||
@@ -56,4 +56,20 @@ describe('iD.actionUpgradeTags', function () {
|
||||
expect(graph.entity(entity.id).tags).to.eql({ shop: 'supermarket', name: 'Foo' });
|
||||
});
|
||||
|
||||
it('upgrades a tag in a semicolon-delimited list with one other value', function () {
|
||||
var oldTags = { cuisine: 'vegan' },
|
||||
newTags = { 'diet:vegan': 'yes' },
|
||||
entity = iD.Entity({ tags: { cuisine: 'italian;vegan', name: 'Foo' }}),
|
||||
graph = iD.actionUpgradeTags(entity.id, oldTags, newTags)(iD.coreGraph([entity]));
|
||||
expect(graph.entity(entity.id).tags).to.eql({ cuisine: 'italian', 'diet:vegan': 'yes', name: 'Foo' });
|
||||
});
|
||||
|
||||
it('upgrades a tag in a semicolon-delimited list with many other values', function () {
|
||||
var oldTags = { cuisine: 'vegan' },
|
||||
newTags = { 'diet:vegan': 'yes' },
|
||||
entity = iD.Entity({ tags: { cuisine: 'italian;vegan;regional;american', name: 'Foo' }}),
|
||||
graph = iD.actionUpgradeTags(entity.id, oldTags, newTags)(iD.coreGraph([entity]));
|
||||
expect(graph.entity(entity.id).tags).to.eql({ cuisine: 'italian;regional;american', 'diet:vegan': 'yes', name: 'Foo' });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user