diff --git a/index.html b/index.html index 6237d2962..a674a2e7c 100644 --- a/index.html +++ b/index.html @@ -45,9 +45,10 @@ + + - diff --git a/js/id/actions/delete_node.js b/js/id/actions/delete_node.js new file mode 100644 index 000000000..1d3737a86 --- /dev/null +++ b/js/id/actions/delete_node.js @@ -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'); + }; +}; diff --git a/js/id/actions/delete_way.js b/js/id/actions/delete_way.js new file mode 100644 index 000000000..157a190a7 --- /dev/null +++ b/js/id/actions/delete_way.js @@ -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'); + }; +}; diff --git a/js/id/actions/remove.js b/js/id/actions/remove.js deleted file mode 100644 index 9d65b7115..000000000 --- a/js/id/actions/remove.js +++ /dev/null @@ -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'); - }; -}; diff --git a/js/id/modes/select.js b/js/id/modes/select.js index de7e0de7b..82fbd7204 100644 --- a/js/id/modes/select.js +++ b/js/id/modes/select.js @@ -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(); } diff --git a/test/index.html b/test/index.html index 0c163b17c..8381f45fa 100644 --- a/test/index.html +++ b/test/index.html @@ -47,9 +47,10 @@ + + - @@ -82,8 +83,9 @@ + + - diff --git a/test/index_packaged.html b/test/index_packaged.html index 2649c9d31..f1e70b069 100644 --- a/test/index_packaged.html +++ b/test/index_packaged.html @@ -26,8 +26,9 @@ + + - diff --git a/test/spec/actions/delete_node.js b/test/spec/actions/delete_node.js new file mode 100644 index 000000000..82388b96c --- /dev/null +++ b/test/spec/actions/delete_node.js @@ -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); + }); +}); diff --git a/test/spec/actions/delete_way.js b/test/spec/actions/delete_way.js new file mode 100644 index 000000000..ed86e45a0 --- /dev/null +++ b/test/spec/actions/delete_way.js @@ -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"); +}); diff --git a/test/spec/actions/remove.js b/test/spec/actions/remove.js deleted file mode 100644 index b34048f9c..000000000 --- a/test/spec/actions/remove.js +++ /dev/null @@ -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); - }); -});