Autocomplete changeset comments from previous changeset comments

Fixes #2002
This commit is contained in:
John Firebaugh
2016-01-24 12:44:33 -08:00
parent 82d1a92b23
commit 0d2a742e18
3 changed files with 78 additions and 4 deletions

View File

@@ -322,6 +322,23 @@ iD.Connection = function(useHttps) {
oauth.xhr({ method: 'GET', path: '/api/0.6/user/details' }, done);
};
connection.userChangesets = function(callback) {
connection.userDetails(function(err, user) {
if (err) return callback(err);
function done(changesets) {
callback(undefined, Array.prototype.map.call(changesets.getElementsByTagName('changeset'),
function (changeset) {
return { tags: getTags(changeset) };
}));
}
d3.xml(url + '/api/0.6/changesets?user=' + user.id).get()
.on('load', done)
.on('error', callback);
});
};
connection.status = function(callback) {
function done(capabilities) {
var apiStatus = capabilities.getElementsByTagName('status');

View File

@@ -38,16 +38,35 @@ iD.ui.Commit = function(context) {
.attr('placeholder', t('commit.description_placeholder'))
.attr('maxlength', 255)
.property('value', context.storage('comment') || '')
.on('input.save', function() {
d3.selectAll('.save-section .save-button')
.attr('disabled', (this.value.length ? null : true));
})
.on('input.save', enableDisableSaveButton)
.on('change.save', enableDisableSaveButton)
.on('blur.save', function() {
context.storage('comment', this.value);
});
function enableDisableSaveButton() {
d3.selectAll('.save-section .save-button')
.attr('disabled', (this.value.length ? null : true));
}
commentField.node().select();
context.connection().userChangesets(function (err, changesets) {
if (err) return;
var comments = [];
for (var i = 0; i < changesets.length; i++) {
if (changesets[i].tags.comment) {
comments.push({
title: changesets[i].tags.comment,
value: changesets[i].tags.comment
});
}
}
commentField.call(d3.combobox().data(comments));
});
// Warnings
var warnings = body.selectAll('div.warning-section')

View File

@@ -248,6 +248,44 @@ describe('iD.Connection', function () {
});
});
describe('#userChangesets', function() {
var server,
changesetsXML = '<?xml version="1.0" encoding="UTF-8"?><osm>' +
'<changeset id="36777543" user="Steve" uid="1" created_at="2016-01-24T15:02:06Z" closed_at="2016-01-24T15:02:07Z" open="false" min_lat="39.3823819" min_lon="-104.8639728" max_lat="39.3834184" max_lon="-104.8618622" comments_count="0">' +
'<tag k="comment" v="Caprice Court has been extended"/>' +
'<tag k="created_by" v="iD 1.8.5"/>' +
'</changeset>' +
'</osm>';
beforeEach(function() {
server = sinon.fakeServer.create();
});
afterEach(function() {
server.restore();
});
it('loads user changesets', function(done) {
c.userDetails = function (callback) {
callback(undefined, { id: 1 });
};
c.userChangesets(function(err, changesets) {
expect(changesets).to.deep.equal([{
tags: {
comment: 'Caprice Court has been extended',
created_by: 'iD 1.8.5'
}
}]);
done();
});
server.respondWith("GET", "http://www.openstreetmap.org/api/0.6/changesets?user=1",
[200, { "Content-Type": "text/xml" }, changesetsXML]);
server.respond();
});
});
describe('#changesetTags', function() {
it('omits comment when empty', function() {
expect(c.changesetTags('', [])).not.to.have.property('comment');