diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/index.js b/packages/node_modules/@node-red/editor-api/lib/editor/index.js index 2e8333f3f..b2fdc1f6b 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/index.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/index.js @@ -93,6 +93,7 @@ module.exports = { // Library var library = require("./library"); library.init(runtimeAPI); + // editorApp.get("/library/:id",needsPermission("library.read"),library.getLibraryConfig); editorApp.get(/^\/library\/([^\/]+)\/([^\/]+)(?:$|\/(.*))/,needsPermission("library.read"),library.getEntry); editorApp.post(/^\/library\/([^\/]+)\/([^\/]+)\/(.*)/,needsPermission("library.write"),library.saveEntry); diff --git a/packages/node_modules/@node-red/editor-api/lib/editor/library.js b/packages/node_modules/@node-red/editor-api/lib/editor/library.js index 89b92fd11..cd564b3f8 100644 --- a/packages/node_modules/@node-red/editor-api/lib/editor/library.js +++ b/packages/node_modules/@node-red/editor-api/lib/editor/library.js @@ -24,6 +24,17 @@ module.exports = { init: function(_runtimeAPI) { runtimeAPI = _runtimeAPI; }, + // getLibraryConfig: function(req,res) { + // var opts = { + // user: req.user, + // library: req.params.id + // } + // runtimeAPI.library.getConfig(opts).then(function(result) { + // res.json(result); + // }).catch(function(err) { + // apiUtils.rejectHandler(req,res,err); + // }); + // }, getEntry: function(req,res) { var opts = { user: req.user, diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js b/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js index bb82ecea3..6ec719708 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/clipboard.js @@ -26,7 +26,8 @@ RED.clipboard = (function() { var currentPopoverError; var activeTab; var libraryBrowser; - var examplesBrowser; + + var activeLibraries = {}; var pendingImportConfig; @@ -93,7 +94,7 @@ RED.clipboard = (function() { $( this ).dialog( "close" ); } else { var flowToExport = $("#red-ui-clipboard-dialog-export-text").val(); - var selectedPath = libraryBrowser.getSelected(); + var selectedPath = activeLibraries[activeTab].getSelected(); if (!selectedPath.children) { selectedPath = selectedPath.parent; } @@ -159,12 +160,7 @@ RED.clipboard = (function() { if (activeTab === "red-ui-clipboard-dialog-import-tab-clipboard") { importNodes($("#red-ui-clipboard-dialog-import-text").val(),addNewFlow); } else { - var selectedPath; - if (activeTab === "red-ui-clipboard-dialog-import-tab-library") { - selectedPath = libraryBrowser.getSelected(); - } else { - selectedPath = examplesBrowser.getSelected(); - } + var selectedPath = activeLibraries[activeTab].getSelected(); if (selectedPath.path) { $.get('library/'+selectedPath.library+'/'+selectedPath.type+'/'+selectedPath.path, function(data) { importNodes(data,addNewFlow); @@ -254,11 +250,8 @@ RED.clipboard = (function() { ''+ ''+ ''+ - '
'+ - '
'+ - '
'+ - ''+ - '
'+ + '
'+ + ''+ '
'+ '
'+ '' @@ -280,8 +273,6 @@ RED.clipboard = (function() { ''+ ''+ ''+ - '
'+ - '
'+ ''+ ''+ '
'+ @@ -414,7 +405,7 @@ RED.clipboard = (function() { } },100); } else { - var file = libraryBrowser.getSelected(); + var file = activeLibraries[activeTab].getSelected(); if (file && file.label && !file.children) { $("#red-ui-clipboard-dialog-ok").button("enable"); } else { @@ -446,7 +437,7 @@ RED.clipboard = (function() { if (tab.id === "red-ui-clipboard-dialog-import-tab-clipboard") { $("#red-ui-clipboard-dialog-import-text").trigger("focus"); } else { - libraryBrowser.focus(); + activeLibraries[tab.id].focus(); } validateImport(); } @@ -455,54 +446,43 @@ RED.clipboard = (function() { id: "red-ui-clipboard-dialog-import-tab-clipboard", label: RED._("clipboard.clipboard") }); - tabs.addTab({ - id: "red-ui-clipboard-dialog-import-tab-library", - label: RED._("library.library") - }); - tabs.addTab({ - id: "red-ui-clipboard-dialog-import-tab-examples", - label: RED._("library.types.examples") - }); + + var libraries = RED.settings.libraries || []; + libraries.forEach(function(lib) { + var tabId = "red-ui-clipboard-dialog-import-tab-library-"+lib.id + tabs.addTab({ + id: tabId, + label: RED._(lib.label||lib.id) + }) + + var content = $('
') + .attr("id",tabId) + .hide() + .appendTo("#red-ui-clipboard-dialog-import-tabs-content"); + + var browser = RED.library.createBrowser({ + container: content, + 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(browser,lib); + activeLibraries[tabId] = browser; + }) $("#red-ui-clipboard-dialog-tab-library-name").on("keyup", validateExportFilename); $("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)}); $("#red-ui-clipboard-dialog-export").button("enable"); - libraryBrowser = RED.library.createBrowser({ - container: $("#red-ui-clipboard-dialog-import-tab-library"), - 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(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(); $("#red-ui-clipboard-dialog-ok").show(); @@ -582,10 +562,12 @@ RED.clipboard = (function() { if (tab.id === "red-ui-clipboard-dialog-export-tab-clipboard") { $("#red-ui-clipboard-dialog-export").button("option","label", RED._("clipboard.export.copy")) $("#red-ui-clipboard-dialog-download").show(); + $("#red-ui-clipboard-dialog-export-tab-library-filename").hide(); } else { $("#red-ui-clipboard-dialog-export").button("option","label", RED._("clipboard.export.export")) $("#red-ui-clipboard-dialog-download").hide(); - libraryBrowser.focus(); + $("#red-ui-clipboard-dialog-export-tab-library-filename").show(); + activeLibraries[activeTab].focus(); } } @@ -594,26 +576,45 @@ RED.clipboard = (function() { id: "red-ui-clipboard-dialog-export-tab-clipboard", label: RED._("clipboard.clipboard") }); - tabs.addTab({ - id: "red-ui-clipboard-dialog-export-tab-library", - label: RED._("library.library") - }); + + + var libraries = RED.settings.libraries || []; + + libraries.forEach(function(lib) { + if (lib.readOnly) { + return + } + var tabId = "red-ui-clipboard-dialog-export-tab-library-"+lib.id + tabs.addTab({ + id: tabId, + label: RED._(lib.label||lib.id) + }) + + var content = $('
') + .attr("id",tabId) + .hide() + .insertBefore("#red-ui-clipboard-dialog-export-tab-library-filename"); + + var browser = RED.library.createBrowser({ + container: content, + folderTools: true, + onselect: function(file) { + if (file && file.label && !file.children) { + $("#red-ui-clipboard-dialog-tab-library-name").val(file.label); + } + }, + }) + loadFlowLibrary(browser,lib); + activeLibraries[tabId] = browser; + }) + + + $("#red-ui-clipboard-dialog-tab-library-name").on("keyup", validateExportFilename); $("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)}); $("#red-ui-clipboard-dialog-export").button("enable"); - libraryBrowser = RED.library.createBrowser({ - container: $("#red-ui-clipboard-dialog-export-tab-library-browser"), - folderTools: true, - onselect: function(file) { - if (file && file.label && !file.children) { - $("#red-ui-clipboard-dialog-tab-library-name").val(file.label); - } - } - }) - loadFlowLibrary(libraryBrowser,"local",RED._("library.types.local")); - var clipboardTabs = RED.tabs.create({ id: "red-ui-clipboard-dialog-export-tab-clipboard-tabs", onchange: function(tab) { @@ -852,35 +853,33 @@ RED.clipboard = (function() { $("#red-ui-clipboard-dialog-export-tab-clipboard-preview-list").treeList('data',treeData); } - function loadFlowLibrary(browser,library,label) { - // if (includeExamples) { - // listing.push({ - // library: "_examples_", - // type: "flows", - // icon: 'fa fa-hdd-o', - // label: RED._("library.types.examples"), - // path: "", - // children: function(done,item) { - // RED.library.loadLibraryFolder("_examples_","flows","",function(children) { - // item.children = children; - // done(children); - // }) - // } - // }) - // } + function loadFlowLibrary(browser,library) { + var icon = 'fa fa-hdd-o'; + if (library.icon) { + var fullIcon = RED.utils.separateIconPath(library.icon); + icon = (fullIcon.module==="font-awesome"?"fa ":"")+fullIcon.file; + } browser.data([{ - library: library, + library: library.id, type: "flows", - icon: 'fa fa-hdd-o', - label: label, + icon: icon, + label: RED._(library.label||library.id), path: "", expanded: true, - children: function(done, item) { - RED.library.loadLibraryFolder(library,"flows","",function(children) { - item.children = children; - done(children); - }) - } + children: [{ + library: library.id, + type: "flows", + icon: 'fa fa-cube', + label: "flows", + path: "", + expanded: true, + children: function(done, item) { + RED.library.loadLibraryFolder(library.id,"flows","",function(children) { + item.children = children; + done(children); + }) + } + }] }], true); } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/library.js b/packages/node_modules/@node-red/editor-client/src/js/ui/library.js index 54d73c022..66e617229 100755 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/library.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/library.js @@ -216,31 +216,7 @@ RED.library = (function() { { id:'node-input-'+options.type+'-menu-open-library', label: RED._("library.openLibrary"), onselect: function() { - activeLibrary = options; - loadLibraryFolder("local",options.url, "", function(items) { - var listing = [{ - library: "local", - type: options.url, - icon: 'fa fa-hdd-o', - label: RED._("library.types.local"), - path: "", - expanded: true, - writable: false, - children: [{ - library: "local", - type: options.url, - icon: 'fa fa-cube', - label: options.type, - path: "", - expanded: true, - children: items - }] - }] - loadLibraryBrowser.data(listing); - setTimeout(function() { - loadLibraryBrowser.select(listing[0].children[0]); - },200); - }); + libraryEditor = ace.edit('red-ui-library-dialog-load-preview-text',{ useWorker: false }); @@ -256,6 +232,43 @@ RED.library = (function() { libraryEditor.renderer.$cursorLayer.element.style.opacity=0; libraryEditor.$blockScrolling = Infinity; + activeLibrary = options; + var listing = []; + var libraries = RED.settings.libraries || []; + libraries.forEach(function(lib) { + if (lib.types && lib.types.indexOf(options.url) === -1) { + return; + } + listing.push({ + library: lib.id, + type: options.url, + icon: lib.icon || 'fa fa-hdd-o', + label: RED._(lib.label||lib.id), + path: "", + expanded: true, + writable: false, + children: [{ + library: lib.id, + type: options.url, + icon: 'fa fa-cube', + label: options.type, + path: "", + expanded: false, + children: function(done, item) { + loadLibraryFolder(lib.id, options.url, "", function(children) { + item.children = children; + done(children); + }) + } + }] + }) + }); + loadLibraryBrowser.data(listing); + setTimeout(function() { + loadLibraryBrowser.select(listing[0].children[0]); + },200); + + var dialogHeight = 400; var winHeight = $(window).height(); if (winHeight < 570) { @@ -278,30 +291,40 @@ RED.library = (function() { } $("#red-ui-library-dialog-save-filename").attr("value",filename+"."+(options.ext||"txt")); - loadLibraryFolder("local",options.url, "", function(items) { - var listing = [{ - library: "local", + var listing = []; + var libraries = RED.settings.libraries || []; + libraries.forEach(function(lib) { + if (lib.types && lib.types.indexOf(options.url) === -1) { + return; + } + listing.push({ + library: lib.id, type: options.url, - icon: 'fa fa-hdd-o', - label: RED._("library.types.local"), + icon: lib.icon || 'fa fa-hdd-o', + label: RED._(lib.label||lib.id), path: "", expanded: true, writable: false, children: [{ - library: "local", + library: lib.id, type: options.url, icon: 'fa fa-cube', label: options.type, path: "", - expanded: true, - children: items + expanded: false, + children: function(done, item) { + loadLibraryFolder(lib.id, options.url, "", function(children) { + item.children = children; + done(children); + }) + } }] - }] - saveLibraryBrowser.data(listing); - setTimeout(function() { - saveLibraryBrowser.select(listing[0].children[0]); - },200); + }) }); + saveLibraryBrowser.data(listing); + setTimeout(function() { + saveLibraryBrowser.select(listing[0].children[0]); + },200); var dialogHeight = 400; var winHeight = $(window).height(); @@ -460,9 +483,235 @@ RED.library = (function() { } } + // var libraryPlugins = {}; + // + // function showLibraryDetailsDialog(container, lib, done) { + // var dialog = $('
').addClass("red-ui-projects-dialog-list-dialog").hide().appendTo(container); + // $('
').addClass("red-ui-projects-dialog-list-dialog-header").text(lib?"Edit library source":"Add library source").appendTo(dialog); + // var formRow = $('
').appendTo(dialog); + // $('