Split actions into separate files

This commit is contained in:
John Firebaugh
2012-12-05 14:39:41 -05:00
parent 4a3169bb1d
commit 33beb3d2f0
15 changed files with 98 additions and 99 deletions
+1
View File
@@ -26,6 +26,7 @@ all: \
js/id/oauth.js \
js/id/taginfo.js \
js/id/util.js \
js/id/actions.js \
js/id/actions/*.js \
js/id/modes.js \
js/id/modes/*.js \
+11 -1
View File
@@ -40,7 +40,17 @@
<script src='js/id/ui/loading.js'></script>
<script src='js/id/ui/userpanel.js'></script>
<script src='js/id/actions/actions.js'></script>
<script src='js/id/actions.js'></script>
<script src='js/id/actions/add_node.js'></script>
<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/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>
<script src='js/id/modes.js'></script>
<script src='js/id/modes/add_area.js'></script>
+1
View File
@@ -0,0 +1 @@
iD.actions = {};
-97
View File
@@ -1,97 +0,0 @@
iD.actions = {};
iD.actions.noop = function() {
return function(graph) {
return graph;
};
};
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/AddCommand.java
iD.actions.addNode = function(node) {
return function(graph) {
return graph.replace(node, 'added a place');
};
};
iD.actions.startWay = function(way) {
return function(graph) {
return graph.replace(way, 'started a road');
};
};
// 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');
};
};
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
iD.actions.addWayNode = function(way, node, index) {
return function(graph) {
var nodes = way.nodes.slice();
nodes.splice(index || nodes.length, 0, node.id);
return graph.replace(way.update({nodes: nodes})).replace(node, 'added to a road');
};
};
iD.actions.removeWayNode = function(way, node) {
return function(graph) {
var nodes = _.without(way.nodes, node.id);
return graph.replace(way.update({nodes: nodes}), 'removed from a road');
};
};
iD.actions.removeRelationEntity = function(relation, entity) {
return function(graph) {
var members = _.without(relation.members, entity.id);
return graph.replace(relation.update({members: members}), 'removed from a relation');
};
};
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
iD.actions.changeWayDirection = function(way) {
return function(graph) {
return graph.replace(way.update({
nodes: way.nodes.slice()
}), 'changed way direction');
};
};
iD.actions.changeTags = function(node, tags) {
return function(graph) {
return graph.replace(node.update({
tags: tags
}), 'changed tags');
};
};
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as
iD.actions.move = function(entity, loc) {
return function(graph) {
return graph.replace(entity.update({loc: loc}), 'moved an element');
};
};
iD.actions.addTemporary = function(node) {
return function(graph) {
return graph.replace(node);
};
};
iD.actions.removeTemporary = function(node) {
return function(graph) {
return graph.remove(node);
};
};
+6
View File
@@ -0,0 +1,6 @@
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/AddCommand.java
iD.actions.addNode = function(node) {
return function(graph) {
return graph.replace(node, 'added a place');
};
};
+8
View File
@@ -0,0 +1,8 @@
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
iD.actions.addWayNode = function(way, node, index) {
return function(graph) {
var nodes = way.nodes.slice();
nodes.splice(index || nodes.length, 0, node.id);
return graph.replace(way.update({nodes: nodes})).replace(node, 'added to a road');
};
};
+7
View File
@@ -0,0 +1,7 @@
iD.actions.changeTags = function(node, tags) {
return function(graph) {
return graph.replace(node.update({
tags: tags
}), 'changed tags');
};
};
+8
View File
@@ -0,0 +1,8 @@
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/AddNodeToWayAction.as
iD.actions.changeWayDirection = function(way) {
return function(graph) {
return graph.replace(way.update({
nodes: way.nodes.slice()
}), 'changed way direction');
};
};
+7
View File
@@ -0,0 +1,7 @@
// https://github.com/openstreetmap/josm/blob/mirror/src/org/openstreetmap/josm/command/MoveCommand.java
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/MoveNodeAction.as
iD.actions.move = function(entity, loc) {
return function(graph) {
return graph.replace(entity.update({loc: loc}), 'moved an element');
};
};
+5
View File
@@ -0,0 +1,5 @@
iD.actions.noop = function() {
return function(graph) {
return graph;
};
};
+16
View File
@@ -0,0 +1,16 @@
// 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');
};
};
+6
View File
@@ -0,0 +1,6 @@
iD.actions.removeRelationEntity = function(relation, entity) {
return function(graph) {
var members = _.without(relation.members, entity.id);
return graph.replace(relation.update({members: members}), 'removed from a relation');
};
};
+6
View File
@@ -0,0 +1,6 @@
iD.actions.removeWayNode = function(way, node) {
return function(graph) {
var nodes = _.without(way.nodes, node.id);
return graph.replace(way.update({nodes: nodes}), 'removed from a road');
};
};
+5
View File
@@ -0,0 +1,5 @@
iD.actions.startWay = function(way) {
return function(graph) {
return graph.replace(way, 'started a road');
};
};
+11 -1
View File
@@ -42,7 +42,17 @@
<script src='../js/id/ui/loading.js'></script>
<script src='../js/id/ui/userpanel.js'></script>
<script src='../js/id/actions/actions.js'></script>
<script src='../js/id/actions.js'></script>
<script src='../js/id/actions/add_node.js'></script>
<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/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>
<script src='../js/id/modes.js'></script>
<script src='../js/id/modes/add_area.js'></script>