From 33beb3d2f0cf90215ef47c8c95f3512ca8d6d6f8 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 5 Dec 2012 14:39:41 -0500 Subject: [PATCH] Split actions into separate files --- Makefile | 1 + index.html | 12 ++- js/id/actions.js | 1 + js/id/actions/actions.js | 97 ------------------------- js/id/actions/add_node.js | 6 ++ js/id/actions/add_way_node.js | 8 ++ js/id/actions/change_tags.js | 7 ++ js/id/actions/change_way_direction.js | 8 ++ js/id/actions/move.js | 7 ++ js/id/actions/noop.js | 5 ++ js/id/actions/remove.js | 16 ++++ js/id/actions/remove_relation_entity.js | 6 ++ js/id/actions/remove_way_node.js | 6 ++ js/id/actions/start_way.js | 5 ++ test/index.html | 12 ++- 15 files changed, 98 insertions(+), 99 deletions(-) create mode 100644 js/id/actions.js delete mode 100644 js/id/actions/actions.js create mode 100644 js/id/actions/add_node.js create mode 100644 js/id/actions/add_way_node.js create mode 100644 js/id/actions/change_tags.js create mode 100644 js/id/actions/change_way_direction.js create mode 100644 js/id/actions/move.js create mode 100644 js/id/actions/noop.js create mode 100644 js/id/actions/remove.js create mode 100644 js/id/actions/remove_relation_entity.js create mode 100644 js/id/actions/remove_way_node.js create mode 100644 js/id/actions/start_way.js diff --git a/Makefile b/Makefile index b14e6f989..d2574ada6 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/index.html b/index.html index ab9e86956..6237d2962 100644 --- a/index.html +++ b/index.html @@ -40,7 +40,17 @@ - + + + + + + + + + + + diff --git a/js/id/actions.js b/js/id/actions.js new file mode 100644 index 000000000..481fa8285 --- /dev/null +++ b/js/id/actions.js @@ -0,0 +1 @@ +iD.actions = {}; diff --git a/js/id/actions/actions.js b/js/id/actions/actions.js deleted file mode 100644 index b27c8fbc2..000000000 --- a/js/id/actions/actions.js +++ /dev/null @@ -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); - }; -}; diff --git a/js/id/actions/add_node.js b/js/id/actions/add_node.js new file mode 100644 index 000000000..291811409 --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/add_way_node.js b/js/id/actions/add_way_node.js new file mode 100644 index 000000000..bc4b7f347 --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/change_tags.js b/js/id/actions/change_tags.js new file mode 100644 index 000000000..81b99760e --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/change_way_direction.js b/js/id/actions/change_way_direction.js new file mode 100644 index 000000000..cfa637336 --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/move.js b/js/id/actions/move.js new file mode 100644 index 000000000..d67af763f --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/noop.js b/js/id/actions/noop.js new file mode 100644 index 000000000..ddae5dde5 --- /dev/null +++ b/js/id/actions/noop.js @@ -0,0 +1,5 @@ +iD.actions.noop = function() { + return function(graph) { + return graph; + }; +}; diff --git a/js/id/actions/remove.js b/js/id/actions/remove.js new file mode 100644 index 000000000..9d65b7115 --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/remove_relation_entity.js b/js/id/actions/remove_relation_entity.js new file mode 100644 index 000000000..4a9fd1c70 --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/remove_way_node.js b/js/id/actions/remove_way_node.js new file mode 100644 index 000000000..16f9883bb --- /dev/null +++ b/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'); + }; +}; diff --git a/js/id/actions/start_way.js b/js/id/actions/start_way.js new file mode 100644 index 000000000..8e7ea7631 --- /dev/null +++ b/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'); + }; +}; diff --git a/test/index.html b/test/index.html index 9bbb4bd31..0c163b17c 100644 --- a/test/index.html +++ b/test/index.html @@ -42,7 +42,17 @@ - + + + + + + + + + + +