- Automatically including any self loops when moving the corresponding component.
This commit is contained in:
Matt Gilman 2014-12-09 12:13:26 -05:00
parent 0125f3da3f
commit 1120b0f1ab
1 changed files with 33 additions and 16 deletions

View File

@ -25,7 +25,7 @@ nf.Draggable = (function () {
*/
var updateComponentsPosition = function (dragSelection) {
var revision = nf.Client.getRevision();
var updates = [];
var updates = d3.map();
// determine the drag delta
var dragData = dragSelection.datum();
@ -39,15 +39,14 @@ nf.Draggable = (function () {
return;
}
// go through each selected component
d3.selectAll('g.component.selected').each(function (d) {
var updateComponentPosition = function(d) {
var newPosition = {
x: d.component.position.x + delta.x,
y: d.component.position.y + delta.y
};
// update the component positioning
updates.push($.Deferred(function (deferred) {
return $.Deferred(function (deferred) {
$.ajax({
type: 'PUT',
url: d.component.uri,
@ -82,11 +81,10 @@ nf.Draggable = (function () {
deferred.reject();
});
}).promise());
});
}).promise();
};
// go through each selected connection
d3.selectAll('g.connection.selected').each(function (d) {
var updateConnectionPosition = function(d) {
// only update if necessary
if (d.component.bends.length === 0) {
return;
@ -109,7 +107,7 @@ nf.Draggable = (function () {
};
// update the component positioning
updates.push($.Deferred(function (deferred) {
return $.Deferred(function (deferred) {
$.ajax({
type: 'PUT',
url: d.component.uri,
@ -146,11 +144,30 @@ nf.Draggable = (function () {
deferred.reject();
});
}).promise());
}).promise();
};
// go through each selected connection
d3.selectAll('g.connection.selected').each(function (d) {
updates.set(d.component.id, updateConnectionPosition(d));
});
// go through each selected component
d3.selectAll('g.component.selected').each(function (d) {
// consider any self looping connections
var connections = nf.Connection.getComponentConnections(d.component.id);
$.each(connections, function(_, connection) {
if (!updates.has(connection.id) && nf.CanvasUtils.getConnectionSourceComponentId(connection) === nf.CanvasUtils.getConnectionDestinationComponentId(connection)) {
updates.set(connection.id, updateConnectionPosition(nf.Connection.get(connection.id)));
}
});
// consider the component itself
updates.set(d.component.id, updateComponentPosition(d));
});
// wait for all updates to complete
$.when.apply(window, updates).done(function () {
$.when.apply(window, updates.values()).done(function () {
var dragged = $.makeArray(arguments);
var connections = d3.set();