Skip to content

Commit

Permalink
Split actions into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Dec 5, 2012
1 parent 4a3169b commit 33beb3d
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 99 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -26,6 +26,7 @@ all: \
js/id/oauth.js \ js/id/oauth.js \
js/id/taginfo.js \ js/id/taginfo.js \
js/id/util.js \ js/id/util.js \
js/id/actions.js \
js/id/actions/*.js \ js/id/actions/*.js \
js/id/modes.js \ js/id/modes.js \
js/id/modes/*.js \ js/id/modes/*.js \
Expand Down
12 changes: 11 additions & 1 deletion index.html
Expand Up @@ -40,7 +40,17 @@
<script src='js/id/ui/loading.js'></script> <script src='js/id/ui/loading.js'></script>
<script src='js/id/ui/userpanel.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.js'></script>
<script src='js/id/modes/add_area.js'></script> <script src='js/id/modes/add_area.js'></script>
Expand Down
1 change: 1 addition & 0 deletions js/id/actions.js
@@ -0,0 +1 @@
iD.actions = {};
97 changes: 0 additions & 97 deletions js/id/actions/actions.js

This file was deleted.

6 changes: 6 additions & 0 deletions js/id/actions/add_node.js
@@ -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 changes: 8 additions & 0 deletions js/id/actions/add_way_node.js
@@ -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 changes: 7 additions & 0 deletions js/id/actions/change_tags.js
@@ -0,0 +1,7 @@
iD.actions.changeTags = function(node, tags) {
return function(graph) {
return graph.replace(node.update({
tags: tags
}), 'changed tags');
};
};
8 changes: 8 additions & 0 deletions js/id/actions/change_way_direction.js
@@ -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 changes: 7 additions & 0 deletions js/id/actions/move.js
@@ -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 changes: 5 additions & 0 deletions js/id/actions/noop.js
@@ -0,0 +1,5 @@
iD.actions.noop = function() {
return function(graph) {
return graph;
};
};
16 changes: 16 additions & 0 deletions js/id/actions/remove.js
@@ -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 changes: 6 additions & 0 deletions js/id/actions/remove_relation_entity.js
@@ -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 changes: 6 additions & 0 deletions js/id/actions/remove_way_node.js
@@ -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 changes: 5 additions & 0 deletions js/id/actions/start_way.js
@@ -0,0 +1,5 @@
iD.actions.startWay = function(way) {
return function(graph) {
return graph.replace(way, 'started a road');
};
};
12 changes: 11 additions & 1 deletion test/index.html
Expand Up @@ -42,7 +42,17 @@
<script src='../js/id/ui/loading.js'></script> <script src='../js/id/ui/loading.js'></script>
<script src='../js/id/ui/userpanel.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.js'></script>
<script src='../js/id/modes/add_area.js'></script> <script src='../js/id/modes/add_area.js'></script>
Expand Down

0 comments on commit 33beb3d

Please sign in to comment.