Browse Source

Use localStorage to preserve work

dds
PaulStoffregen 10 years ago
parent
commit
97fd83a90a
5 changed files with 41 additions and 101 deletions
  1. +1
    -0
      gui/index.html
  2. +8
    -98
      gui/red/main.js
  3. +5
    -3
      gui/red/nodes.js
  4. +25
    -0
      gui/red/storage.js
  5. +2
    -0
      gui/red/ui/view.js

+ 1
- 0
gui/index.html View File

@@ -272,6 +272,7 @@
<script src="red/comms.js"></script>
<script src="red/ui/state.js"></script>
<script src="red/nodes.js"></script>
<script src="red/storage.js"></script>
<script src="red/history.js"></script>
<script src="red/validators.js"></script>
<script src="red/ui/keyboard.js"></script>

+ 8
- 98
gui/red/main.js View File

@@ -46,6 +46,8 @@ var RED = (function() {
});

function save(force) {
RED.storage.update();

if (RED.view.dirty()) {

if (!force) {
@@ -138,7 +140,6 @@ var RED = (function() {
//console.log(cpp);

RED.view.state(RED.state.EXPORT);
//mouse_mode = RED.state.EXPORT;
$("#dialog-form").html($("script[data-template-name='export-clipboard-dialog']").html());
$("#node-input-export").val(cpp);
$("#node-input-export").focus(function() {
@@ -151,48 +152,7 @@ var RED = (function() {
});
$( "#dialog" ).dialog("option","title","Export nodes to clipboard").dialog( "open" );
$("#node-input-export").focus();

/*
$("#btn-icn-deploy").removeClass('icon-upload');
$("#btn-icn-deploy").addClass('spinner');
RED.view.dirty(false);
$.ajax({
url:"flows",
type: "POST",
data: JSON.stringify(nns),
contentType: "application/json; charset=utf-8"
}).done(function(data,textStatus,xhr) {
RED.notify("Successfully deployed","success");
RED.nodes.eachNode(function(node) {
if (node.changed) {
node.dirty = true;
node.changed = false;
}
if(node.credentials) {
delete node.credentials;
}
});
RED.nodes.eachConfig(function (confNode) {
if (confNode.credentials) {
delete confNode.credentials;
}
});
// Once deployed, cannot undo back to a clean state
RED.history.markAllDirty();
RED.view.redraw();
}).fail(function(xhr,textStatus,err) {
RED.view.dirty(true);
if (xhr.responseText) {
RED.notify("<strong>Error</strong>: "+xhr.responseText,"error");
} else {
RED.notify("<strong>Error</strong>: no response from server","error");
}
}).always(function() {
$("#btn-icn-deploy").removeClass('spinner');
$("#btn-icn-deploy").addClass('icon-upload');
});
*/
//RED.view.dirty(false);
}
}

@@ -222,67 +182,17 @@ var RED = (function() {
]
});

function loadSettings() {
/*
$.get('settings', function(data) {
RED.settings = data;
console.log("Node-RED: "+data.version);
loadNodes();
});
*/
loadNodes();
}
function loadNodes() {
console.log("loadNodes");
console.log("loadNodes");
$.get('list.html', function(data) {
console.log("loadNodes complete");
$("body").append(data);
$(".palette-spinner").hide();
$(".palette-scroll").show();
$("#palette-search").show();
//loadFlows();
}, "html");
}

function loadFlows() {
$.getJSON("flows",function(nodes) {
RED.nodes.import(nodes);
RED.view.dirty(false);
RED.storage.load();
RED.view.redraw();
RED.comms.subscribe("status/#",function(topic,msg) {
var parts = topic.split("/");
var node = RED.nodes.node(parts[1]);
if (node) {
node.status = msg;
if (statusEnabled) {
node.dirty = true;
RED.view.redraw();
}
}
});
RED.comms.subscribe("node/#",function(topic,msg) {
var i;
if (topic == "node/added") {
for (i=0;i<msg.length;i++) {
var m = msg[i];
var id = m.id;
$.get('nodes/'+id, function(data) {
$("body").append(data);
var typeList = "<ul><li>"+m.types.join("</li><li>")+"</li></ul>";
RED.notify("Node"+(m.types.length!=1 ? "s":"")+" added to palette:"+typeList,"success");
});
}
} else if (topic == "node/removed") {
if (msg.types) {
for (i=0;i<msg.types.length;i++) {
RED.palette.remove(msg.types[i]);
}
var typeList = "<ul><li>"+msg.types.join("</li><li>")+"</li></ul>";
RED.notify("Node"+(msg.types.length!=1 ? "s":"")+" removed from palette:"+typeList,"success");
}
}
});
});
}, "html");
}

$('#btn-node-status').click(function() {toggleStatus();});
@@ -314,8 +224,8 @@ var RED = (function() {

$(function() {
RED.keyboard.add(/* ? */ 191,{shift:true},function(){showHelp();d3.event.preventDefault();});
loadSettings();
RED.comms.connect();
loadNodes();
//RED.comms.connect();
});

return {

+ 5
- 3
gui/red/nodes.js View File

@@ -338,6 +338,7 @@ RED.nodes = (function() {
}
}
}
/*
if (unknownTypes.length > 0) {
var typeList = "<ul><li>"+unknownTypes.join("</li><li>")+"</li></ul>";
var type = "type"+(unknownTypes.length > 1?"s":"");
@@ -364,7 +365,7 @@ RED.nodes = (function() {
addWorkspace(defaultWorkspace);
RED.view.addWorkspace(defaultWorkspace);
}
*/
var node_map = {};
var new_nodes = [];
var new_links = [];
@@ -428,8 +429,9 @@ RED.nodes = (function() {
for (var w1=0;w1<n.wires.length;w1++) {
var wires = (n.wires[w1] instanceof Array)?n.wires[w1]:[n.wires[w1]];
for (var w2=0;w2<wires.length;w2++) {
if (wires[w2] in node_map) {
var link = {source:n,sourcePort:w1,target:node_map[wires[w2]]};
var parts = wires[w2].split(":");
if (parts.length == 2 && parts[0] in node_map) {
var link = {source:n,sourcePort:w1,target:node_map[parts[0]],targetPort:parts[1]};
addLink(link);
new_links.push(link);
}

+ 25
- 0
gui/red/storage.js View File

@@ -0,0 +1,25 @@
/* public domain
* vim: set ts=4:
*/

RED.storage = (function() {
function update() {
// TOOD: use setTimeout to limit the rate of changes?
if (localStorage) {
var nns = RED.nodes.createCompleteNodeSet();
localStorage.setItem("audio_library_guitool", JSON.stringify(nns));
//console.log("localStorage write");
}
}
function load() {
if (localStorage) {
var data = localStorage.getItem("audio_library_guitool");
//console.log("localStorage read: " + data);
if (data) RED.nodes.import(data, false);
}
}
return {
update: update,
load: load
}
})();

+ 2
- 0
gui/red/ui/view.js View File

@@ -523,6 +523,7 @@ RED.view = (function() {
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.storage.update();
}
}
if (mouse_mode == RED.state.MOVING || mouse_mode == RED.state.MOVING_ACTIVE) {
@@ -1427,6 +1428,7 @@ RED.view = (function() {
dirty = d;
if (dirty) {
$("#btn-deploy").removeClass("disabled").addClass("btn-danger");
RED.storage.update();
} else {
$("#btn-deploy").addClass("disabled").removeClass("btn-danger");
}

Loading…
Cancel
Save