Split remove action into DeleteWay and DeleteNode

This commit is contained in:
John Firebaugh
2012-12-05 16:14:26 -05:00
parent d26c8638b3
commit 812b427ac4
10 changed files with 112 additions and 45 deletions

View File

@@ -45,9 +45,10 @@
<script src='js/id/actions/add_way_node.js'></script>
<script src='js/id/actions/change_tags.js'></script>
<script src='js/id/actions/change_way_direction.js'></script>
<script src="js/id/actions/delete_node.js"></script>
<script src="js/id/actions/delete_way.js"></script>
<script src='js/id/actions/move.js'></script>
<script src='js/id/actions/noop.js'></script>
<script src='js/id/actions/remove.js'></script>
<script src='js/id/actions/remove_relation_entity.js'></script>
<script src='js/id/actions/remove_way_node.js'></script>
<script src='js/id/actions/start_way.js'></script>

View File

@@ -0,0 +1,16 @@
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
iD.actions.DeleteNode = function(node) {
return function(graph) {
graph.parentWays(node.id)
.forEach(function(parent) {
graph = iD.actions.removeWayNode(parent, node)(graph);
});
graph.parentRelations(node.id)
.forEach(function(parent) {
graph = iD.actions.removeRelationEntity(parent, node)(graph);
});
return graph.remove(node, 'removed a node');
};
};

View File

@@ -0,0 +1,21 @@
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
iD.actions.DeleteWay = function(way) {
return function(graph) {
graph.parentRelations(way.id)
.forEach(function(parent) {
graph = iD.actions.removeRelationEntity(parent, way)(graph);
});
way.nodes.forEach(function (id) {
var node = graph.entity(id);
graph = iD.actions.removeWayNode(way, node)(graph);
if (!graph.parentWays(id).length && !graph.parentRelations(id).length) {
graph = graph.remove(node);
}
});
return graph.remove(way, 'removed a way');
};
};

View File

@@ -1,16 +0,0 @@
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
iD.actions.remove = function(entity) {
return function(graph) {
graph.parentWays(entity.id)
.forEach(function(parent) {
graph = iD.actions.removeWayNode(parent, entity)(graph);
});
graph.parentRelations(entity.id)
.forEach(function(parent) {
graph = iD.actions.removeRelationEntity(parent, entity)(graph);
});
return graph.remove(entity, 'removed a feature');
};
};

View File

@@ -33,7 +33,13 @@ iD.modes.Select = function (entity) {
});
function remove() {
mode.history.perform(iD.actions.remove(entity));
switch (entity.type) {
case 'way':
mode.history.perform(iD.actions.DeleteWay(entity));
case 'node':
mode.history.perform(iD.actions.DeleteNode(entity));
}
mode.controller.exit();
}

View File

@@ -47,9 +47,10 @@
<script src='../js/id/actions/add_way_node.js'></script>
<script src='../js/id/actions/change_tags.js'></script>
<script src='../js/id/actions/change_way_direction.js'></script>
<script src="../js/id/actions/delete_node.js"></script>
<script src="../js/id/actions/delete_way.js"></script>
<script src='../js/id/actions/move.js'></script>
<script src='../js/id/actions/noop.js'></script>
<script src='../js/id/actions/remove.js'></script>
<script src='../js/id/actions/remove_relation_entity.js'></script>
<script src='../js/id/actions/remove_way_node.js'></script>
<script src='../js/id/actions/start_way.js'></script>
@@ -82,8 +83,9 @@
<!-- include spec files here... -->
<script src="spec/actions/add_way_node.js"></script>
<script src="spec/actions/delete_node.js"></script>
<script src="spec/actions/delete_way.js"></script>
<script src="spec/actions/remove_way_node.js"></script>
<script src="spec/actions/remove.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
<script src="spec/graph/graph.js"></script>

View File

@@ -26,8 +26,9 @@
<!-- include spec files here... -->
<script src="spec/actions/add_way_node.js"></script>
<script src="spec/actions/delete_node.js"></script>
<script src="spec/actions/delete_way.js"></script>
<script src="spec/actions/remove_way_node.js"></script>
<script src="spec/actions/remove.js"></script>
<script src="spec/format/geojson.js"></script>
<script src="spec/format/xml.js"></script>
<script src="spec/graph/graph.js"></script>

View File

@@ -0,0 +1,24 @@
describe("iD.actions.DeleteNode", function () {
it("removes the node from the graph", function () {
var node = iD.Node(),
action = iD.actions.DeleteNode(node),
graph = action(iD.Graph([node]));
expect(graph.entity(node.id)).to.be.undefined;
});
it("removes the node from parent ways", function () {
var node = iD.Node(),
way = iD.Way({nodes: [node.id]}),
action = iD.actions.DeleteNode(node),
graph = action(iD.Graph([node, way]));
expect(graph.entity(way.id).nodes).not.to.contain(node.id);
});
it("removes the node from parent relations", function () {
var node = iD.Node(),
relation = iD.Relation({members: [node.id]}),
action = iD.actions.DeleteNode(node),
graph = action(iD.Graph([node, relation]));
expect(graph.entity(relation.id).members).not.to.contain(node.id);
});
});

View File

@@ -0,0 +1,36 @@
describe("iD.actions.DeleteWay", function () {
it("removes the way from the graph", function () {
var way = iD.Way(),
action = iD.actions.DeleteWay(way),
graph = action(iD.Graph([way]));
expect(graph.entity(way.id)).to.be.undefined;
});
it("removes a way from parent relations", function () {
var way = iD.Way(),
relation = iD.Relation({members: [way.id]}),
action = iD.actions.DeleteWay(way),
graph = action(iD.Graph([way, relation]));
expect(graph.entity(relation.id).members).not.to.contain(way.id);
});
it("deletes member nodes not referenced by another parent", function () {
var node = iD.Node(),
way = iD.Way({nodes: [node.id]}),
action = iD.actions.DeleteWay(way),
graph = action(iD.Graph([node, way]));
expect(graph.entity(node.id)).to.be.undefined;
});
it("does not delete member nodes referenced by another parent", function () {
var node = iD.Node(),
way1 = iD.Way({nodes: [node.id]}),
way2 = iD.Way({nodes: [node.id]}),
action = iD.actions.DeleteWay(way1),
graph = action(iD.Graph([node, way1, way2]));
expect(graph.entity(node.id)).not.to.be.undefined;
});
it("does not delete member nodes with interesting tags");
it("registers member nodes with interesting tags as POIs");
});

View File

@@ -1,24 +0,0 @@
describe("iD.actions.remove", function () {
it("removes the entity from the graph", function () {
var entity = iD.Way(),
action = iD.actions.remove(entity),
graph = action(iD.Graph().replace(entity));
expect(graph.entity(entity.id)).to.be.undefined;
});
it("removes a node from parent ways", function () {
var node = iD.Node(),
way = iD.Way().update({nodes: [node.id]}),
action = iD.actions.remove(node),
graph = action(iD.Graph().replace(node).replace(way));
expect(graph.entity(way.id).nodes).not.to.contain(node.id);
});
it("removes a way from parent relations", function () {
var way = iD.Way(),
relation = iD.Relation().update({members: [way.id]}),
action = iD.actions.remove(way),
graph = action(iD.Graph().replace(way).replace(relation));
expect(graph.entity(relation.id).members).not.to.contain(way.id);
});
});