mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Don't allow deleting incomplete relations
This will fail with an "entity not found" error.
This commit is contained in:
@@ -65,6 +65,7 @@ en:
|
||||
area: Deleted an area.
|
||||
relation: Deleted a relation.
|
||||
multiple: "Deleted {n} objects."
|
||||
incomplete_relation: This feature can't be deleted because it hasn't been fully downloaded.
|
||||
connect:
|
||||
annotation:
|
||||
point: Connected a way to a point.
|
||||
|
||||
6
dist/locales/en.json
vendored
6
dist/locales/en.json
vendored
@@ -84,7 +84,8 @@
|
||||
"area": "Deleted an area.",
|
||||
"relation": "Deleted a relation.",
|
||||
"multiple": "Deleted {n} objects."
|
||||
}
|
||||
},
|
||||
"incomplete_relation": "This feature can't be deleted because it hasn't been fully downloaded."
|
||||
},
|
||||
"connect": {
|
||||
"annotation": {
|
||||
@@ -156,7 +157,7 @@
|
||||
},
|
||||
"nothing_to_undo": "Nothing to undo.",
|
||||
"nothing_to_redo": "Nothing to redo.",
|
||||
"tooltip_keyhint": "Shortcut: ",
|
||||
"tooltip_keyhint": "Shortcut:",
|
||||
"just_edited": "You just edited OpenStreetMap!",
|
||||
"browser_notice": "This editor is supported in Firefox, Chrome, Safari, Opera, and Internet Explorer 9 and above. Please upgrade your browser or use Potlatch 2 to edit the map.",
|
||||
"view_on_osm": "View on OSM",
|
||||
@@ -166,7 +167,6 @@
|
||||
"localized_translation_language": "Choose language",
|
||||
"localized_translation_name": "Name"
|
||||
},
|
||||
"localized_translation_label": "Translation",
|
||||
"zoom_in_edit": "zoom in to edit the map",
|
||||
"logout": "logout",
|
||||
"loading_auth": "Connecting to OpenStreetMap...",
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
iD.actions.DeleteMultiple = function(ids) {
|
||||
return function(graph) {
|
||||
var actions = {
|
||||
way: iD.actions.DeleteWay,
|
||||
node: iD.actions.DeleteNode,
|
||||
relation: iD.actions.DeleteRelation
|
||||
};
|
||||
var actions = {
|
||||
way: iD.actions.DeleteWay,
|
||||
node: iD.actions.DeleteNode,
|
||||
relation: iD.actions.DeleteRelation
|
||||
};
|
||||
|
||||
var action = function(graph) {
|
||||
ids.forEach(function(id) {
|
||||
if (graph.hasEntity(id)) { // It may have been deleted aready.
|
||||
graph = actions[graph.entity(id).type](id)(graph);
|
||||
@@ -14,4 +14,14 @@ iD.actions.DeleteMultiple = function(ids) {
|
||||
|
||||
return graph;
|
||||
};
|
||||
|
||||
action.disabled = function(graph) {
|
||||
for (var i = 0; i < ids.length; i++) {
|
||||
var id = ids[i],
|
||||
disabled = actions[graph.entity(id).type](id).disabled(graph);
|
||||
if (disabled) return disabled;
|
||||
}
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -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.disabled = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ iD.actions.DeleteRelation = function(relationId) {
|
||||
!entity.hasInterestingTags();
|
||||
}
|
||||
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var relation = graph.entity(relationId);
|
||||
|
||||
graph.parentRelations(relation)
|
||||
@@ -25,4 +25,11 @@ iD.actions.DeleteRelation = function(relationId) {
|
||||
|
||||
return graph.remove(relation);
|
||||
};
|
||||
|
||||
action.disabled = function(graph) {
|
||||
if (!graph.entity(relationId).isComplete(graph))
|
||||
return 'incomplete_relation';
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ iD.actions.DeleteWay = function(wayId) {
|
||||
!node.hasInterestingTags();
|
||||
}
|
||||
|
||||
return function(graph) {
|
||||
var action = function(graph) {
|
||||
var way = graph.entity(wayId);
|
||||
|
||||
graph.parentRelations(way)
|
||||
@@ -25,4 +25,10 @@ iD.actions.DeleteWay = function(wayId) {
|
||||
|
||||
return graph.remove(way);
|
||||
};
|
||||
|
||||
action.disabled = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
return action;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
iD.operations.Delete = function(selection, context) {
|
||||
var action = iD.actions.DeleteMultiple(selection);
|
||||
|
||||
var operation = function() {
|
||||
var annotation;
|
||||
|
||||
@@ -9,7 +11,7 @@ iD.operations.Delete = function(selection, context) {
|
||||
}
|
||||
|
||||
context.perform(
|
||||
iD.actions.DeleteMultiple(selection),
|
||||
action,
|
||||
annotation);
|
||||
|
||||
context.enter(iD.modes.Browse(context));
|
||||
@@ -20,11 +22,14 @@ iD.operations.Delete = function(selection, context) {
|
||||
};
|
||||
|
||||
operation.disabled = function() {
|
||||
return false;
|
||||
return action.disabled(context.graph());
|
||||
};
|
||||
|
||||
operation.tooltip = function() {
|
||||
return t('operations.delete.description');
|
||||
var disable = operation.disabled();
|
||||
return disable ?
|
||||
t('operations.delete.' + disable) :
|
||||
t('operations.delete.description');
|
||||
};
|
||||
|
||||
operation.id = "delete";
|
||||
|
||||
@@ -18,4 +18,14 @@ describe("iD.actions.DeleteMultiple", function () {
|
||||
expect(graph.hasEntity(w.id)).to.be.undefined;
|
||||
expect(graph.hasEntity(n.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
describe("#disabled", function () {
|
||||
it("returns the result of the first action that is disabled", function () {
|
||||
var node = iD.Node(),
|
||||
relation = iD.Relation({members: [{id: 'w'}]}),
|
||||
graph = iD.Graph([node, relation]),
|
||||
action = iD.actions.DeleteMultiple([node.id, relation.id]);
|
||||
expect(action.disabled(graph)).to.equal('incomplete_relation');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -73,4 +73,13 @@ describe("iD.actions.DeleteRelation", function () {
|
||||
graph = action(iD.Graph([node, way, relation]));
|
||||
expect(graph.hasEntity(node.id)).to.be.undefined;
|
||||
});
|
||||
|
||||
describe("#disabled", function() {
|
||||
it("returns 'incomplete_relation' if the relation is incomplete", function() {
|
||||
var relation = iD.Relation({members: [{id: 'w'}]}),
|
||||
graph = iD.Graph([relation]),
|
||||
action = iD.actions.DeleteRelation(relation.id);
|
||||
expect(action.disabled(graph)).to.equal('incomplete_relation');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user