mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-20 10:03:29 +00:00
Rename permitted -> enabled and add to more actions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteNodeAction.as
|
||||
iD.actions.DeleteNode = function(nodeId) {
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var node = graph.entity(nodeId);
|
||||
|
||||
graph.parentWays(node)
|
||||
@@ -20,4 +20,10 @@ iD.actions.DeleteNode = function(nodeId) {
|
||||
|
||||
return graph.remove(node);
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// https://github.com/openstreetmap/potlatch2/blob/master/net/systemeD/halcyon/connection/actions/DeleteWayAction.as
|
||||
iD.actions.DeleteWay = function(wayId) {
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var way = graph.entity(wayId);
|
||||
|
||||
graph.parentRelations(way)
|
||||
@@ -29,4 +29,10 @@ iD.actions.DeleteWay = function(wayId) {
|
||||
|
||||
return graph.remove(way);
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ iD.actions.ReverseWay = function(wayId) {
|
||||
}
|
||||
}
|
||||
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var way = graph.entity(wayId),
|
||||
nodes = way.nodes.slice().reverse(),
|
||||
tags = {}, key, role;
|
||||
@@ -73,4 +73,10 @@ iD.actions.ReverseWay = function(wayId) {
|
||||
|
||||
return graph.replace(way.update({nodes: nodes, tags: tags}));
|
||||
};
|
||||
|
||||
action.enabled = function(graph) {
|
||||
return true;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ iD.actions.SplitWay = function(nodeId, newWayId) {
|
||||
}
|
||||
|
||||
var action = function(graph) {
|
||||
if (!action.permitted(graph))
|
||||
if (!action.enabled(graph))
|
||||
return graph;
|
||||
|
||||
var way = candidateWays(graph)[0],
|
||||
@@ -60,7 +60,7 @@ iD.actions.SplitWay = function(nodeId, newWayId) {
|
||||
return graph;
|
||||
};
|
||||
|
||||
action.permitted = function(graph) {
|
||||
action.enabled = function(graph) {
|
||||
return candidateWays(graph).length === 1;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//
|
||||
iD.actions.UnjoinNode = function(nodeId, newNodeId) {
|
||||
var action = function(graph) {
|
||||
if (!action.permitted(graph))
|
||||
if (!action.enabled(graph))
|
||||
return graph;
|
||||
|
||||
var node = graph.entity(nodeId);
|
||||
@@ -29,7 +29,7 @@ iD.actions.UnjoinNode = function(nodeId, newNodeId) {
|
||||
return graph;
|
||||
};
|
||||
|
||||
action.permitted = function(graph) {
|
||||
action.enabled = function(graph) {
|
||||
return graph.parentWays(graph.entity(nodeId)).length >= 2;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe("iD.actions.SplitWay", function () {
|
||||
describe("#permitted", function () {
|
||||
describe("#enabled", function () {
|
||||
it("returns true for a non-end node of a single way", function () {
|
||||
var graph = iD.Graph({
|
||||
'a': iD.Node({id: 'a'}),
|
||||
@@ -8,7 +8,7 @@ describe("iD.actions.SplitWay", function () {
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b', 'c']})
|
||||
});
|
||||
|
||||
expect(iD.actions.SplitWay('b').permitted(graph)).to.be.true;
|
||||
expect(iD.actions.SplitWay('b').enabled(graph)).to.be.true;
|
||||
});
|
||||
|
||||
it("returns false for the first node of a single way", function () {
|
||||
@@ -18,7 +18,7 @@ describe("iD.actions.SplitWay", function () {
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b']})
|
||||
});
|
||||
|
||||
expect(iD.actions.SplitWay('a').permitted(graph)).to.be.false;
|
||||
expect(iD.actions.SplitWay('a').enabled(graph)).to.be.false;
|
||||
});
|
||||
|
||||
it("returns false for the last node of a single way", function () {
|
||||
@@ -28,7 +28,7 @@ describe("iD.actions.SplitWay", function () {
|
||||
'-': iD.Way({id: '-', nodes: ['a', 'b']})
|
||||
});
|
||||
|
||||
expect(iD.actions.SplitWay('b').permitted(graph)).to.be.false;
|
||||
expect(iD.actions.SplitWay('b').enabled(graph)).to.be.false;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
describe("iD.actions.UnjoinNode", function () {
|
||||
describe("#permitted", function () {
|
||||
describe("#enabled", function () {
|
||||
it("returns false for a node shared by less than two ways", function () {
|
||||
var graph = iD.Graph({'a': iD.Node()});
|
||||
|
||||
expect(iD.actions.UnjoinNode('a').permitted(graph)).to.equal(false);
|
||||
expect(iD.actions.UnjoinNode('a').enabled(graph)).to.equal(false);
|
||||
});
|
||||
|
||||
it("returns true for a node shared by two or more ways", function () {
|
||||
@@ -19,7 +19,7 @@ describe("iD.actions.UnjoinNode", function () {
|
||||
'|': iD.Way({id: '|', nodes: ['d', 'b']})
|
||||
});
|
||||
|
||||
expect(iD.actions.UnjoinNode('b').permitted(graph)).to.equal(true);
|
||||
expect(iD.actions.UnjoinNode('b').enabled(graph)).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user