소스 검색

Use localStorage to preserve work

dds
PaulStoffregen 10 년 전
부모
커밋
97fd83a90a
5개의 변경된 파일41개의 추가작업 그리고 101개의 파일을 삭제
  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 파일 보기

<script src="red/comms.js"></script> <script src="red/comms.js"></script>
<script src="red/ui/state.js"></script> <script src="red/ui/state.js"></script>
<script src="red/nodes.js"></script> <script src="red/nodes.js"></script>
<script src="red/storage.js"></script>
<script src="red/history.js"></script> <script src="red/history.js"></script>
<script src="red/validators.js"></script> <script src="red/validators.js"></script>
<script src="red/ui/keyboard.js"></script> <script src="red/ui/keyboard.js"></script>

+ 8
- 98
gui/red/main.js 파일 보기

}); });


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

if (RED.view.dirty()) { if (RED.view.dirty()) {


if (!force) { if (!force) {
//console.log(cpp); //console.log(cpp);


RED.view.state(RED.state.EXPORT); RED.view.state(RED.state.EXPORT);
//mouse_mode = RED.state.EXPORT;
$("#dialog-form").html($("script[data-template-name='export-clipboard-dialog']").html()); $("#dialog-form").html($("script[data-template-name='export-clipboard-dialog']").html());
$("#node-input-export").val(cpp); $("#node-input-export").val(cpp);
$("#node-input-export").focus(function() { $("#node-input-export").focus(function() {
}); });
$( "#dialog" ).dialog("option","title","Export nodes to clipboard").dialog( "open" ); $( "#dialog" ).dialog("option","title","Export nodes to clipboard").dialog( "open" );
$("#node-input-export").focus(); $("#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);
} }
} }


] ]
}); });


function loadSettings() {
/*
$.get('settings', function(data) {
RED.settings = data;
console.log("Node-RED: "+data.version);
loadNodes();
});
*/
loadNodes();
}
function loadNodes() { function loadNodes() {
console.log("loadNodes");
console.log("loadNodes");
$.get('list.html', function(data) { $.get('list.html', function(data) {
console.log("loadNodes complete"); console.log("loadNodes complete");
$("body").append(data); $("body").append(data);
$(".palette-spinner").hide(); $(".palette-spinner").hide();
$(".palette-scroll").show(); $(".palette-scroll").show();
$("#palette-search").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.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();}); $('#btn-node-status').click(function() {toggleStatus();});


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


return { return {

+ 5
- 3
gui/red/nodes.js 파일 보기

} }
} }
} }
/*
if (unknownTypes.length > 0) { if (unknownTypes.length > 0) {
var typeList = "<ul><li>"+unknownTypes.join("</li><li>")+"</li></ul>"; var typeList = "<ul><li>"+unknownTypes.join("</li><li>")+"</li></ul>";
var type = "type"+(unknownTypes.length > 1?"s":""); var type = "type"+(unknownTypes.length > 1?"s":"");
addWorkspace(defaultWorkspace); addWorkspace(defaultWorkspace);
RED.view.addWorkspace(defaultWorkspace); RED.view.addWorkspace(defaultWorkspace);
} }
*/
var node_map = {}; var node_map = {};
var new_nodes = []; var new_nodes = [];
var new_links = []; var new_links = [];
for (var w1=0;w1<n.wires.length;w1++) { for (var w1=0;w1<n.wires.length;w1++) {
var wires = (n.wires[w1] instanceof Array)?n.wires[w1]:[n.wires[w1]]; var wires = (n.wires[w1] instanceof Array)?n.wires[w1]:[n.wires[w1]];
for (var w2=0;w2<wires.length;w2++) { 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); addLink(link);
new_links.push(link); new_links.push(link);
} }

+ 25
- 0
gui/red/storage.js 파일 보기

/* 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 파일 보기

ns.push({n:moving_set[j].n,ox:moving_set[j].ox,oy:moving_set[j].oy}); 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:dirty});
RED.storage.update();
} }
} }
if (mouse_mode == RED.state.MOVING || mouse_mode == RED.state.MOVING_ACTIVE) { if (mouse_mode == RED.state.MOVING || mouse_mode == RED.state.MOVING_ACTIVE) {
dirty = d; dirty = d;
if (dirty) { if (dirty) {
$("#btn-deploy").removeClass("disabled").addClass("btn-danger"); $("#btn-deploy").removeClass("disabled").addClass("btn-danger");
RED.storage.update();
} else { } else {
$("#btn-deploy").addClass("disabled").removeClass("btn-danger"); $("#btn-deploy").addClass("disabled").removeClass("btn-danger");
} }

Loading…
취소
저장