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

Fix library/clipboard import/export issues

This commit is contained in:
Nick O'Leary 2019-05-21 22:58:56 +01:00
parent 5ab7380ad1
commit 42b60aef4e
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
7 changed files with 127 additions and 54 deletions

View File

@ -26,6 +26,7 @@ RED.clipboard = (function() {
var currentPopoverError; var currentPopoverError;
var activeTab; var activeTab;
var libraryBrowser; var libraryBrowser;
var examplesBrowser;
function setupDialogs() { function setupDialogs() {
dialog = $('<div id="red-ui-clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>') dialog = $('<div id="red-ui-clipboard-dialog" class="hide"><form class="dialog-form form-horizontal"></form></div>')
@ -139,10 +140,15 @@ RED.clipboard = (function() {
text: RED._("common.label.import"), text: RED._("common.label.import"),
click: function() { click: function() {
var addNewFlow = ($("#red-ui-clipboard-dialog-import-opt > a.selected").attr('id') === 'red-ui-clipboard-dialog-import-opt-new'); var addNewFlow = ($("#red-ui-clipboard-dialog-import-opt > a.selected").attr('id') === 'red-ui-clipboard-dialog-import-opt-new');
if (activeTab === "red-ui-clipboard-dialog-red-ui-clipboard-dialog-import-opt-clipboard") { if (activeTab === "red-ui-clipboard-dialog-import-tab-clipboard") {
RED.view.importNodes($("#red-ui-clipboard-dialog-import-text").val(),addNewFlow); RED.view.importNodes($("#red-ui-clipboard-dialog-import-text").val(),addNewFlow);
} else { } else {
var selectedPath = libraryBrowser.getSelected(); var selectedPath;
if (activeTab === "red-ui-clipboard-dialog-import-tab-library") {
selectedPath = libraryBrowser.getSelected();
} else {
selectedPath = examplesBrowser.getSelected();
}
if (selectedPath.path) { if (selectedPath.path) {
$.get('library/'+selectedPath.library+'/'+selectedPath.type+'/'+selectedPath.path, function(data) { $.get('library/'+selectedPath.library+'/'+selectedPath.type+'/'+selectedPath.path, function(data) {
RED.view.importNodes(data,addNewFlow); RED.view.importNodes(data,addNewFlow);
@ -214,9 +220,8 @@ RED.clipboard = (function() {
'<textarea id="red-ui-clipboard-dialog-import-text"></textarea>'+ '<textarea id="red-ui-clipboard-dialog-import-text"></textarea>'+
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'<div id="red-ui-clipboard-dialog-import-tab-library" class="red-ui-clipboard-dialog-tab-library">'+ '<div id="red-ui-clipboard-dialog-import-tab-library" class="red-ui-clipboard-dialog-tab-library"></div>'+
'<div id="red-ui-clipboard-dialog-import-tab-library-browser"></div>'+ '<div id="red-ui-clipboard-dialog-import-tab-examples" class="red-ui-clipboard-dialog-tab-library"></div>'+
'</div>'+
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'<div class="form-row">'+ '<div class="form-row">'+
@ -386,6 +391,10 @@ RED.clipboard = (function() {
id: "red-ui-clipboard-dialog-import-tab-library", id: "red-ui-clipboard-dialog-import-tab-library",
label: RED._("library.library") label: RED._("library.library")
}); });
tabs.addTab({
id: "red-ui-clipboard-dialog-import-tab-examples",
label: RED._("library.types.examples")
});
tabs.activateTab("red-ui-clipboard-dialog-import-tab-"+mode); tabs.activateTab("red-ui-clipboard-dialog-import-tab-"+mode);
if (mode === 'clipboard') { if (mode === 'clipboard') {
@ -400,16 +409,39 @@ RED.clipboard = (function() {
$("#red-ui-clipboard-dialog-export").button("enable"); $("#red-ui-clipboard-dialog-export").button("enable");
libraryBrowser = RED.library.createBrowser({ libraryBrowser = RED.library.createBrowser({
container: $("#red-ui-clipboard-dialog-import-tab-library-browser"), container: $("#red-ui-clipboard-dialog-import-tab-library"),
onselect: function(file) { onselect: function(file) {
if (file && file.label && !file.children) { if (file && file.label && !file.children) {
$("#red-ui-clipboard-dialog-ok").button("enable"); $("#red-ui-clipboard-dialog-ok").button("enable");
} else { } else {
$("#red-ui-clipboard-dialog-ok").button("disable"); $("#red-ui-clipboard-dialog-ok").button("disable");
} }
},
onconfirm: function(item) {
if (item && item.label && !item.children) {
$("#red-ui-clipboard-dialog-ok").trigger("click");
}
} }
}) })
loadFlowLibrary(libraryBrowser,true); loadFlowLibrary(libraryBrowser,"local",RED._("library.types.local"));
examplesBrowser = RED.library.createBrowser({
container: $("#red-ui-clipboard-dialog-import-tab-examples"),
onselect: function(file) {
if (file && file.label && !file.children) {
$("#red-ui-clipboard-dialog-ok").button("enable");
} else {
$("#red-ui-clipboard-dialog-ok").button("disable");
}
},
onconfirm: function(item) {
if (item && item.label && !item.children) {
$("#red-ui-clipboard-dialog-ok").trigger("click");
}
}
})
loadFlowLibrary(examplesBrowser,"_examples_",RED._("library.types.examples"));
dialogContainer.i18n(); dialogContainer.i18n();
@ -504,7 +536,7 @@ RED.clipboard = (function() {
} }
} }
}) })
loadFlowLibrary(libraryBrowser,false); loadFlowLibrary(libraryBrowser,"local",RED._("library.types.local"));
$("#red-ui-clipboard-dialog-tab-library-name").val("flows.json").select(); $("#red-ui-clipboard-dialog-tab-library-name").val("flows.json").select();
@ -615,38 +647,36 @@ RED.clipboard = (function() {
} }
function loadFlowLibrary(browser,includeExamples) { function loadFlowLibrary(browser,library,label) {
var listing = []; // if (includeExamples) {
if (includeExamples) { // listing.push({
listing.push({ // library: "_examples_",
library: "_examples_", // type: "flows",
// icon: 'fa fa-hdd-o',
// label: RED._("library.types.examples"),
// path: "",
// children: function(item,done) {
// RED.library.loadLibraryFolder("_examples_","flows","",function(children) {
// item.children = children;
// done(children);
// })
// }
// })
// }
browser.data([{
library: library,
type: "flows", type: "flows",
icon: 'fa fa-hdd-o', icon: 'fa fa-hdd-o',
label: RED._("library.types.examples"), label: label,
path: "",
children: function(item,done) {
RED.library.loadLibraryFolder("_examples_","flows","",function(children) {
item.children = children;
done(children);
})
}
})
}
listing.push({
library: "local",
type: "flows",
icon: 'fa fa-hdd-o',
label: RED._("library.types.local"),
path: "", path: "",
expanded: true, expanded: true,
children: function(item,done) { children: function(item,done) {
RED.library.loadLibraryFolder("local","flows","",function(children) { RED.library.loadLibraryFolder(library,"flows","",function(children) {
item.children = children; item.children = children;
done(children); done(children);
}) })
} }
}) }]);
browser.data(listing);
} }
function hideDropTarget() { function hideDropTarget() {

View File

@ -24,7 +24,7 @@
* *
* events: * events:
* - treelistselect : function(event, item) {} * - treelistselect : function(event, item) {}
* * - treelistconfirm : function(event,item) {}
* *
* data: * data:
* [ * [
@ -61,6 +61,18 @@
} }
var target; var target;
switch(evt.keyCode) { switch(evt.keyCode) {
case 13: // ENTER
if (selected.children) {
if (selected.treeList.container.hasClass("expanded")) {
selected.treeList.collapse()
} else {
selected.treeList.expand()
}
} else {
that._trigger("confirm",null,selected)
}
break;
case 37: // LEFT case 37: // LEFT
if (selected.children&& selected.treeList.container.hasClass("expanded")) { if (selected.children&& selected.treeList.container.hasClass("expanded")) {
selected.treeList.collapse() selected.treeList.collapse()
@ -290,6 +302,11 @@
label.addClass("selected"); label.addClass("selected");
that._trigger("select",e,item) that._trigger("select",e,item)
}) })
label.on("dblclick", function(e) {
if (!item.children) {
that._trigger("confirm",e,item);
}
})
} }
if (item.icon) { if (item.icon) {
$('<span class="red-ui-treeList-icon"><i class="'+item.icon+'" /></span>').appendTo(label); $('<span class="red-ui-treeList-icon"><i class="'+item.icon+'" /></span>').appendTo(label);

View File

@ -225,14 +225,19 @@ RED.library = (function() {
expanded: true, expanded: true,
writable: false, writable: false,
children: [{ children: [{
library: "local",
type: options.url,
icon: 'fa fa-cube', icon: 'fa fa-cube',
label: options.type, label: options.type,
path: options.type+"/", path: "",
expanded: true, expanded: true,
children: items children: items
}] }]
}] }]
loadLibraryBrowser.data(listing); loadLibraryBrowser.data(listing);
setTimeout(function() {
loadLibraryBrowser.select(listing[0].children[0]);
},200);
}); });
libraryEditor = ace.edit('red-ui-library-dialog-load-preview-text',{ libraryEditor = ace.edit('red-ui-library-dialog-load-preview-text',{
useWorker: false useWorker: false
@ -262,24 +267,31 @@ RED.library = (function() {
if (filename === "") { if (filename === "") {
filename = "unnamed-"+options.type; filename = "unnamed-"+options.type;
} }
$("#red-ui-library-dialog-save-filename").attr("value",filename+".js"); $("#red-ui-library-dialog-save-filename").attr("value",filename+"."+(options.ext||"txt"));
loadLibraryFolder("local",options.url, "", function(items) { loadLibraryFolder("local",options.url, "", function(items) {
var listing = [{ var listing = [{
icon: 'fa fa-archive', library: "local",
type: options.url,
icon: 'fa fa-hdd-o',
label: RED._("library.types.local"), label: RED._("library.types.local"),
path: "", path: "",
expanded: true, expanded: true,
writable: false, writable: false,
children: [{ children: [{
library: "local",
type: options.url,
icon: 'fa fa-cube', icon: 'fa fa-cube',
label: options.type, label: options.type,
path: options.type+"/", path: "",
expanded: true, expanded: true,
children: items children: items
}] }]
}] }]
saveLibraryBrowser.data(listing); saveLibraryBrowser.data(listing);
setTimeout(function() {
saveLibraryBrowser.select(listing[0].children[0]);
},200);
}); });
$( "#red-ui-library-dialog-save" ).dialog( "open" ); $( "#red-ui-library-dialog-save" ).dialog( "open" );
} }
@ -299,6 +311,10 @@ RED.library = (function() {
if (options.onselect) { if (options.onselect) {
options.onselect(item); options.onselect(item);
} }
}).on('treelistconfirm', function(event, item) {
if (options.onconfirm) {
options.onconfirm(item);
}
}); });
var itemTools = $("<div>").css({position: "absolute",bottom:"6px",right:"8px"}); var itemTools = $("<div>").css({position: "absolute",bottom:"6px",right:"8px"});
var menuButton = $('<button class="red-ui-button red-ui-button-small" type="button"><i class="fa fa-ellipsis-h"></i></button>') var menuButton = $('<button class="red-ui-button red-ui-button-small" type="button"><i class="fa fa-ellipsis-h"></i></button>')
@ -406,6 +422,9 @@ RED.library = (function() {
} }
return { return {
select: function(item) {
dirList.treeList('select',item);
},
getSelected: function() { getSelected: function() {
return dirList.treeList('selected'); return dirList.treeList('selected');
}, },
@ -424,8 +443,8 @@ RED.library = (function() {
return { return {
init: function() { init: function() {
$(_librarySave).appendTo("#red-ui-editor"); $(_librarySave).appendTo("#red-ui-editor").i18n();
$(_libraryLookup).appendTo("#red-ui-editor"); $(_libraryLookup).appendTo("#red-ui-editor").i18n();
$( "#red-ui-library-dialog-save" ).dialog({ $( "#red-ui-library-dialog-save" ).dialog({
title: RED._("library.saveToLibrary"), title: RED._("library.saveToLibrary"),
@ -459,7 +478,7 @@ RED.library = (function() {
saveLibraryBrowser = RED.library.createBrowser({ saveLibraryBrowser = RED.library.createBrowser({
container: $("#red-ui-library-dialog-save-browser"), container: $("#red-ui-library-dialog-save-browser"),
addFolderButton: true, folderTools: true,
onselect: function(item) { onselect: function(item) {
if (item.label) { if (item.label) {
if (!item.children) { if (!item.children) {
@ -482,6 +501,11 @@ RED.library = (function() {
autoOpen: false, autoOpen: false,
width: 800, width: 800,
resizable: false, resizable: false,
classes: {
"ui-dialog": "red-ui-editor-dialog",
"ui-dialog-titlebar-close": "hide",
"ui-widget-overlay": "red-ui-editor-dialog"
},
buttons: [ buttons: [
{ {
text: RED._("common.label.cancel"), text: RED._("common.label.cancel"),
@ -545,11 +569,17 @@ RED.library = (function() {
}); });
RED.panels.create({ RED.panels.create({
container:$("#red-ui-library-dialog-load-panes"), container:$("#red-ui-library-dialog-load-panes"),
dir: "horizontal" dir: "horizontal",
resize: function() {
libraryEditor.resize();
}
}); });
RED.panels.create({ RED.panels.create({
container:$("#red-ui-library-dialog-load-preview"), container:$("#red-ui-library-dialog-load-preview"),
dir: "vertical" dir: "vertical",
resize: function() {
libraryEditor.resize();
}
}); });
}, },
create: createUI, create: createUI,

View File

@ -61,7 +61,7 @@
padding: 0; padding: 0;
background: $form-input-background; background: $form-input-background;
&>div { &>div {
height: calc(100% - 20px) height: 100%;
} }
} }
.red-ui-clipboard-dialog-box { .red-ui-clipboard-dialog-box {
@ -88,14 +88,11 @@
width: calc(100% - 120px); width: calc(100% - 120px);
} }
#red-ui-clipboard-dialog-export-tab-library-browser { #red-ui-clipboard-dialog-export-tab-library-browser {
height: calc(100% - 40px); height: calc(100% - 60px);
margin-bottom: 10px; margin-bottom: 13px;
border-bottom: 1px solid $primary-border-color; border-bottom: 1px solid $primary-border-color;
box-sizing: border-box; box-sizing: border-box;
} }
#red-ui-clipboard-dialog-import-tab-library {
height: 100%;
}
#red-ui-clipboard-dialog-import-tab-library-browser { #red-ui-clipboard-dialog-import-tab-library-browser {
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;

View File

@ -75,7 +75,8 @@
type:"function", // the type of object the library is for type:"function", // the type of object the library is for
editor:this.editor, // the field name the main text body goes to editor:this.editor, // the field name the main text body goes to
mode:"ace/mode/nrjavascript", mode:"ace/mode/nrjavascript",
fields:['name','outputs'] fields:['name','outputs'],
ext:"js"
}); });
this.editor.focus(); this.editor.focus();

View File

@ -95,10 +95,11 @@
value: $("#node-input-template").val() value: $("#node-input-template").val()
}); });
RED.library.create({ RED.library.create({
url:"functions", // where to get the data from url:"templates", // where to get the data from
type:"function", // the type of object the library is for type:"template", // the type of object the library is for
editor:that.editor, // the field name the main text body goes to editor:that.editor, // the field name the main text body goes to
fields:['name','outputs'] fields:['name','format','output','syntax'],
ext: "txt"
}); });
this.editor.focus(); this.editor.focus();

View File

@ -77,9 +77,6 @@ function getFileBody(root,path) {
body += parts[i]+"\n"; body += parts[i]+"\n";
} }
} }
if (! /^\/\/ \w+: /.test(remaining)) {
scanning = false;
}
if (!scanning) { if (!scanning) {
body += remaining; body += remaining;
} }