From 3f9a29730f9ddcbb8ce2cadad5c77c77f9b4f2f6 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Fri, 22 Jan 2021 11:20:28 +0000 Subject: [PATCH] Add partial implementation of adding library sources via editor This adds lots of commented out code that provides a settings panel to add new library sources. It is incomplete as it doesn't actually add/update the library sources on the runtime. For 1.3, I'm focussing on allowing additional sources get added via the settings file only. I've done enough work on the editor side to convince myself more work is needed than I can justify at this time on what is otherwise not going to be a widely used feature. --- .../@node-red/editor-api/lib/editor/index.js | 1 + .../editor-api/lib/editor/library.js | 11 + .../editor-client/src/js/ui/clipboard.js | 7 +- .../editor-client/src/js/ui/library.js | 228 +++++++++++++++++- .../editor-client/src/sass/library.scss | 38 +++ .../editor-client/src/sass/projects.scss | 1 + .../@node-red/runtime/lib/api/library.js | 21 ++ .../@node-red/runtime/lib/library/examples.js | 6 +- .../@node-red/runtime/lib/library/index.js | 75 +++--- .../@node-red/runtime/lib/library/local.js | 4 +- .../plugin/test-plugin/library-filestore.html | 15 +- .../plugin/test-plugin/library-filestore.js | 17 +- .../locales/en-US/library-filestore.json | 8 + 13 files changed, 393 insertions(+), 39 deletions(-) create mode 100644 test/resources/plugin/test-plugin/locales/en-US/library-filestore.json 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 eb3b7b6de..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 @@ -854,10 +854,15 @@ RED.clipboard = (function() { } 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.id, type: "flows", - icon: library.icon || 'fa fa-hdd-o', + icon: icon, label: RED._(library.label||library.id), path: "", expanded: 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 3872a38ea..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 @@ -483,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); + // $('