diff --git a/data/locales.js b/data/locales.js index eebbd3daf..d33af171b 100644 --- a/data/locales.js +++ b/data/locales.js @@ -1042,6 +1042,14 @@ locale.en = { "name": "Office", "terms": "" }, + "other": { + "name": "Other", + "terms": "" + }, + "other_area": { + "name": "Other", + "terms": "" + }, "place": { "name": "Place", "terms": "" diff --git a/data/presets.yaml b/data/presets.yaml index 39ac13f76..2e1c54364 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -591,6 +591,12 @@ en: office: name: Office terms: "" + other: + name: Other + terms: "" + other_area: + name: Other + terms: "" place: name: Place terms: "" diff --git a/data/presets/presets.json b/data/presets/presets.json index 0bd1d3777..483b04fe7 100644 --- a/data/presets/presets.json +++ b/data/presets/presets.json @@ -2375,6 +2375,27 @@ "terms": [], "name": "Office" }, + "other": { + "name": "Other", + "tags": {}, + "geometry": [ + "point", + "vertex", + "line", + "area" + ], + "fields": [] + }, + "other_area": { + "name": "Other", + "tags": { + "area": "yes" + }, + "geometry": [ + "area" + ], + "fields": [] + }, "place": { "fields": [ "place" diff --git a/js/id/presets.js b/js/id/presets.js index e1a8cc97d..b0ad04358 100644 --- a/js/id/presets.js +++ b/js/id/presets.js @@ -3,19 +3,13 @@ iD.presets = function(context) { // an iD.presets.Collection with methods for // loading new data and returning defaults - var other = iD.presets.Preset('other', { - tags: {}, - geometry: ['point', 'vertex', 'line', 'area'] - }), - otherarea = iD.presets.Preset('other/area', { - tags: { area: 'yes' }, - geometry: ['area'] - }), - all = iD.presets.Collection([other, otherarea]), + var all = iD.presets.Collection([]), defaults = { area: all, line: all, point: all, vertex: all }, fields = {}, universal = [], - recent = iD.presets.Collection([]); + recent = iD.presets.Collection([]), + other, + other_area; all.load = function(d) { @@ -49,6 +43,9 @@ iD.presets = function(context) { }; } + other = all.item('other'); + other_area = all.item('other_area'); + return all; }; @@ -62,12 +59,13 @@ iD.presets = function(context) { all.defaults = function(entity, n) { var rec = recent.matchGeometry(entity, context.graph()).collection.slice(0, 4), - def = _.uniq(rec.concat(defaults[entity.geometry(context.graph())].collection)).slice(0, n - 1); - return iD.presets.Collection(_.unique(rec.concat(def).concat(other))); + def = _.uniq(rec.concat(defaults[entity.geometry(context.graph())].collection)).slice(0, n - 1), + geometry = entity.geometry(context.graph()); + return iD.presets.Collection(_.unique(rec.concat(def).concat(geometry === 'area' ? other_area : other))); }; all.choose = function(preset) { - if (preset !== other) { + if (preset !== other && preset !== other_area) { recent = iD.presets.Collection(_.unique([preset].concat(recent.collection))); } return all; diff --git a/js/id/presets/preset.js b/js/id/presets/preset.js index 8b8ba456f..8ebfb7297 100644 --- a/js/id/presets/preset.js +++ b/js/id/presets/preset.js @@ -65,7 +65,7 @@ iD.presets.Preset = function(id, preset, fields) { for (var f in preset.fields) { f = preset.fields[f]; - if (f.matchGeometry(geometry) && f.key && !tags[f.key]) { + if (f.matchGeometry(geometry) && f.key && !tags[f.key] && f['default']) { tags[f.key] = f['default']; } } diff --git a/test/spec/presets/preset.js b/test/spec/presets/preset.js index 126da1b86..6f1305966 100644 --- a/test/spec/presets/preset.js +++ b/test/spec/presets/preset.js @@ -1,46 +1,21 @@ describe('iD.presets.Preset', function() { - var fields = { - "building_area": iD.presets.Field("building_area", { - "key": "building", - "type": "check", - "geometry": ["area"], - "default": "yes" - }) - }; + var fields, p; + + beforeEach(function() { + if (!p) { + fields = {}; + var i = 0; + for (i in iD.data.presets.fields) { + fields[i] = iD.presets.Field(i, iD.data.presets.fields[i]); + } + p = {}; + for (i in iD.data.presets.presets) { + p[i] = iD.presets.Preset(i, iD.data.presets.presets[i], fields); + } + } + }); - var p = { - other: iD.presets.Preset('other', { - tags: {}, - geometry: ['point', 'vertex', 'line', 'area'] - }), - residential: iD.presets.Preset('highway/residential', { - tags: { - highway: 'residential' - }, - geometry: ['line'] - }), - tennis: iD.presets.Preset('leisure/pitch/tennis', { - tags: { - leisure: 'pitch', - sport: 'tennis' - }, - geometry: ['area'] - }), - building: iD.presets.Preset('building', { - tags: { - building: '*' - }, - geometry: ['area'] - }), - cafe: iD.presets.Preset('amenity/cafe', { - tags: { - amenity: 'cafe' - }, - geometry: ['point', 'area'], - fields: ['building_area'] - }, fields) - }; var w1 = iD.Way({ tags: { highway: 'motorway' }}), @@ -64,9 +39,9 @@ describe('iD.presets.Preset', function() { describe('#matchGeometry', function() { var n = iD.Node(); - var g = iD.Graph().replace(p); + var g = iD.Graph().replace(n); it("returns false if it doesn't match the entity type", function() { - expect(p.residential.matchGeometry(n, g)).to.equal(false); + expect(p['highway/residential'].matchGeometry(n, g)).to.equal(false); }); it("returns true if it does match the entity type", function() { @@ -76,7 +51,7 @@ describe('iD.presets.Preset', function() { describe('#matchTags', function() { it("returns -1 if preset does not match tags", function() { - expect(p.residential.matchTags(w1)).to.equal(-1); + expect(p['highway/residential'].matchTags(w1)).to.equal(-1); }); it("returns 0 for other preset (no match tags)", function() { @@ -84,8 +59,8 @@ describe('iD.presets.Preset', function() { }); it("returns the number of matched tags", function() { - expect(p.residential.matchTags(w3)).to.equal(1); - expect(p.tennis.matchTags(w2)).to.equal(2); + expect(p['highway/residential'].matchTags(w3)).to.equal(1); + expect(p['leisure/pitch/tennis'].matchTags(w2)).to.equal(2); }); it("counts * as a match for any value", function() { @@ -98,28 +73,30 @@ describe('iD.presets.Preset', function() { describe('#applyTags', function() { it("adds match tags", function() { - expect(p.residential.applyTags({}, 'area')).to.eql({ highway: 'residential' }); + console.log(p['highway/residential']); + console.log(p['highway/residential'].applyTags({}, 'area')); + expect(p['highway/residential'].applyTags({}, 'area')).to.eql({ highway: 'residential' }); }); it("does not add wildcard tags", function() { - expect(p.building.applyTags({}, 'area')).to.eql({}); + expect(p.amenity.applyTags({}, 'area')).to.eql({}); }); it("adds default tags", function() { - expect(p.cafe.applyTags({}, 'area')).to.eql({ amenity: 'cafe', building: 'yes'}); - expect(p.cafe.applyTags({}, 'point')).to.eql({ amenity: 'cafe' }); + expect(p['amenity/cafe'].applyTags({}, 'area')).to.eql({ amenity: 'cafe', building: 'yes'}); + expect(p['amenity/cafe'].applyTags({}, 'point')).to.eql({ amenity: 'cafe' }); }); }); describe('#removeTags', function() { it('removes match tags', function() { - expect(p.residential.removeTags({ highway: 'residential' }, 'area')).to.eql({}); + expect(p['highway/residential'].removeTags({ highway: 'residential' }, 'area')).to.eql({}); }); it('removes default tags', function() { - expect(p.cafe.removeTags({ amenity: 'cafe', building: 'yes'}, 'area')).to.eql({}); - expect(p.cafe.removeTags({ amenity: 'cafe', building: 'yep'}, 'area')).to.eql({ building: 'yep'}); + expect(p['amenity/cafe'].removeTags({ amenity: 'cafe', building: 'yes'}, 'area')).to.eql({}); + expect(p['amenity/cafe'].removeTags({ amenity: 'cafe', building: 'yep'}, 'area')).to.eql({ building: 'yep'}); }); });