Disable Move operation on incomplete relations (fixes #972)

This commit is contained in:
John Firebaugh
2013-03-11 16:43:06 -07:00
parent 113ae58de8
commit 68cc99c412
4 changed files with 45 additions and 3 deletions

View File

@@ -14,7 +14,7 @@ iD.actions.Move = function(ids, delta, projection) {
});
}
return function(graph) {
var action = function(graph) {
var nodes = [];
addNodes(ids, nodes, graph);
@@ -28,4 +28,13 @@ iD.actions.Move = function(ids, delta, projection) {
return graph;
};
action.enabled = function(graph) {
return _.every(ids, function(id) {
var entity = graph.entity(id);
return entity.type !== 'relation' || entity.isComplete(graph);
});
};
return action;
};

View File

@@ -140,6 +140,15 @@ _.extend(iD.Relation.prototype, {
return this.tags.type === 'multipolygon';
},
isComplete: function(resolver) {
for (var i = 0; i < this.members.length; i++) {
if (!resolver.entity(this.members[i].id)) {
return false;
}
}
return true;
},
isRestriction: function() {
return !!(this.tags.type && this.tags.type.match(/^restriction:?/));
},

View File

@@ -1,5 +1,4 @@
iD.operations.Move = function(selection, context) {
var operation = function() {
context.enter(iD.modes.Move(context, selection));
};
@@ -10,7 +9,8 @@ iD.operations.Move = function(selection, context) {
};
operation.enabled = function() {
return true;
return iD.actions.Move(selection)
.enabled(context.graph());
};
operation.id = "move";

View File

@@ -1,4 +1,28 @@
describe("iD.actions.Move", function() {
describe("#enabled", function() {
it("returns true by default", function() {
var node = iD.Node({loc: [0, 0]}),
action = iD.actions.Move([node.id], [0, 0], d3.geo.mercator()),
graph = iD.Graph([node]);
expect(action.enabled(graph)).to.be.true;
});
it("returns false for an incomplete relation", function() {
var relation = iD.Relation({members: [{id: 1}]}),
action = iD.actions.Move([relation.id], [0, 0], d3.geo.mercator()),
graph = iD.Graph([relation]);
expect(action.enabled(graph)).to.be.false;
});
it("returns true for a complete relation", function() {
var node = iD.Node({loc: [0, 0]}),
relation = iD.Relation({members: [{id: node.id}]}),
action = iD.actions.Move([relation.id], [0, 0], d3.geo.mercator()),
graph = iD.Graph([node, relation]);
expect(action.enabled(graph)).to.be.true;
});
});
it("moves all nodes in a way by the given amount", function() {
var node1 = iD.Node({loc: [0, 0]}),
node2 = iD.Node({loc: [5, 10]}),