1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Track dirty state in RED.nodes not RED.view

- add 'change' event on RED.nodes for tracking dirty state change
This commit is contained in:
Nick O'Leary 2015-03-15 21:54:36 +00:00
parent 46f2f752b0
commit fb738ad9fa
8 changed files with 81 additions and 55 deletions

View File

@ -191,7 +191,7 @@ RED.history = (function() {
}
}
}
RED.view.dirty(ev.dirty);
RED.nodes.dirty(ev.dirty);
RED.view.redraw(true);
RED.palette.refresh();
}

View File

@ -23,7 +23,7 @@ var RED = (function() {
var deploymentType = "full";
function save(force) {
if (RED.view.dirty()) {
if (RED.nodes.dirty()) {
//$("#debug-tab-clear").click(); // uncomment this to auto clear debug on deploy
if (!force) {
@ -56,7 +56,7 @@ var RED = (function() {
$("#btn-icn-deploy").removeClass('fa-download');
$("#btn-icn-deploy").addClass('spinner');
RED.view.dirty(false);
RED.nodes.dirty(false);
$.ajax({
url:"flows",
@ -86,7 +86,7 @@ var RED = (function() {
RED.history.markAllDirty();
RED.view.redraw();
}).fail(function(xhr,textStatus,err) {
RED.view.dirty(true);
RED.nodes.dirty(true);
if (xhr.responseText) {
RED.notify("<strong>Error</strong>: "+xhr.responseText,"error");
} else {
@ -168,7 +168,7 @@ var RED = (function() {
url: 'flows',
success: function(nodes) {
RED.nodes.import(nodes);
RED.view.dirty(false);
RED.nodes.dirty(false);
RED.view.redraw(true);
RED.comms.subscribe("status/#",function(topic,msg) {
var parts = topic.split("/");

View File

@ -23,6 +23,13 @@ RED.nodes = (function() {
var workspaces = {};
var subflows = {};
var dirty = false;
function setDirty(d) {
dirty = d;
eventHandler.emit("change",{dirty:dirty});
}
var registry = (function() {
var nodeList = [];
var nodeSets = {};
@ -772,7 +779,29 @@ RED.nodes = (function() {
return [new_nodes,new_links,new_workspaces,new_subflows];
}
// TODO: DRY
var eventHandler = (function() {
var handlers = {};
return {
on: function(evt,func) {
handlers[evt] = handlers[evt]||[];
handlers[evt].push(func);
},
emit: function(evt,arg) {
if (handlers[evt]) {
for (var i=0;i<handlers[evt].length;i++) {
handlers[evt][i](arg);
}
}
}
}
})();
return {
on: eventHandler.on,
registry:registry,
setNodeList: registry.setNodeList,
@ -832,6 +861,13 @@ RED.nodes = (function() {
createExportableNodeSet: createExportableNodeSet,
createCompleteNodeSet: createCompleteNodeSet,
id: getID,
dirty: function(d) {
if (d == null) {
return dirty;
} else {
setDirty(d);
}
},
nodes: nodes, // TODO: exposed for d3 vis
links: links // TODO: exposed for d3 vis
};

View File

@ -142,7 +142,7 @@ RED.editor = (function() {
if (editing_node) {
var changes = {};
var changed = false;
var wasDirty = RED.view.dirty();
var wasDirty = RED.nodes.dirty();
var d;
if (editing_node._def.oneditsave) {
@ -228,7 +228,7 @@ RED.editor = (function() {
if (changed) {
var wasChanged = editing_node.changed;
editing_node.changed = true;
RED.view.dirty(true);
RED.nodes.dirty(true);
RED.history.push({t:'edit',node:editing_node,changes:changes,links:removedLinks,dirty:wasDirty,changed:wasChanged});
}
editing_node.dirty = true;
@ -570,7 +570,7 @@ RED.editor = (function() {
validateNode(user);
}
updateConfigNodeSelect(configProperty,configType,"");
RED.view.dirty(true);
RED.nodes.dirty(true);
$( this ).dialog( "close" );
RED.view.redraw();
}
@ -662,7 +662,7 @@ RED.editor = (function() {
}
validateNode(configNode);
RED.view.dirty(true);
RED.nodes.dirty(true);
$(this).dialog("close");
}
@ -729,7 +729,7 @@ RED.editor = (function() {
var i;
var changes = {};
var changed = false;
var wasDirty = RED.view.dirty();
var wasDirty = RED.nodes.dirty();
var newName = $("#subflow-input-name").val();
@ -751,7 +751,7 @@ RED.editor = (function() {
});
var wasChanged = editing_node.changed;
editing_node.changed = true;
RED.view.dirty(true);
RED.nodes.dirty(true);
var historyEvent = {
t:'edit',
node:editing_node,

View File

@ -53,7 +53,7 @@ RED.subflow = (function() {
var oldInCount = subflow.in.length;
subflow.in.push(newInput);
subflow.dirty = true;
var wasDirty = RED.view.dirty();
var wasDirty = RED.nodes.dirty();
var wasChanged = subflow.changed;
subflow.changed = true;
@ -94,7 +94,7 @@ RED.subflow = (function() {
var oldOutCount = subflow.out.length;
subflow.out.push(newOutput);
subflow.dirty = true;
var wasDirty = RED.view.dirty();
var wasDirty = RED.nodes.dirty();
var wasChanged = subflow.changed;
subflow.changed = true;
@ -142,7 +142,7 @@ RED.subflow = (function() {
event.preventDefault();
var removedNodes = [];
var removedLinks = [];
var startDirty = RED.view.dirty();
var startDirty = RED.nodes.dirty();
RED.nodes.eachNode(function(n) {
if (n.type == "subflow:"+getSubflow().id) {
@ -171,7 +171,7 @@ RED.subflow = (function() {
});
RED.workspaces.remove(activeSubflow);
RED.view.dirty(true);
RED.nodes.dirty(true);
RED.view.redraw();
});
@ -208,7 +208,7 @@ RED.subflow = (function() {
RED.history.push({
t:'createSubflow',
subflow: subflow,
dirty:RED.view.dirty()
dirty:RED.nodes.dirty()
});
RED.workspaces.show(subflowId);
}
@ -384,10 +384,10 @@ RED.subflow = (function() {
activeWorkspace: RED.workspaces.active(),
removedLinks: removedLinks,
dirty:RED.view.dirty()
dirty:RED.nodes.dirty()
});
RED.view.dirty(true);
RED.nodes.dirty(true);
RED.view.redraw(true);
}

View File

@ -46,7 +46,6 @@ RED.view = (function() {
mouse_position = null,
mouse_mode = 0,
moving_set = [],
dirty = false,
lasso = null,
showStatus = false,
lastClickNode = null,
@ -284,6 +283,14 @@ RED.view = (function() {
redraw();
});
RED.nodes.on('change',function(state) {
if (state.dirty) {
$("#btn-deploy").removeClass("disabled");
} else {
$("#btn-deploy").addClass("disabled");
}
});
$('#btn-zoom-out').click(function() {zoomOut();});
$('#btn-zoom-zero').click(function() {zoomZero();});
$('#btn-zoom-in').click(function() {zoomIn();});
@ -351,10 +358,10 @@ RED.view = (function() {
}
nn.h = Math.max(node_height,(nn.outputs||0) * 15);
RED.history.push({t:'add',nodes:[nn.id],dirty:dirty});
RED.history.push({t:'add',nodes:[nn.id],dirty:RED.nodes.dirty()});
RED.nodes.add(nn);
RED.editor.validateNode(nn);
setDirty(true);
RED.nodes.dirty(true);
// auto select dropped node - so info shows (if visible)
clearSelection();
nn.selected = true;
@ -591,7 +598,7 @@ RED.view = (function() {
for (var j=0;j<moving_set.length;j++) {
ns.push({n:moving_set[j].n,ox:moving_set[j].ox,oy:moving_set[j].oy});
}
RED.history.push({t:'move',nodes:ns,dirty:dirty});
RED.history.push({t:'move',nodes:ns,dirty:RED.nodes.dirty()});
}
}
if (mouse_mode == RED.state.MOVING || mouse_mode == RED.state.MOVING_ACTIVE) {
@ -603,7 +610,7 @@ RED.view = (function() {
if (mouse_mode == RED.state.IMPORT_DRAGGING) {
RED.keyboard.remove(/* ESCAPE */ 27);
updateActiveNodes();
setDirty(true);
RED.nodes.dirty(true);
}
resetMouseVars();
redraw();
@ -711,7 +718,7 @@ RED.view = (function() {
delete moving_set[i].ox;
delete moving_set[i].oy;
}
RED.history.push({t:'move',nodes:ns,dirty:dirty});
RED.history.push({t:'move',nodes:ns,dirty:RED.nodes.dirty()});
}
function moveSelection(dx,dy) {
var minX = 0;
@ -747,7 +754,7 @@ RED.view = (function() {
var removedSubflowOutputs = [];
var removedSubflowInputs = [];
var startDirty = dirty;
var startDirty = RED.nodes.dirty();
if (moving_set.length > 0) {
for (var i=0;i<moving_set.length;i++) {
var node = moving_set[i].n;
@ -830,14 +837,14 @@ RED.view = (function() {
}
moving_set = [];
if (removedNodes.length > 0) {
setDirty(true);
if (removedNodes.length > 0 || removedSubflowOutputs.length > 0 || removedSubflowInputs.length > 0) {
RED.nodes.dirty(true);
}
}
if (selected_link) {
RED.nodes.removeLink(selected_link);
removedLinks.push(selected_link);
setDirty(true);
RED.nodes.dirty(true);
}
RED.history.push({t:'delete',nodes:removedNodes,links:removedLinks,subflowOutputs:removedSubflowOutputs,subflowInputs:removedSubflowInputs,dirty:startDirty});
@ -936,9 +943,9 @@ RED.view = (function() {
if (!existingLink) {
var link = {source: src, sourcePort:src_port, target: dst};
RED.nodes.addLink(link);
RED.history.push({t:'add',links:[link],dirty:dirty});
RED.history.push({t:'add',links:[link],dirty:RED.nodes.dirty()});
updateActiveNodes();
setDirty(true);
RED.nodes.dirty(true);
} else {
}
selected_link = null;
@ -970,7 +977,7 @@ RED.view = (function() {
if (mouse_mode == RED.state.IMPORT_DRAGGING) {
RED.keyboard.remove(/* ESCAPE */ 27);
updateSelection();
setDirty(true);
RED.nodes.dirty(true);
redraw();
resetMouseVars();
d3.event.stopPropagation();
@ -1646,16 +1653,6 @@ RED.view = (function() {
}
// TODO: 'dirty' should be a property of RED.nodes - with an event callback for ui hooks
function setDirty(d) {
dirty = d;
if (dirty) {
$("#btn-deploy").removeClass("disabled");
} else {
$("#btn-deploy").addClass("disabled");
}
}
function focusView() {
$("#chart svg").focus();
}
@ -1731,7 +1728,7 @@ RED.view = (function() {
links:new_links,
workspaces:new_workspaces,
subflows:new_subflows,
dirty:RED.view.dirty()
dirty:RED.nodes.dirty()
});
updateActiveNodes();
@ -1785,13 +1782,6 @@ RED.view = (function() {
RED.workspaces.refresh();
redraw();
},
dirty: function(d) {
if (d == null) {
return dirty;
} else {
setDirty(d);
}
},
focus: focusView,
importNodes: importNodes,
status: function(s) {

View File

@ -34,8 +34,8 @@ RED.workspaces = (function() {
RED.nodes.addWorkspace(ws);
workspace_tabs.addTab(ws);
workspace_tabs.activateTab(tabId);
RED.history.push({t:'add',workspaces:[ws],dirty:RED.view.dirty()});
RED.view.dirty(true);
RED.history.push({t:'add',workspaces:[ws],dirty:RED.nodes.dirty()});
RED.nodes.dirty(true);
}
}
function deleteWorkspace(ws,force) {
@ -53,10 +53,10 @@ RED.workspaces = (function() {
removeWorkspace(ws);
var historyEvent = RED.nodes.removeWorkspace(ws.id);
historyEvent.t = 'delete';
historyEvent.dirty = RED.view.dirty();
historyEvent.dirty = RED.nodes.dirty();
historyEvent.workspaces = [ws];
RED.history.push(historyEvent);
RED.view.dirty(true);
RED.nodes.dirty(true);
} else {
$( "#node-dialog-delete-workspace" ).dialog('option','workspace',ws);
$( "#node-dialog-delete-workspace-name" ).text(ws.label);
@ -143,7 +143,7 @@ RED.workspaces = (function() {
var label = $( "#node-input-workspace-name" ).val();
if (workspace.label != label) {
workspace_tabs.renameTab(workspace.id,label);
RED.view.dirty(true);
RED.nodes.dirty(true);
$("#btn-workspace-menu-"+workspace.id.replace(".","-")).text(label);
// TODO: update entry in menu
}