mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-14 13:18:15 +02:00
Eliminate attempted entity modification in format.XML
This commit is contained in:
+16
-24
@@ -4,9 +4,9 @@ iD.format.XML = {
|
||||
return iD.format.XML.mappings[entity.type](entity);
|
||||
}
|
||||
},
|
||||
rep: function(entity) {
|
||||
rep: function(entity, changeset_id) {
|
||||
if (iD.format.XML.reps[entity.type]) {
|
||||
return iD.format.XML.reps[entity.type](entity);
|
||||
return iD.format.XML.reps[entity.type](entity, changeset_id);
|
||||
} else {
|
||||
if (typeof console !== 'undefined') console.log(entity.type);
|
||||
}
|
||||
@@ -47,32 +47,24 @@ iD.format.XML = {
|
||||
});
|
||||
return ordered;
|
||||
}
|
||||
var rep = {
|
||||
|
||||
function rep(entity) {
|
||||
return iD.format.XML.rep(entity, changeset_id);
|
||||
}
|
||||
|
||||
return (new XMLSerializer()).serializeToString(JXON.unbuild({
|
||||
osmChange: {
|
||||
'@version': 0.3,
|
||||
'@generator': 'iD',
|
||||
// TODO: copy elements first
|
||||
create: nest(changes.created.map(function(c) {
|
||||
var x = iD.Entity(c);
|
||||
x.changeset = changeset_id;
|
||||
return x;
|
||||
}).map(iD.format.XML.rep)),
|
||||
modify: changes.modified.map(function(c) {
|
||||
var x = iD.Entity(c);
|
||||
x.changeset = changeset_id;
|
||||
return x;
|
||||
}).map(iD.format.XML.rep),
|
||||
'delete': changes.deleted.map(function(c) {
|
||||
var x = iD.Entity(c);
|
||||
x.changeset = changeset_id;
|
||||
return x;
|
||||
}).map(iD.format.XML.rep)
|
||||
create: nest(changes.created.map(rep)),
|
||||
modify: changes.modified.map(rep),
|
||||
'delete': changes.deleted.map(rep)
|
||||
}
|
||||
};
|
||||
return (new XMLSerializer()).serializeToString(JXON.unbuild(rep));
|
||||
}));
|
||||
},
|
||||
reps: {
|
||||
node: function(entity) {
|
||||
node: function(entity, changeset_id) {
|
||||
var r = {
|
||||
node: {
|
||||
'@id': entity.id.replace('n', ''),
|
||||
@@ -84,10 +76,10 @@ iD.format.XML = {
|
||||
})
|
||||
}
|
||||
};
|
||||
if (entity.changeset) r.node['@changeset'] = entity.changeset;
|
||||
if (changeset_id) r.node['@changeset'] = changeset_id;
|
||||
return r;
|
||||
},
|
||||
way: function(entity) {
|
||||
way: function(entity, changeset_id) {
|
||||
var r = {
|
||||
way: {
|
||||
'@id': entity.id.replace('w', ''),
|
||||
@@ -100,7 +92,7 @@ iD.format.XML = {
|
||||
})
|
||||
}
|
||||
};
|
||||
if (entity.changeset) r.way['@changeset'] = entity.changeset;
|
||||
if (changeset_id) r.way['@changeset'] = changeset_id;
|
||||
return r;
|
||||
}
|
||||
},
|
||||
|
||||
+23
-4
@@ -1,4 +1,7 @@
|
||||
describe('XML', function() {
|
||||
var node = iD.Node({ id: 'n-1', type: 'node', loc: [-77, 38] }),
|
||||
way = iD.Way({ id: 'w-1', type: 'way', nodes: [] });
|
||||
|
||||
describe('#decode', function() {
|
||||
it('decodes xml', function() {
|
||||
expect(iD.format.XML.decode('<">')).to.eql('<">');
|
||||
@@ -7,12 +10,28 @@ describe('XML', function() {
|
||||
|
||||
describe('#rep', function() {
|
||||
it('converts a node to jxon', function() {
|
||||
expect(iD.format.XML.rep({ id: 'n-1', type: 'node', loc: [-77, 38] }))
|
||||
.to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, tag: [ ] } });
|
||||
expect(iD.format.XML.rep(node))
|
||||
.to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, tag: [ ] } });
|
||||
});
|
||||
|
||||
it('converts a way to jxon', function() {
|
||||
expect(iD.format.XML.rep({ id: 'w-1', type: 'way', nodes: [] }))
|
||||
.to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, tag: [ ] } });
|
||||
expect(iD.format.XML.rep(way))
|
||||
.to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, tag: [ ] } });
|
||||
});
|
||||
|
||||
it('includes changeset if provided', function() {
|
||||
expect(iD.format.XML.rep(node, '1234'))
|
||||
.to.eql({ node : { '@id': '-1', '@lat': 38, '@lon': -77, '@version': 0, '@changeset': '1234', tag: [ ] } });
|
||||
|
||||
expect(iD.format.XML.rep(way, '1234'))
|
||||
.to.eql({ way : { '@id' : '-1', nd : [ ], '@version': 0, '@changeset': '1234', tag: [ ] } });
|
||||
});
|
||||
});
|
||||
|
||||
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('<osmChange version="0.3" generator="iD"><create><node id="-1" lon="-77" lat="38" version="0" changeset="1234"/></create><modify><way id="-1" version="0" changeset="1234"/></modify></osmChange>');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user