mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
For ice rinks, prefer the "sport" values "ice_hockey" and "ice_skating" instead of "hockey" and "skating" since that latter are ambiguous
Don't remove other values when upgrading a tag value within a semicolon-delimited list
This commit is contained in:
@@ -447,6 +447,14 @@
|
||||
"old": {"leisure": "club"},
|
||||
"replace": {"club": "*"}
|
||||
},
|
||||
{
|
||||
"old": {"leisure": "ice_rink", "sport": "hockey"},
|
||||
"replace": {"leisure": "ice_rink", "sport": "ice_hockey"}
|
||||
},
|
||||
{
|
||||
"old": {"leisure": "ice_rink", "sport": "skating"},
|
||||
"replace": {"leisure": "ice_rink", "sport": "ice_skating"}
|
||||
},
|
||||
{
|
||||
"old": {"leisure": "social_club"},
|
||||
"replace": {"club": "*"}
|
||||
|
||||
@@ -337,7 +337,7 @@
|
||||
"social_facility_for": {"key": "social_facility:for", "type": "combo", "label": "People Served"},
|
||||
"social_facility": {"key": "social_facility", "type": "combo", "label": "Type"},
|
||||
"source": {"key": "source", "type": "semiCombo", "icon": "source", "universal": true, "label": "Sources", "snake_case": false, "caseSensitive": true, "options": ["survey", "local knowledge", "gps", "aerial imagery", "streetlevel imagery"]},
|
||||
"sport_ice": {"key": "sport", "type": "semiCombo", "label": "Sports", "options": ["skating", "hockey", "multi", "curling", "ice_stock"]},
|
||||
"sport_ice": {"key": "sport", "type": "semiCombo", "label": "Sports", "options": ["ice_skating", "ice_hockey", "multi", "curling", "ice_stock"]},
|
||||
"sport_racing_motor": {"key": "sport", "type": "semiCombo", "label": "Sports", "options": ["motor", "karting", "motocross"]},
|
||||
"sport_racing_nonmotor": {"key": "sport", "type": "semiCombo", "label": "Sports", "options": ["bmx", "cycling", "dog_racing", "horse_racing", "running"]},
|
||||
"sport": {"key": "sport", "type": "semiCombo", "label": "Sports"},
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
"type": "semiCombo",
|
||||
"label": "Sports",
|
||||
"options": [
|
||||
"skating",
|
||||
"hockey",
|
||||
"ice_skating",
|
||||
"ice_hockey",
|
||||
"multi",
|
||||
"curling",
|
||||
"ice_stock"
|
||||
|
||||
@@ -4,6 +4,7 @@ export function actionUpgradeTags(entityId, oldTags, replaceTags) {
|
||||
var entity = graph.entity(entityId);
|
||||
var tags = Object.assign({}, entity.tags); // shallow copy
|
||||
var transferValue;
|
||||
var semiIndex;
|
||||
|
||||
for (var oldTagKey in oldTags) {
|
||||
if (oldTags[oldTagKey] === '*') {
|
||||
@@ -15,6 +16,10 @@ export function actionUpgradeTags(entityId, oldTags, replaceTags) {
|
||||
if (vals.length === 1 || oldIndex === -1) {
|
||||
delete tags[oldTagKey];
|
||||
} else {
|
||||
if (replaceTags && replaceTags[oldTagKey]) {
|
||||
// replacing a value within a semicolon-delimited value, note the index
|
||||
semiIndex = oldIndex;
|
||||
}
|
||||
vals.splice(oldIndex, 1);
|
||||
tags[oldTagKey] = vals.join(';');
|
||||
}
|
||||
@@ -36,7 +41,16 @@ export function actionUpgradeTags(entityId, oldTags, replaceTags) {
|
||||
} else if (replaceValue === '$1') {
|
||||
tags[replaceKey] = transferValue;
|
||||
} else {
|
||||
tags[replaceKey] = replaceValue;
|
||||
if (tags[replaceKey] && oldTags[replaceKey] && semiIndex !== undefined) {
|
||||
// don't override preexisting values
|
||||
var existingVals = tags[replaceKey].split(';').filter(Boolean);
|
||||
if (existingVals.indexOf(replaceValue) === -1) {
|
||||
existingVals.splice(semiIndex, 0, replaceValue);
|
||||
tags[replaceKey] = existingVals.join(';');
|
||||
}
|
||||
} else {
|
||||
tags[replaceKey] = replaceValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,14 @@ describe('iD.actionUpgradeTags', function () {
|
||||
expect(graph.entity(entity.id).tags).to.eql({ natural: 'wetland', wetland: 'marsh', name: 'Foo' });
|
||||
});
|
||||
|
||||
it('upgrades a tag and overrides an existing value', function () {
|
||||
var oldTags = { landuse: 'wood' },
|
||||
newTags = { natural: 'wood' },
|
||||
entity = iD.Entity({ tags: { landuse: 'wood', natural: 'wetland', name: 'Foo' }}),
|
||||
graph = iD.actionUpgradeTags(entity.id, oldTags, newTags)(iD.coreGraph([entity]));
|
||||
expect(graph.entity(entity.id).tags).to.eql({ natural: 'wood', name: 'Foo' });
|
||||
});
|
||||
|
||||
it('upgrades a tag with no replacement tags', function () {
|
||||
var oldTags = { highway: 'no' },
|
||||
newTags = undefined,
|
||||
@@ -56,7 +64,7 @@ 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 () {
|
||||
it('upgrades a tag from a semicolon-delimited list that has one other value', function () {
|
||||
var oldTags = { cuisine: 'vegan' },
|
||||
newTags = { 'diet:vegan': 'yes' },
|
||||
entity = iD.Entity({ tags: { cuisine: 'italian;vegan', name: 'Foo' }}),
|
||||
@@ -64,7 +72,7 @@ describe('iD.actionUpgradeTags', function () {
|
||||
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 () {
|
||||
it('upgrades a tag from a semicolon-delimited list that has many other values', function () {
|
||||
var oldTags = { cuisine: 'vegan' },
|
||||
newTags = { 'diet:vegan': 'yes' },
|
||||
entity = iD.Entity({ tags: { cuisine: 'italian;vegan;regional;american', name: 'Foo' }}),
|
||||
@@ -72,4 +80,12 @@ describe('iD.actionUpgradeTags', function () {
|
||||
expect(graph.entity(entity.id).tags).to.eql({ cuisine: 'italian;regional;american', 'diet:vegan': 'yes', name: 'Foo' });
|
||||
});
|
||||
|
||||
it('upgrades a tag within a semicolon-delimited list without changing other values', function () {
|
||||
var oldTags = { leisure: 'ice_rink', sport: 'hockey' },
|
||||
newTags = { leisure: 'ice_rink', sport: 'ice_hockey' },
|
||||
entity = iD.Entity({ tags: { leisure: 'ice_rink', sport: 'curling;hockey;multi', name: 'Foo' }}),
|
||||
graph = iD.actionUpgradeTags(entity.id, oldTags, newTags)(iD.coreGraph([entity]));
|
||||
expect(graph.entity(entity.id).tags).to.eql({ leisure: 'ice_rink', sport: 'curling;ice_hockey;multi', name: 'Foo' });
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user