Read tags directly from value properties

Fixes #310
This commit is contained in:
John Firebaugh
2013-01-01 14:38:21 -08:00
parent 75b9961bb3
commit 1956c2f55d
2 changed files with 21 additions and 38 deletions
+9 -22
View File
@@ -42,14 +42,6 @@ iD.Inspector = function() {
function draw(tags) {
function setValue(d) {
d.value = this.value;
}
function setKey(d) {
d.key = this.value;
}
function emptyTag(d) {
return d.key === '';
}
@@ -86,14 +78,12 @@ iD.Inspector = function() {
inputs.append('input')
.property('type', 'text')
.attr('class', 'key')
.property('value', function(d) { return d.key; })
.on('keyup.update', setKey);
.property('value', function(d) { return d.key; });
inputs.append('input')
.property('type', 'text')
.attr('class', 'value')
.property('value', function(d) { return d.value; })
.on('keyup.update', setValue)
.on('keydown.push-more', pushMore)
.each(bindTypeahead);
@@ -208,18 +198,15 @@ iD.Inspector = function() {
});
}
function unentries(entries) {
return d3.nest()
.key(function(d) { return d.key; })
.rollup(function(v) { return v[0].value; })
.map(entries);
}
inspector.tags = function () {
var grabbed = [];
function grab(d) { if (d.key !== '') grabbed.push(d); }
inspectorwrap.selectAll('li').each(grab);
return unentries(grabbed);
var tags = {};
inspectorwrap.selectAll('li').each(function() {
var row = d3.select(this),
key = row.selectAll('.key').property('value'),
value = row.selectAll('.value').property('value');
if (key !== '') tags[key] = value;
});
return tags;
};
return d3.rebind(inspector, event, 'on');
+12 -16
View File
@@ -1,6 +1,6 @@
describe("iD.Inspector", function () {
var inspector, element,
tags = {highway: 'residential'},
tags = {highway: 'residential'},
entity = iD.Entity({type: 'node', id: "n12345", tags: tags});
beforeEach(function () {
@@ -17,9 +17,15 @@ describe("iD.Inspector", function () {
});
describe("#tags", function () {
it("returns the current tags", function () {
expect(inspector.tags()).to.eql(tags);
});
it("returns the current tags", function () {
expect(inspector.tags()).to.eql(tags);
});
it("returns updated tags when input values have changed", function () {
element.selectAll(".tag-row-empty input.key").property('value', 'k');
element.selectAll(".tag-row-empty input.value").property('value', 'v');
expect(inspector.tags()).to.eql({highway: 'residential', k: 'v'});
});
});
it("creates input elements for each key-value pair", function () {
@@ -28,8 +34,8 @@ describe("iD.Inspector", function () {
});
it("creates one trailing pair of empty input elements", function () {
expect(element.selectAll("input")[0][2].value).to.be.empty;
expect(element.selectAll("input")[0][3].value).to.be.empty;
expect(element.selectAll("input")[0][2].value).to.be.empty;
expect(element.selectAll("input")[0][3].value).to.be.empty;
});
it("sets the 'tag-row-empty' class on the placeholder row", function () {
@@ -41,16 +47,6 @@ describe("iD.Inspector", function () {
expect(inspector.tags()).to.eql({});
});
it("adds tags when typing in the placeholder row", function () {
var k = element.selectAll(".tag-row-empty input.key").node(),
v = element.selectAll(".tag-row-empty input.value").node();
k.value = 'k';
v.value = 'v';
happen.keyup(k);
happen.keyup(v);
expect(inspector.tags()).to.eql({highway: 'residential', k: 'v'});
});
it("emits a close event when the close button is clicked", function () {
var spy = sinon.spy();
inspector.on('close', spy);