From 16e5f5e2ceddda74452ae9d470d453aea5255c89 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 24 May 2013 15:42:55 -0700 Subject: [PATCH] Extract Entity#isUsed --- js/id/core/entity.js | 5 +++++ js/id/ui/inspector.js | 12 ++++-------- test/spec/core/entity.js | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/js/id/core/entity.js b/js/id/core/entity.js index e8181da16..c97545ee9 100644 --- a/js/id/core/entity.js +++ b/js/id/core/entity.js @@ -99,6 +99,11 @@ iD.Entity.prototype = { return this.extent(resolver).intersects(extent); }, + isUsed: function(resolver) { + return _.without(Object.keys(this.tags), 'area').length > 0 || + resolver.parentRelations(this).length > 0; + }, + // Returns the (possibly negative) area of the entity in square pixels at an // arbitrary unspecified zoom level -- so basically, only useful for relative // comparisons. diff --git a/js/id/ui/inspector.js b/js/id/ui/inspector.js index 89d21836c..ae762beab 100644 --- a/js/id/ui/inspector.js +++ b/js/id/ui/inspector.js @@ -53,16 +53,12 @@ iD.ui.Inspector = function(context) { presetLayer.call(presetList); }); - var unused = - _.without(Object.keys(entity.tags), 'area').length === 0 && - context.graph().parentRelations(entity).length === 0; - - if (unused) { - panewrap.style('right', '-100%'); - presetLayer.call(presetList); - } else { + if (entity.isUsed(context.graph())) { panewrap.style('right', '-0%'); tagLayer.call(entityEditor); + } else { + panewrap.style('right', '-100%'); + presetLayer.call(presetList); } } diff --git a/test/spec/core/entity.js b/test/spec/core/entity.js index ef2cee6e5..fc4822f00 100644 --- a/test/spec/core/entity.js +++ b/test/spec/core/entity.js @@ -144,6 +144,33 @@ describe('iD.Entity', function () { }); }); + describe("#isUsed", function () { + it("returns false for an entity without tags", function () { + var node = iD.Node(), + graph = iD.Graph([node]); + expect(node.isUsed(graph)).to.equal(false); + }); + + it("returns true for an entity with tags", function () { + var node = iD.Node({tags: {foo: 'bar'}}), + graph = iD.Graph([node]); + expect(node.isUsed(graph)).to.equal(true); + }); + + it("returns false for an entity with only an area=yes tag", function () { + var node = iD.Node({tags: {area: 'yes'}}), + graph = iD.Graph([node]); + expect(node.isUsed(graph)).to.equal(false); + }); + + it("returns true for an entity that is a relation member", function () { + var node = iD.Node(), + relation = iD.Relation({members: [{id: node.id}]}), + graph = iD.Graph([node, relation]); + expect(node.isUsed(graph)).to.equal(true); + }); + }); + describe("#hasDeprecatedTags", function () { it("returns false if entity has no tags", function () { expect(iD.Entity().deprecatedTags()).to.eql({});