mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
[groups] Support dragging node from palette into group
This commit is contained in:
parent
7886e5d57c
commit
27c462fee9
@ -284,6 +284,8 @@ RED.palette = (function() {
|
|||||||
var mouseX;
|
var mouseX;
|
||||||
var mouseY;
|
var mouseY;
|
||||||
var spliceTimer;
|
var spliceTimer;
|
||||||
|
var groupTimer;
|
||||||
|
var activeGroup;
|
||||||
var paletteWidth;
|
var paletteWidth;
|
||||||
var paletteTop;
|
var paletteTop;
|
||||||
$(d).draggable({
|
$(d).draggable({
|
||||||
@ -295,16 +297,37 @@ RED.palette = (function() {
|
|||||||
start: function() {
|
start: function() {
|
||||||
paletteWidth = $("#red-ui-palette").width();
|
paletteWidth = $("#red-ui-palette").width();
|
||||||
paletteTop = $("#red-ui-palette").parent().position().top + $("#red-ui-palette-container").position().top;
|
paletteTop = $("#red-ui-palette").parent().position().top + $("#red-ui-palette-container").position().top;
|
||||||
|
activeGroup = null;
|
||||||
RED.view.focus();
|
RED.view.focus();
|
||||||
},
|
},
|
||||||
stop: function() { d3.select('.red-ui-flow-link-splice').classed('red-ui-flow-link-splice',false); if (spliceTimer) { clearTimeout(spliceTimer); spliceTimer = null;}},
|
stop: function() {
|
||||||
|
d3.select('.red-ui-flow-link-splice').classed('red-ui-flow-link-splice',false);
|
||||||
|
if (spliceTimer) { clearTimeout(spliceTimer); spliceTimer = null; }
|
||||||
|
if (groupTimer) { clearTimeout(groupTimer); groupTimer = null; }
|
||||||
|
},
|
||||||
drag: function(e,ui) {
|
drag: function(e,ui) {
|
||||||
var paletteNode = getPaletteNode(nt);
|
var paletteNode = getPaletteNode(nt);
|
||||||
ui.originalPosition.left = paletteNode.offset().left;
|
ui.originalPosition.left = paletteNode.offset().left;
|
||||||
|
mouseX = ui.position.left - paletteWidth + (ui.helper.width()/2) + chart.scrollLeft();
|
||||||
|
mouseY = ui.position.top - paletteTop + (ui.helper.height()/2) + chart.scrollTop();
|
||||||
|
if (!groupTimer) {
|
||||||
|
groupTimer = setTimeout(function() {
|
||||||
|
var group = RED.view.getGroupAtPoint(mouseX,mouseY);
|
||||||
|
if (group !== activeGroup) {
|
||||||
|
// TODO: needs to be a CSS style on the group
|
||||||
|
d3.selectAll(".red-ui-flow-group-body").style("stroke-dasharray", function(d) { return (d === group)?"10 4":"none"})
|
||||||
|
activeGroup = group;
|
||||||
|
if (activeGroup) {
|
||||||
|
$(ui.helper).data('group',activeGroup);
|
||||||
|
} else {
|
||||||
|
$(ui.helper).removeData('group');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
groupTimer = null;
|
||||||
|
|
||||||
|
},200)
|
||||||
|
}
|
||||||
if (def.inputs > 0 && def.outputs > 0) {
|
if (def.inputs > 0 && def.outputs > 0) {
|
||||||
mouseX = ui.position.left - paletteWidth + (ui.helper.width()/2) + chart.scrollLeft();
|
|
||||||
mouseY = ui.position.top - paletteTop + (ui.helper.height()/2) + chart.scrollTop();
|
|
||||||
if (!spliceTimer) {
|
if (!spliceTimer) {
|
||||||
spliceTimer = setTimeout(function() {
|
spliceTimer = setTimeout(function() {
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
|
@ -389,14 +389,35 @@ RED.view = (function() {
|
|||||||
historyEvent.removedLinks = [spliceLink];
|
historyEvent.removedLinks = [spliceLink];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var group = $(ui.helper).data("group");
|
||||||
|
if (group) {
|
||||||
|
RED.group.addToGroup(group, nn);
|
||||||
|
historyEvent = {
|
||||||
|
t: 'multi',
|
||||||
|
events: [historyEvent],
|
||||||
|
|
||||||
|
}
|
||||||
|
historyEvent.events.push({
|
||||||
|
t: "addToGroup",
|
||||||
|
group: group,
|
||||||
|
nodes: nn
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
RED.history.push(historyEvent);
|
RED.history.push(historyEvent);
|
||||||
RED.nodes.add(nn);
|
RED.nodes.add(nn);
|
||||||
RED.editor.validateNode(nn);
|
RED.editor.validateNode(nn);
|
||||||
RED.nodes.dirty(true);
|
RED.nodes.dirty(true);
|
||||||
// auto select dropped node - so info shows (if visible)
|
// auto select dropped node - so info shows (if visible)
|
||||||
|
exitActiveGroup();
|
||||||
clearSelection();
|
clearSelection();
|
||||||
nn.selected = true;
|
nn.selected = true;
|
||||||
moving_set.push({n:nn});
|
moving_set.push({n:nn});
|
||||||
|
if (group) {
|
||||||
|
selectGroup(group,false);
|
||||||
|
group.active = true;
|
||||||
|
activeGroup = group;
|
||||||
|
}
|
||||||
updateActiveNodes();
|
updateActiveNodes();
|
||||||
updateSelection();
|
updateSelection();
|
||||||
redraw();
|
redraw();
|
||||||
|
Loading…
Reference in New Issue
Block a user