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).
This commit is contained in:
John Firebaugh
2012-11-12 08:02:02 -10:00
parent 16618da564
commit 12e3c379fc
3 changed files with 15 additions and 23 deletions
-8
View File
@@ -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);
}
};
+6 -6
View File
@@ -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();
}
+9 -9
View File
@@ -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)