diff --git a/Makefile b/Makefile index 788eef43e..c9d13ff60 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,6 @@ all: \ js/id/modes.js \ js/id/modes/*.js \ js/id/controller/*.js \ - js/id/format/*.js \ js/id/graph/*.js \ js/id/renderer/*.js \ js/id/svg.js \ diff --git a/index.html b/index.html index 19e7446bb..af436a86e 100644 --- a/index.html +++ b/index.html @@ -108,10 +108,6 @@ - - - - diff --git a/js/id/connection.js b/js/id/connection.js index 326e9ebfa..42cf73c98 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -182,12 +182,65 @@ iD.Connection = function() { return oauth.authenticated(); } + // Generate Changeset XML. Returns a string. + connection.changesetXML = function(tags) { + return (new XMLSerializer()).serializeToString( + JXON.unbuild({ + osm: { + changeset: { + tag: _.map(tags, function(value, key) { + return { '@k': key, '@v': value }; + }), + '@version': 0.3, + '@generator': 'iD' + } + } + })); + }; + + // Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange) + // XML. Returns a string. + connection.osmChangeXML = function(userid, changeset_id, changes) { + function nest(x) { + var groups = {}; + for (var i = 0; i < x.length; i++) { + var tagName = Object.keys(x[i])[0]; + if (!groups[tagName]) groups[tagName] = []; + groups[tagName].push(x[i][tagName]); + } + var order = ['node', 'way', 'relation']; + var ordered = {}; + order.forEach(function(o) { + if (groups[o]) ordered[o] = groups[o]; + }); + return ordered; + } + + function rep(entity) { + return entity.asJXON(changeset_id); + } + + return (new XMLSerializer()).serializeToString(JXON.unbuild({ + osmChange: { + '@version': 0.3, + '@generator': 'iD', + 'create': nest(changes.created.map(rep)), + 'modify': changes.modified.map(rep), + 'delete': changes.deleted.map(function(x) { + x = rep(x); + x['@if-unused'] = true; + return x; + }) + } + })); + }; + connection.putChangeset = function(changes, comment, imagery_used, callback) { oauth.xhr({ method: 'PUT', path: '/api/0.6/changeset/create', options: { header: { 'Content-Type': 'text/xml' } }, - content: iD.format.XML.changeset({ + content: connection.changesetXML({ imagery_used: imagery_used.join(';'), comment: comment, created_by: 'iD ' + (version || '') @@ -198,7 +251,7 @@ iD.Connection = function() { method: 'POST', path: '/api/0.6/changeset/' + changeset_id + '/upload', options: { header: { 'Content-Type': 'text/xml' } }, - content: iD.format.XML.osmChange(user.id, changeset_id, changes) + content: connection.osmChangeXML(user.id, changeset_id, changes) }, function (err) { if (err) return callback(err); oauth.xhr({ diff --git a/js/id/format/format.js b/js/id/format/format.js deleted file mode 100644 index 8a159180a..000000000 --- a/js/id/format/format.js +++ /dev/null @@ -1,2 +0,0 @@ -iD.format = {}; - diff --git a/js/id/format/xml.js b/js/id/format/xml.js deleted file mode 100644 index e092a59af..000000000 --- a/js/id/format/xml.js +++ /dev/null @@ -1,55 +0,0 @@ -iD.format.XML = { - // Generate Changeset XML. Returns a string. - changeset: function(tags) { - return (new XMLSerializer()).serializeToString( - JXON.unbuild({ - osm: { - changeset: { - tag: _.map(tags, function(value, key) { - return { '@k': key, '@v': value }; - }), - '@version': 0.3, - '@generator': 'iD' - } - } - })); - }, - - // Generate [osmChange](http://wiki.openstreetmap.org/wiki/OsmChange) - // XML. Returns a string. - osmChange: function(userid, changeset_id, changes) { - function nest(x) { - var groups = {}; - for (var i = 0; i < x.length; i++) { - var tagName = Object.keys(x[i])[0]; - if (!groups[tagName]) groups[tagName] = []; - groups[tagName].push(x[i][tagName]); - } - var order = ['node', 'way', 'relation']; - var ordered = {}; - order.forEach(function(o) { - if (groups[o]) ordered[o] = groups[o]; - }); - return ordered; - } - - function rep(entity) { - return entity.asJXON(changeset_id); - } - - return (new XMLSerializer()).serializeToString(JXON.unbuild({ - osmChange: { - '@version': 0.3, - '@generator': 'iD', - // TODO: copy elements first - create: nest(changes.created.map(rep)), - modify: changes.modified.map(rep), - 'delete': changes.deleted.map(function(x) { - x = rep(x); - x['@if-unused'] = true; - return x; - }) - } - })); - } -}; diff --git a/test/index.html b/test/index.html index a14bade99..859d5b95d 100644 --- a/test/index.html +++ b/test/index.html @@ -102,9 +102,6 @@ - - - @@ -142,9 +139,6 @@ - - - diff --git a/test/index_packaged.html b/test/index_packaged.html index c86734083..c4eca2cca 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -47,8 +47,6 @@ - - diff --git a/test/spec/connection.js b/test/spec/connection.js index dbf7722bb..5565323d5 100644 --- a/test/spec/connection.js +++ b/test/spec/connection.js @@ -50,4 +50,13 @@ describe('iD.Connection', function() { }); }); + + describe('#osmChangeXML', function() { + it('converts change data to XML', function() { + var node = iD.Node({ id: 'n-1', type: 'node', loc: [-77, 38] }), + way = iD.Way({ id: 'w-1', type: 'way', nodes: [] }), + xml = c.osmChangeXML('jfire', '1234', {created: [node], modified: [way], deleted: []}); + expect(xml).to.eql(''); + }); + }); }); diff --git a/test/spec/format/xml.js b/test/spec/format/xml.js deleted file mode 100644 index 98cd33028..000000000 --- a/test/spec/format/xml.js +++ /dev/null @@ -1,11 +0,0 @@ -describe('iD.format.XML', function() { - var node = iD.Node({ id: 'n-1', type: 'node', loc: [-77, 38] }), - way = iD.Way({ id: 'w-1', type: 'way', nodes: [] }); - - describe('#osmChange', function() { - it('converts change data to XML', function() { - var jxon = iD.format.XML.osmChange('jfire', '1234', {created: [node], modified: [way], deleted: []}); - expect(jxon).to.eql(''); - }); - }); -});