Merge branch 'master' of github.com:systemed/iD

This commit is contained in:
Tom MacWright
2012-10-26 16:33:28 -04:00
2 changed files with 60 additions and 45 deletions
+36 -37
View File
@@ -1,53 +1,52 @@
if (typeof iD === 'undefined') iD = {};
iD.Entity = function() {
iD.Entity = function () {
var entity = {};
// The ID in OSM terms
entity.parents = {};
entity.connection = null;
entity.connection = null;
entity._id = iD.Util.id();
entity.id = NaN;
entity.loaded = false;
entity.entityType = '';
entity.modified = false;
entity.deleted = false;
entity.id = NaN;
entity.loaded = false;
entity.entityType = '';
entity.modified = false;
entity.deleted = false;
// Parent-handling
entity.addParent = function(x) {
// summary: Record a parent (a relation or way which contains this entity).
entity.parents[x._id] = x;
};
entity.removeParent = function(x) {
// summary: Remove a parent (e.g. when node removed from a way).
// Parent-handling
entity.addParent = function (x) {
// summary: Record a parent (a relation or way which contains this entity).
entity.parents[x._id] = x;
};
entity.removeParent = function (x) {
// summary: Remove a parent (e.g. when node removed from a way).
delete entity.parents[x._id];
};
entity.hasParent = function(x) {
// summary: Does this entity have the specified parent (e.g. is it in a certain relation)?
return !!entity.parents[x._id];
};
entity.parentObjects = function() {
// summary: List of all parents of this entity.
return _.values(entity.parents);
};
entity.hasParentWays = function() {
// summary: Does this entity have any parents which are ways?
return !!_.find(entity.parentObjects(), function(p) {
};
entity.hasParent = function (x) {
// summary: Does this entity have the specified parent (e.g. is it in a certain relation)?
return !!entity.parents[x._id];
};
entity.parentObjects = function () {
// summary: List of all parents of this entity.
return _.values(entity.parents);
};
entity.hasParentWays = function () {
// summary: Does this entity have any parents which are ways?
return !!_.find(entity.parentObjects(), function (p) {
return p.entityType === 'way';
});
};
entity.parentWays = function() {
return entity._parentObjectsOfClass('way');
};
entity.parentRelations = function() {
return entity._parentObjectsOfClass('relation');
};
function _parentObjectsOfClass(_class) {
return _.filter(entity.parentObjects(), function(p) {
};
entity.parentWays = function () {
return _parentObjectsOfClass('way');
};
entity.parentRelations = function () {
return _parentObjectsOfClass('relation');
};
function _parentObjectsOfClass(_class) {
return _.filter(entity.parentObjects(), function (p) {
return p.entityType === _class;
});
}
}
return entity;
};
+24 -8
View File
@@ -1,11 +1,27 @@
describe('Entity', function() {
var entity;
describe('Entity', function () {
var entity;
beforeEach(function() {
entity = iD.Entity();
});
beforeEach(function () {
entity = iD.Entity();
});
it('has no entity type', function() {
expect(entity.entityType).toEqual('');
});
it('has no entity type', function () {
expect(entity.entityType).toEqual('');
});
describe('#parentWays', function () {
it('returns an array of parents with entityType way', function () {
entity.addParent({_id: 1, entityType: 'way'});
entity.addParent({_id: 2, entityType: 'node'});
expect(entity.parentWays()).toEqual([{_id: 1, entityType: 'way'}]);
});
});
describe('#parentRelations', function () {
it('returns an array of parents with entityType relation', function () {
entity.addParent({_id: 1, entityType: 'way'});
entity.addParent({_id: 2, entityType: 'relation'});
expect(entity.parentRelations()).toEqual([{_id: 2, entityType: 'relation'}]);
});
})
});