From 12e3c379fc3b1818ca415b173f24466266f65bec Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 12 Nov 2012 08:02:02 -1000 Subject: [PATCH] Remove graph dependency from Inspector It expects entities to have references to other entities rather than arrays of ids; we need a general strategy for this (#73). --- js/iD/graph/History.js | 8 -------- js/iD/renderer/Map.js | 12 ++++++------ js/iD/ui/Inspector.js | 18 +++++++++--------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/js/iD/graph/History.js b/js/iD/graph/History.js index a93aabe83..6cd188e0d 100644 --- a/js/iD/graph/History.js +++ b/js/iD/graph/History.js @@ -38,13 +38,5 @@ iD.History.prototype = { this.index++; if (this.stack[this.index].annotation) break; } - }, - - entity: function(id) { - return this.graph().entity(id); - }, - - fetch: function(id) { - return this.graph().fetch(id); } }; diff --git a/js/iD/renderer/Map.js b/js/iD/renderer/Map.js index 03b490760..24ce97a04 100644 --- a/js/iD/renderer/Map.js +++ b/js/iD/renderer/Map.js @@ -13,7 +13,7 @@ iD.Map = function(elem) { dispatch = d3.dispatch('move', 'update'), history = iD.History(), connection = iD.Connection(), - inspector = iD.Inspector(history), + inspector = iD.Inspector(), parent = d3.select(elem), selection = null, translateStart, @@ -381,13 +381,13 @@ iD.Map = function(elem) { } function selectClick() { - var d = d3.select(d3.event.target).data(); - if (d) d = d[0]; - if (!d || selection === d.id) return; - selection = d.id; + var entity = d3.select(d3.event.target).data(); + if (entity) entity = entity[0]; + if (!entity || selection === entity.id) return; + selection = entity.id; d3.select('.inspector-wrap') .style('display', 'block') - .datum(d).call(inspector); + .datum(history.graph().fetch(entity.id)).call(inspector); redraw(); } diff --git a/js/iD/ui/Inspector.js b/js/iD/ui/Inspector.js index 3f11865c5..249e5f16f 100644 --- a/js/iD/ui/Inspector.js +++ b/js/iD/ui/Inspector.js @@ -1,9 +1,9 @@ -iD.Inspector = function(graph) { +iD.Inspector = function() { var event = d3.dispatch('change', 'update', 'remove', 'close'); function inspector(selection) { // http://jsfiddle.net/7WQjr/ - selection.each(function(d, i) { + selection.each(function(entity) { // TODO: there must be a better way to do this. d3.select(this).node().innerHTML = ''; @@ -20,12 +20,12 @@ iD.Inspector = function(graph) { .attr('class', 'head'); head.append('h2') - .text(iD.Util.friendlyName(d)); + .text(iD.Util.friendlyName(entity)); head.append('a') .attr('class', 'permalink') .attr('href', 'http://www.openstreetmap.org/browse/' + - d.type + '/' + d.id.slice(1)) + entity.type + '/' + entity.id.slice(1)) .text('OSM'); head.append('a') @@ -34,7 +34,7 @@ iD.Inspector = function(graph) { .text('XML') .on('click', function() { d3.event.stopPropagation(); - iD.Util.codeWindow(iD.format.XML.mapping(graph.fetch(d.id))); + iD.Util.codeWindow(iD.format.XML.mapping(entity)); }); head.append('a') @@ -44,7 +44,7 @@ iD.Inspector = function(graph) { .on('click', function() { d3.event.stopPropagation(); iD.Util.codeWindow(JSON.stringify( - iD.format.GeoJSON.mapping(graph.fetch(d.id)), null, 2)); + iD.format.GeoJSON.mapping(entity), null, 2)); }); var table = d3.select(this) @@ -72,7 +72,7 @@ iD.Inspector = function(graph) { .property('value', function(d) { return d.key; }) .on('change', function(row) { row.key = this.value; - event.update(d, newtags(table)); + event.update(entity, newtags(table)); draw(formtags(table)); }); @@ -81,7 +81,7 @@ iD.Inspector = function(graph) { .property('value', function(d) { return d.value; }) .on('change', function(row) { row.value = this.value; - event.update(d, newtags(table)); + event.update(entity, newtags(table)); draw(formtags(table)); }); @@ -93,7 +93,7 @@ iD.Inspector = function(graph) { }); } - var data = d3.entries(d.tags).concat([{ key: '', value: ''}]); + var data = d3.entries(entity.tags).concat([{ key: '', value: ''}]); draw(data); d3.select(this)