mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 01:02:58 +00:00
Split remove action into DeleteWay and DeleteNode
This commit is contained in:
@@ -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>
|
||||
|
||||
16
js/id/actions/delete_node.js
Normal file
16
js/id/actions/delete_node.js
Normal 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');
|
||||
};
|
||||
};
|
||||
21
js/id/actions/delete_way.js
Normal file
21
js/id/actions/delete_way.js
Normal 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');
|
||||
};
|
||||
};
|
||||
@@ -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');
|
||||
};
|
||||
};
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
24
test/spec/actions/delete_node.js
Normal file
24
test/spec/actions/delete_node.js
Normal 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);
|
||||
});
|
||||
});
|
||||
36
test/spec/actions/delete_way.js
Normal file
36
test/spec/actions/delete_way.js
Normal 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");
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user