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

Merge pull request #2785 from node-red/library-plugins

Library plugins
This commit is contained in:
Nick O'Leary 2021-02-25 16:05:23 +00:00 committed by GitHub
commit 3af77b6a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 833 additions and 180 deletions

View File

@ -93,6 +93,7 @@ module.exports = {
// Library // Library
var library = require("./library"); var library = require("./library");
library.init(runtimeAPI); library.init(runtimeAPI);
// editorApp.get("/library/:id",needsPermission("library.read"),library.getLibraryConfig);
editorApp.get(/^\/library\/([^\/]+)\/([^\/]+)(?:$|\/(.*))/,needsPermission("library.read"),library.getEntry); editorApp.get(/^\/library\/([^\/]+)\/([^\/]+)(?:$|\/(.*))/,needsPermission("library.read"),library.getEntry);
editorApp.post(/^\/library\/([^\/]+)\/([^\/]+)\/(.*)/,needsPermission("library.write"),library.saveEntry); editorApp.post(/^\/library\/([^\/]+)\/([^\/]+)\/(.*)/,needsPermission("library.write"),library.saveEntry);

View File

@ -24,6 +24,17 @@ module.exports = {
init: function(_runtimeAPI) { init: function(_runtimeAPI) {
runtimeAPI = _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) { getEntry: function(req,res) {
var opts = { var opts = {
user: req.user, user: req.user,

View File

@ -26,7 +26,8 @@ RED.clipboard = (function() {
var currentPopoverError; var currentPopoverError;
var activeTab; var activeTab;
var libraryBrowser; var libraryBrowser;
var examplesBrowser;
var activeLibraries = {};
var pendingImportConfig; var pendingImportConfig;
@ -93,7 +94,7 @@ RED.clipboard = (function() {
$( this ).dialog( "close" ); $( this ).dialog( "close" );
} else { } else {
var flowToExport = $("#red-ui-clipboard-dialog-export-text").val(); var flowToExport = $("#red-ui-clipboard-dialog-export-text").val();
var selectedPath = libraryBrowser.getSelected(); var selectedPath = activeLibraries[activeTab].getSelected();
if (!selectedPath.children) { if (!selectedPath.children) {
selectedPath = selectedPath.parent; selectedPath = selectedPath.parent;
} }
@ -159,12 +160,7 @@ RED.clipboard = (function() {
if (activeTab === "red-ui-clipboard-dialog-import-tab-clipboard") { if (activeTab === "red-ui-clipboard-dialog-import-tab-clipboard") {
importNodes($("#red-ui-clipboard-dialog-import-text").val(),addNewFlow); importNodes($("#red-ui-clipboard-dialog-import-text").val(),addNewFlow);
} else { } else {
var selectedPath; var selectedPath = activeLibraries[activeTab].getSelected();
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) {
importNodes(data,addNewFlow); importNodes(data,addNewFlow);
@ -254,13 +250,10 @@ RED.clipboard = (function() {
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'<div id="red-ui-clipboard-dialog-export-tab-library" class="red-ui-clipboard-dialog-tab-library">'+ '<div class="form-row" id="red-ui-clipboard-dialog-export-tab-library-filename">'+
'<div id="red-ui-clipboard-dialog-export-tab-library-browser"></div>'+
'<div class="form-row">'+
'<label data-i18n="clipboard.export.exportAs"></label><input id="red-ui-clipboard-dialog-tab-library-name" type="text">'+ '<label data-i18n="clipboard.export.exportAs"></label><input id="red-ui-clipboard-dialog-tab-library-name" type="text">'+
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'</div>'+
'</div>' '</div>'
; ;
@ -280,8 +273,6 @@ 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>'+
'<div id="red-ui-clipboard-dialog-import-tab-examples" class="red-ui-clipboard-dialog-tab-library"></div>'+
'</div>'+ '</div>'+
'</div>'+ '</div>'+
'<div class="form-row">'+ '<div class="form-row">'+
@ -414,7 +405,7 @@ RED.clipboard = (function() {
} }
},100); },100);
} else { } else {
var file = libraryBrowser.getSelected(); var file = activeLibraries[activeTab].getSelected();
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 {
@ -446,7 +437,7 @@ RED.clipboard = (function() {
if (tab.id === "red-ui-clipboard-dialog-import-tab-clipboard") { if (tab.id === "red-ui-clipboard-dialog-import-tab-clipboard") {
$("#red-ui-clipboard-dialog-import-text").trigger("focus"); $("#red-ui-clipboard-dialog-import-text").trigger("focus");
} else { } else {
libraryBrowser.focus(); activeLibraries[tab.id].focus();
} }
validateImport(); validateImport();
} }
@ -455,54 +446,43 @@ RED.clipboard = (function() {
id: "red-ui-clipboard-dialog-import-tab-clipboard", id: "red-ui-clipboard-dialog-import-tab-clipboard",
label: RED._("clipboard.clipboard") label: RED._("clipboard.clipboard")
}); });
var libraries = RED.settings.libraries || [];
libraries.forEach(function(lib) {
var tabId = "red-ui-clipboard-dialog-import-tab-library-"+lib.id
tabs.addTab({ tabs.addTab({
id: "red-ui-clipboard-dialog-import-tab-library", id: tabId,
label: RED._("library.library") label: RED._(lib.label||lib.id)
}); })
tabs.addTab({
id: "red-ui-clipboard-dialog-import-tab-examples", var content = $('<div id="red-ui-clipboard-dialog-import-tab-library" class="red-ui-clipboard-dialog-tab-library"></div>')
label: RED._("library.types.examples") .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("keyup", validateExportFilename);
$("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)}); $("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)});
$("#red-ui-clipboard-dialog-export").button("enable"); $("#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(); dialogContainer.i18n();
$("#red-ui-clipboard-dialog-ok").show(); $("#red-ui-clipboard-dialog-ok").show();
@ -582,10 +562,12 @@ RED.clipboard = (function() {
if (tab.id === "red-ui-clipboard-dialog-export-tab-clipboard") { 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-export").button("option","label", RED._("clipboard.export.copy"))
$("#red-ui-clipboard-dialog-download").show(); $("#red-ui-clipboard-dialog-download").show();
$("#red-ui-clipboard-dialog-export-tab-library-filename").hide();
} else { } else {
$("#red-ui-clipboard-dialog-export").button("option","label", RED._("clipboard.export.export")) $("#red-ui-clipboard-dialog-export").button("option","label", RED._("clipboard.export.export"))
$("#red-ui-clipboard-dialog-download").hide(); $("#red-ui-clipboard-dialog-download").hide();
libraryBrowser.focus(); $("#red-ui-clipboard-dialog-export-tab-library-filename").show();
activeLibraries[activeTab].focus();
} }
} }
@ -594,25 +576,44 @@ RED.clipboard = (function() {
id: "red-ui-clipboard-dialog-export-tab-clipboard", id: "red-ui-clipboard-dialog-export-tab-clipboard",
label: RED._("clipboard.clipboard") label: RED._("clipboard.clipboard")
}); });
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({ tabs.addTab({
id: "red-ui-clipboard-dialog-export-tab-library", id: tabId,
label: RED._("library.library") label: RED._(lib.label||lib.id)
}); })
$("#red-ui-clipboard-dialog-tab-library-name").on("keyup", validateExportFilename); var content = $('<div class="red-ui-clipboard-dialog-export-tab-library-browser red-ui-clipboard-dialog-tab-library"></div>')
$("#red-ui-clipboard-dialog-tab-library-name").on('paste',function() { setTimeout(validateExportFilename,10)}); .attr("id",tabId)
$("#red-ui-clipboard-dialog-export").button("enable"); .hide()
.insertBefore("#red-ui-clipboard-dialog-export-tab-library-filename");
libraryBrowser = RED.library.createBrowser({ var browser = RED.library.createBrowser({
container: $("#red-ui-clipboard-dialog-export-tab-library-browser"), container: content,
folderTools: true, folderTools: true,
onselect: function(file) { onselect: function(file) {
if (file && file.label && !file.children) { if (file && file.label && !file.children) {
$("#red-ui-clipboard-dialog-tab-library-name").val(file.label); $("#red-ui-clipboard-dialog-tab-library-name").val(file.label);
} }
} },
}) })
loadFlowLibrary(libraryBrowser,"local",RED._("library.types.local")); 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");
var clipboardTabs = RED.tabs.create({ var clipboardTabs = RED.tabs.create({
id: "red-ui-clipboard-dialog-export-tab-clipboard-tabs", id: "red-ui-clipboard-dialog-export-tab-clipboard-tabs",
@ -852,35 +853,33 @@ RED.clipboard = (function() {
$("#red-ui-clipboard-dialog-export-tab-clipboard-preview-list").treeList('data',treeData); $("#red-ui-clipboard-dialog-export-tab-clipboard-preview-list").treeList('data',treeData);
} }
function loadFlowLibrary(browser,library,label) { function loadFlowLibrary(browser,library) {
// if (includeExamples) { var icon = 'fa fa-hdd-o';
// listing.push({ if (library.icon) {
// library: "_examples_", var fullIcon = RED.utils.separateIconPath(library.icon);
// type: "flows", icon = (fullIcon.module==="font-awesome"?"fa ":"")+fullIcon.file;
// 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);
// })
// }
// })
// }
browser.data([{ browser.data([{
library: library, library: library.id,
type: "flows", type: "flows",
icon: 'fa fa-hdd-o', icon: icon,
label: label, label: RED._(library.label||library.id),
path: "",
expanded: true,
children: [{
library: library.id,
type: "flows",
icon: 'fa fa-cube',
label: "flows",
path: "", path: "",
expanded: true, expanded: true,
children: function(done, item) { children: function(done, item) {
RED.library.loadLibraryFolder(library,"flows","",function(children) { RED.library.loadLibraryFolder(library.id,"flows","",function(children) {
item.children = children; item.children = children;
done(children); done(children);
}) })
} }
}]
}], true); }], true);
} }

View File

@ -216,31 +216,7 @@ RED.library = (function() {
{ id:'node-input-'+options.type+'-menu-open-library', { id:'node-input-'+options.type+'-menu-open-library',
label: RED._("library.openLibrary"), label: RED._("library.openLibrary"),
onselect: function() { 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',{ libraryEditor = ace.edit('red-ui-library-dialog-load-preview-text',{
useWorker: false useWorker: false
}); });
@ -256,6 +232,43 @@ RED.library = (function() {
libraryEditor.renderer.$cursorLayer.element.style.opacity=0; libraryEditor.renderer.$cursorLayer.element.style.opacity=0;
libraryEditor.$blockScrolling = Infinity; 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 dialogHeight = 400;
var winHeight = $(window).height(); var winHeight = $(window).height();
if (winHeight < 570) { if (winHeight < 570) {
@ -278,30 +291,40 @@ RED.library = (function() {
} }
$("#red-ui-library-dialog-save-filename").attr("value",filename+"."+(options.ext||"txt")); $("#red-ui-library-dialog-save-filename").attr("value",filename+"."+(options.ext||"txt"));
loadLibraryFolder("local",options.url, "", function(items) { var listing = [];
var listing = [{ var libraries = RED.settings.libraries || [];
library: "local", libraries.forEach(function(lib) {
if (lib.types && lib.types.indexOf(options.url) === -1) {
return;
}
listing.push({
library: lib.id,
type: options.url, type: options.url,
icon: 'fa fa-hdd-o', icon: lib.icon || 'fa fa-hdd-o',
label: RED._("library.types.local"), label: RED._(lib.label||lib.id),
path: "", path: "",
expanded: true, expanded: true,
writable: false, writable: false,
children: [{ children: [{
library: "local", library: lib.id,
type: options.url, type: options.url,
icon: 'fa fa-cube', icon: 'fa fa-cube',
label: options.type, label: options.type,
path: "", path: "",
expanded: true, expanded: false,
children: items children: function(done, item) {
}] loadLibraryFolder(lib.id, options.url, "", function(children) {
item.children = children;
done(children);
})
}
}] }]
})
});
saveLibraryBrowser.data(listing); saveLibraryBrowser.data(listing);
setTimeout(function() { setTimeout(function() {
saveLibraryBrowser.select(listing[0].children[0]); saveLibraryBrowser.select(listing[0].children[0]);
},200); },200);
});
var dialogHeight = 400; var dialogHeight = 400;
var winHeight = $(window).height(); var winHeight = $(window).height();
@ -460,9 +483,235 @@ RED.library = (function() {
} }
} }
// var libraryPlugins = {};
//
// function showLibraryDetailsDialog(container, lib, done) {
// var dialog = $('<div>').addClass("red-ui-projects-dialog-list-dialog").hide().appendTo(container);
// $('<div>').addClass("red-ui-projects-dialog-list-dialog-header").text(lib?"Edit library source":"Add library source").appendTo(dialog);
// var formRow = $('<div class="red-ui-settings-row"></div>').appendTo(dialog);
// $('<label>').text("Type").appendTo(formRow);
// var typeSelect = $('<select>').appendTo(formRow);
// for (var type in libraryPlugins) {
// if (libraryPlugins.hasOwnProperty(type)) {
// $('<option>').attr('value',type).attr('selected',(lib && lib.type === type)?true:null).text(libraryPlugins[type].name).appendTo(typeSelect);
// }
// }
// var dialogBody = $("<div>").addClass("red-ui-settings-section").appendTo(dialog);
// var libraryFields = {};
// var fieldsModified = {};
// function validateFields() {
// var validForm = true;
// for (var p in libraryFields) {
// if (libraryFields.hasOwnProperty(p)) {
// var v = libraryFields[p].input.val().trim();
// if (v === "") {
// validForm = false;
// if (libraryFields[p].modified) {
// libraryFields[p].input.addClass("input-error");
// }
// } else {
// libraryFields[p].input.removeClass("input-error");
// }
// }
// }
// okayButton.attr("disabled",validForm?null:"disabled");
// }
// typeSelect.on("change", function(evt) {
// dialogBody.empty();
// libraryFields = {};
// fieldsModified = {};
// var libDef = libraryPlugins[$(this).val()];
// var defaultIcon = lib?lib.icon:(libDef.icon || "font-awesome/fa-image");
// formRow = $('<div class="red-ui-settings-row"></div>').appendTo(dialogBody);
// $('<label>').text(RED._("editor.settingIcon")).appendTo(formRow);
// libraryFields['icon'] = {input: $('<input type="hidden">').val(defaultIcon) };
// var iconButton = $('<button type="button" class="red-ui-button"></button>').appendTo(formRow);
// iconButton.on("click", function(evt) {
// evt.preventDefault();
// var icon = libraryFields['icon'].input.val() || "";
// var iconPath = (icon ? RED.utils.separateIconPath(icon) : {});
// RED.editor.showIconPicker(iconButton, null, iconPath, true, function (newIcon) {
// iconButton.empty();
// var path = newIcon || "";
// var newPath = RED.utils.separateIconPath(path);
// if (newPath) {
// $('<i class="fa"></i>').addClass(newPath.file).appendTo(iconButton);
// }
// libraryFields['icon'].input.val(path);
// });
// })
// var newPath = RED.utils.separateIconPath(defaultIcon);
// $('<i class="fa '+newPath.file+'"></i>').appendTo(iconButton);
//
// var libProps = libDef.defaults;
// var libPropKeys = Object.keys(libProps).map(function(p) { return {id: p, def: libProps[p]}});
// libPropKeys.unshift({id: "label", def: {value:""}})
//
// libPropKeys.forEach(function(prop) {
// var p = prop.id;
// var def = prop.def;
// formRow = $('<div class="red-ui-settings-row"></div>').appendTo(dialogBody);
// var label = libDef._(def.label || "label."+p,{defaultValue: p});
// if (label === p) {
// label = libDef._("editor:common.label."+p,{defaultValue:p});
// }
// $('<label>').text(label).appendTo(formRow);
// libraryFields[p] = {
// input: $('<input type="text">').val(lib?(lib[p]||lib.config[p]):def.value).appendTo(formRow),
// modified: false
// }
// if (def.type === "password") {
// libraryFields[p].input.attr("type","password").typedInput({type:"cred"})
// }
//
// libraryFields[p].input.on("change paste keyup", function(evt) {
// if (!evt.key || evt.key.length === 1) {
// libraryFields[p].modified = true;
// }
// validateFields();
// })
// var desc = libDef._("desc."+p, {defaultValue: ""});
// if (desc) {
// $('<label class="red-ui-projects-edit-form-sublabel"></label>').append($('<small>').text(desc)).appendTo(formRow);
// }
// });
// validateFields();
// })
//
// var dialogButtons = $('<span class="button-row" style="position: relative; float: right; margin: 10px;"></span>').appendTo(dialog);
// var cancelButton = $('<button class="red-ui-button"></button>').text(RED._("common.label.cancel")).appendTo(dialogButtons).on("click", function(evt) {
// evt.preventDefault();
// done(false);
// })
// var okayButton = $('<button class="red-ui-button"></button>').text(lib?"Update library":"Add library").appendTo(dialogButtons).on("click", function(evt) {
// evt.preventDefault();
// var item;
// if (!lib) {
// item = {
// id: libraryFields['label'].input.val().trim().toLowerCase().replace(/( |[^a-z0-9])/g,"-"),
// user: true,
// type: typeSelect.val(),
// config: {}
// }
// } else {
// item = lib;
// }
//
// item.label = libraryFields['label'].input.val().trim();
// item.icon = libraryFields['icon'].input.val();
//
// for (var p in libraryFields) {
// if (libraryFields.hasOwnProperty(p) && p !== 'label') {
// item.config[p] = libraryFields[p].input.val().trim();
// }
// }
// done(item);
// });
//
// typeSelect.trigger("change");
// if (lib) {
// typeSelect.attr('disabled',true);
// }
//
// dialog.slideDown(200);
// }
//
// function createSettingsPane() {
// var pane = $('<div id="red-ui-settings-tab-library-manager"></div>');
// var toolbar = $('<div>').css("text-align","right").appendTo(pane);
// var addButton = $('<button class="red-ui-button"><i class="fa fa-plus"></i> Add library</button>').appendTo(toolbar);
//
// var addingLibrary = false;
//
// var libraryList = $("<ol>").css({
// position: "absolute",
// left: "10px",
// right: "10px",
// top: "50px",
// bottom: "10px"
// }).appendTo(pane).editableList({
// addButton: false,
// addItem: function(row,index,itemData) {
// if (itemData.id) {
// row.addClass("red-ui-settings-tab-library-entry");
// var iconCell = $("<span>").appendTo(row);
// if (itemData.icon) {
// var iconPath = RED.utils.separateIconPath(itemData.icon);
// if (iconPath) {
// $("<i>").addClass("fa "+iconPath.file).appendTo(iconCell);
// }
// }
// $("<span>").text(RED._(itemData.label)).appendTo(row);
// $("<span>").text(RED._(itemData.type)).appendTo(row);
// $('<button class="red-ui-button red-ui-button-small"></button>').text(RED._("sidebar.project.projectSettings.edit")).appendTo(
// $('<span>').appendTo(row)
// ).on("click", function(evt) {
// if (addingLibrary) {
// return;
// }
// evt.preventDefault();
// addingLibrary = true;
// row.empty();
// row.removeClass("red-ui-settings-tab-library-entry");
// showLibraryDetailsDialog(row,itemData,function(newItem) {
// var itemIndex = libraryList.editableList("indexOf", itemData);
// libraryList.editableList("removeItem", itemData);
// if (newItem) {
// libraryList.editableList("insertItemAt", newItem, itemIndex);
// } else {
// libraryList.editableList("insertItemAt", itemData,itemIndex);
// }
// addingLibrary = false;
//
// })
// })
//
// } else {
// showLibraryDetailsDialog(row,null,function(newItem) {
// libraryList.editableList("removeItem", itemData);
// if (newItem) {
// libraryList.editableList("addItem", newItem);
// }
// addingLibrary = false;
// })
//
// }
// }
// });
//
// addButton.on('click', function(evt) {
// evt.preventDefault();
// if (!addingLibrary) {
// addingLibrary = true;
// libraryList.editableList("addItem",{user:true});
// }
// })
// var libraries = RED.settings.libraries || [];
// libraries.forEach(function(library) {
// if (library.user) {
// libraryList.editableList("addItem",library)
// }
// })
//
// return pane;
// }
//
//
return { return {
init: function() { init: function() {
// RED.events.on("registry:plugin-added", function(id) {
// var plugin = RED.plugins.getPlugin(id);
// if (plugin.type === "node-red-library-source") {
// libraryPlugins[id] = plugin;
// }
// });
//
// RED.userSettings.add({
// id:'library-manager',
// title: "NLS: Libraries",
// get: createSettingsPane,
// close: function() {}
// });
$(_librarySave).appendTo("#red-ui-editor").i18n(); $(_librarySave).appendTo("#red-ui-editor").i18n();
$(_libraryLookup).appendTo("#red-ui-editor").i18n(); $(_libraryLookup).appendTo("#red-ui-editor").i18n();

View File

@ -93,11 +93,10 @@
border:1px solid $primary-border-color; border:1px solid $primary-border-color;
} }
.red-ui-clipboard-dialog-tab-library { #red-ui-clipboard-dialog-export-tab-library-filename {
.form-row { height: auto !important;
margin-left: 10px; margin-left: 10px;
} }
}
#red-ui-clipboard-dialog { #red-ui-clipboard-dialog {
form { form {
@ -110,7 +109,7 @@
#red-ui-clipboard-dialog-tab-library-name { #red-ui-clipboard-dialog-tab-library-name {
width: calc(100% - 120px); width: calc(100% - 120px);
} }
#red-ui-clipboard-dialog-export-tab-library-browser { .red-ui-clipboard-dialog-tabs-content>div.red-ui-clipboard-dialog-export-tab-library-browser {
height: calc(100% - 60px); height: calc(100% - 60px);
margin-bottom: 13px; margin-bottom: 13px;
border-bottom: 1px solid $primary-border-color; border-bottom: 1px solid $primary-border-color;
@ -233,3 +232,41 @@
margin: 0; margin: 0;
} }
} }
#red-ui-settings-tab-library-manager {
box-sizing: border-box;
padding: 10px;
position: relative;
height: 100%;
li {
padding: 0;
}
}
.red-ui-settings-tab-library-entry {
display: flex;
flex-direction: row;
span:not(:nth-child(2)) {
@include disable-selection;
}
span {
padding: 8px 0;
}
span:first-child {
display: inline-block;
width: 20px;
padding-right: 8px;
text-align: center;
flex-grow: 0;
}
span:nth-child(2) {
flex-grow: 1;
}
span:nth-child(3), span:nth-child(4) {
flex-grow: 0;
padding-right: 5px;
color: $secondary-text-color;
font-size: 0.9em;
}
}

View File

@ -807,6 +807,7 @@ div.red-ui-projects-dialog-ssh-public-key {
border: 1px solid $secondary-border-color; border: 1px solid $secondary-border-color;
.red-ui-projects-edit-form-sublabel { .red-ui-projects-edit-form-sublabel {
margin-top: -8px !important; margin-top: -8px !important;
margin-right: 50px;
display: block !important; display: block !important;
width: auto !important; width: auto !important;
} }

View File

@ -304,6 +304,7 @@ module.exports = {
getPluginsByType: plugins.getPluginsByType, getPluginsByType: plugins.getPluginsByType,
getPluginList: plugins.getPluginList, getPluginList: plugins.getPluginList,
getPluginConfigs: plugins.getPluginConfigs, getPluginConfigs: plugins.getPluginConfigs,
exportPluginSettings: plugins.exportPluginSettings,
deprecated: require("./deprecated") deprecated: require("./deprecated")

View File

@ -1,11 +1,13 @@
const registry = require("./registry"); const registry = require("./registry");
const {events} = require("@node-red/util") const {events} = require("@node-red/util");
const clone = require("clone");
var pluginConfigCache = {}; let pluginConfigCache = {};
var pluginToId = {}; let pluginToId = {};
var plugins = {}; let plugins = {};
var pluginsByType = {}; let pluginsByType = {};
var settings; let pluginSettings = {};
let settings;
function init(_settings) { function init(_settings) {
settings = _settings; settings = _settings;
@ -13,6 +15,7 @@ function init(_settings) {
pluginConfigCache = {}; pluginConfigCache = {};
pluginToId = {}; pluginToId = {};
pluginsByType = {}; pluginsByType = {};
pluginSettings = {};
} }
function registerPlugin(nodeSetId,id,definition) { function registerPlugin(nodeSetId,id,definition) {
@ -32,6 +35,11 @@ function registerPlugin(nodeSetId,id,definition) {
pluginsByType[definition.type] = pluginsByType[definition.type] || []; pluginsByType[definition.type] = pluginsByType[definition.type] || [];
pluginsByType[definition.type].push(definition); pluginsByType[definition.type].push(definition);
} }
if (definition.settings) {
pluginSettings[id] = definition.settings;
}
if (definition.onadd && typeof definition.onadd === 'function') { if (definition.onadd && typeof definition.onadd === 'function') {
definition.onadd(); definition.onadd();
} }
@ -93,11 +101,53 @@ function getPluginList() {
return list; return list;
} }
function exportPluginSettings(safeSettings) {
for (let id in pluginSettings) {
if (pluginSettings.hasOwnProperty(id)) {
if (settings.hasOwnProperty(id) && !safeSettings.hasOwnProperty(id)) {
let pluginTypeSettings = pluginSettings[id];
let exportedSet = {};
let defaultExportable = false;
if (pluginTypeSettings['*'] && pluginTypeSettings['*'].hasOwnProperty("exportable")) {
defaultExportable = pluginTypeSettings['*'].exportable;
}
if (defaultExportable) {
exportedSet = clone(settings[id]);
}
for (let property in pluginTypeSettings) {
if (pluginTypeSettings.hasOwnProperty(property)) {
let setting = pluginTypeSettings[property];
if (defaultExportable) {
if (setting.exportable === false) {
delete exportedSet[property]
} else if (!exportedSet.hasOwnProperty(property) && setting.hasOwnProperty('value')) {
exportedSet[property] = setting.value;
}
} else if (setting.exportable) {
if (settings[id].hasOwnProperty(property)) {
exportedSet[property] = settings[id][property];
} else if (setting.hasOwnProperty('value')) {
exportedSet[property] = setting.value;
}
}
}
}
if (Object.keys(exportedSet).length > 0) {
safeSettings[id] = exportedSet;
}
}
}
}
return safeSettings;
}
module.exports = { module.exports = {
init, init,
registerPlugin, registerPlugin,
getPlugin, getPlugin,
getPluginsByType, getPluginsByType,
getPluginConfigs, getPluginConfigs,
getPluginList getPluginList,
exportPluginSettings
} }

View File

@ -25,6 +25,27 @@ var api = module.exports = {
runtime = _runtime; runtime = _runtime;
}, },
// /* *
// * Gets the configuration of a library source.
// * @param {Object} opts
// * @param {User} opts.user - the user calling the api
// * @param {String} opts.library - the library
// * @param {Object} opts.req - the request to log (optional)
// * @return {Promise<String|Object>} - resolves when complete
// * @memberof @node-red/runtime_library
// */
// getConfig: async function(opts) {
// runtime.log.audit({event: "library.getConfig",library:opts.library}, opts.req);
// try {
// return runtime.library.getConfig(opts.library)
// } catch(err) {
// var error = new Error();
// error.code = "not_found";
// error.status = 404;
// throw error;
// }
// },
/** /**
* Gets an entry from the library. * Gets an entry from the library.
* @param {Object} opts * @param {Object} opts

View File

@ -81,7 +81,7 @@ var api = module.exports = {
if (!runtime.settings.disableEditor) { if (!runtime.settings.disableEditor) {
safeSettings.context = runtime.nodes.listContextStores(); safeSettings.context = runtime.nodes.listContextStores();
safeSettings.libraries = runtime.library.getLibraries();
if (util.isArray(runtime.settings.paletteCategories)) { if (util.isArray(runtime.settings.paletteCategories)) {
safeSettings.paletteCategories = runtime.settings.paletteCategories; safeSettings.paletteCategories = runtime.settings.paletteCategories;
} }
@ -130,6 +130,7 @@ var api = module.exports = {
safeSettings.flowEncryptionType = runtime.nodes.getCredentialKeyType(); safeSettings.flowEncryptionType = runtime.nodes.getCredentialKeyType();
runtime.settings.exportNodeSettings(safeSettings); runtime.settings.exportNodeSettings(safeSettings);
runtime.plugins.exportPluginSettings(safeSettings);
} }
return safeSettings; return safeSettings;

View File

@ -74,7 +74,6 @@ function init(userSettings,httpServer,_adminApi) {
adminApi = _adminApi; adminApi = _adminApi;
} }
redNodes.init(runtime); redNodes.init(runtime);
library.init(runtime);
externalAPI.init(runtime); externalAPI.init(runtime);
} }
@ -104,6 +103,7 @@ function start() {
return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"..","locales")),"runtime.json") return i18n.registerMessageCatalog("runtime",path.resolve(path.join(__dirname,"..","locales")),"runtime.json")
.then(function() { return storage.init(runtime)}) .then(function() { return storage.init(runtime)})
.then(function() { return settings.load(storage)}) .then(function() { return settings.load(storage)})
.then(function() { return library.init(runtime)})
.then(function() { .then(function() {
if (log.metric()) { if (log.metric()) {

View File

@ -95,7 +95,11 @@ function getEntry(type,path) {
} }
module.exports = { module.exports = {
name: '_examples_', id: "examples",
label: "editor:library.types.examples",
icon: "font-awesome/fa-life-ring",
types: ["flows"],
readOnly: true,
init: init, init: init,
getEntry: getEntry getEntry: getEntry
} }

View File

@ -15,23 +15,81 @@
**/ **/
var knownTypes = {}; const {events,log} = require("@node-red/util")
const knownTypes = {};
const libraries = {};
const libraryConfigs = {};
const libraryPlugins = {};
var libraries = {}; // Libraries defined in the settings file. Their configurations
// cannot be modified in the editor.
let runtimeLibraries = [];
// Libraries defined by the user in the editor.
let userLibraries = [];
function init(runtime) { let runtime;
knownTypes = {
'flows': 'node-red' function init(_runtime) {
}; runtime = _runtime;
events.removeListener("registry:plugin-added",onPluginAdded);
events.on("registry:plugin-added",onPluginAdded);
knownTypes.flows = 'node-red';
libraries["_examples_"] = require("./examples");
libraries["_examples_"].init(runtime);
libraries["local"] = require("./local"); libraries["local"] = require("./local");
libraries["local"].init(runtime); libraries["local"].init(runtime);
libraryConfigs["local"] = libraries["local"]
libraries["examples"] = require("./examples");
libraries["examples"].init(runtime);
libraryConfigs["examples"] = libraries["examples"]
try {
runtimeLibraries = runtime.settings.editorTheme.library.sources;
} catch(err) {
runtimeLibraries = [];
}
// userLibraries = runtime.settings.get("library")
} }
function onPluginAdded(id) {
const plugin = runtime.plugins.getPlugin(id);
if (plugin.type === "node-red-library-source") {
libraryPlugins[plugin.id] = plugin;
runtimeLibraries.forEach(library => {
if (library.type === id) {
library.local = false;
if (!/^[a-z0-9-_]+$/.test(library.id)) {
log.warn(log._("library.failedToInit",{error:log._("library.invalidProperty",{prop:"id",value:library.id})}));
return;
}
try {
libraries[library.id] = new plugin.class(library)
libraryConfigs[library.id] = library;
libraryConfigs[library.id].type = id;
if (libraries[library.id].init) {
libraries[library.id].init().catch(err => {
delete libraries[library.id];
delete libraryConfigs[library.id];
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
});
}
} catch(err) {
log.warn(log._("library.failedToInit",{library:library.id, error:err.toString()}));
}
}
})
}
}
function registerType(id,type) { function registerType(id,type) {
// TODO: would like to enforce this, but currently the tests register the same type multiple // TODO: would like to enforce this, but currently the tests register the same type multiple
// times and have no way to remove themselves. // times and have no way to remove themselves.
@ -43,31 +101,82 @@ function registerType(id,type) {
function getEntry(library,type,path) { function getEntry(library,type,path) {
if (!knownTypes.hasOwnProperty(type)) { if (!knownTypes.hasOwnProperty(type)) {
throw new Error(`Unknown library type '${type}'`); throw new Error(log._("library.unknownType",{type: type}))
} }
if (libraries.hasOwnProperty(library)) { if (libraries.hasOwnProperty(library)) {
return libraries[library].getEntry(type,path); return libraries[library].getEntry(type,path);
} else { } else {
throw new Error(`Unknown library '${library}'`); throw new Error(log._("library.unknownLibrary",{library: library}))
} }
} }
function saveEntry(library,type,path,meta,body) { function saveEntry(library,type,path,meta,body) {
if (!knownTypes.hasOwnProperty(type)) { if (!knownTypes.hasOwnProperty(type)) {
throw new Error(`Unknown library type '${type}'`); throw new Error(log._("library.unknownType",{type: type}))
} }
if (libraries.hasOwnProperty(library)) { if (libraries.hasOwnProperty(library)) {
if (libraries[library].hasOwnProperty("saveEntry")) { if (libraries[library].saveEntry) {
return libraries[library].saveEntry(type,path,meta,body); return libraries[library].saveEntry(type,path,meta,body);
} else { } else {
throw new Error(`Library '${library}' is read-only`); throw new Error(log._("library.readOnly",{library: library}))
} }
} else { } else {
throw new Error(`Unknown library '${library}'`); throw new Error(log._("library.unknownLibrary",{library: library}))
} }
} }
function getLibraries() {
const libraryList = []
for (let id in libraries) {
if (libraries.hasOwnProperty(id)) {
var config = getConfig(id);
// Don't include the full configuration of each library when providing
// the list of all libraries
delete config.config;
libraryList.push(config);
}
}
return libraryList;
}
function getConfig(id) {
var lib = {
id: id,
label: libraryConfigs[id].label || id,
user: false,
icon: libraryConfigs[id].icon
}
if (libraryConfigs[id].types) {
lib.types = libraryConfigs[id].types
}
if (libraryConfigs[id].readOnly) {
lib.readOnly = libraryConfigs[id].readOnly
}
if (libraryConfigs[id].type) {
lib.type = libraryConfigs[id].type;
var def = libraryPlugins[lib.type];
if (def && def.defaults) {
lib.config = {};
for (var d in def.defaults) {
if (def.defaults.hasOwnProperty(d)) {
if (def.defaults[d].type !== 'password') {
lib.config[d] = libraryConfigs[id][d];
} else if (!!libraryConfigs[id][d]) {
lib.config["has_"+d] = true;
}
}
}
}
}
return lib;
}
module.exports = { module.exports = {
init: init, init: init,
getLibraries: getLibraries,
// getConfig: getConfig,
register: registerType, register: registerType,
getEntry: getEntry, getEntry: getEntry,
saveEntry: saveEntry saveEntry: saveEntry

View File

@ -30,7 +30,9 @@ function saveEntry(type,path,meta,body) {
} }
module.exports = { module.exports = {
name: 'local', id: "local",
label: "editor:library.types.local",
icon: "font-awesome/fa-hdd-o",
init: init, init: init,
getEntry: getEntry, getEntry: getEntry,
saveEntry: saveEntry saveEntry: saveEntry

View File

@ -7,4 +7,5 @@ module.exports = {
getPluginsByType: registry.getPluginsByType, getPluginsByType: registry.getPluginsByType,
getPluginList: registry.getPluginList, getPluginList: registry.getPluginList,
getPluginConfigs: registry.getPluginConfigs, getPluginConfigs: registry.getPluginConfigs,
exportPluginSettings: registry.exportPluginSettings
} }

View File

@ -89,7 +89,13 @@
"not-available": "Settings not available", "not-available": "Settings not available",
"property-read-only": "Property '__prop__' is read-only" "property-read-only": "Property '__prop__' is read-only"
}, },
"library": {
"unknownLibrary": "Unknown library: __library__",
"unknownType": "Unknown library type: __type__",
"readOnly": "Library __library__ is read-only",
"failedToInit": "Failed to initialise library __library__: __error__",
"invalidProperty": "Invalid property __prop__: '__value__'"
},
"nodes": { "nodes": {
"credentials": { "credentials": {
"error":"Error loading credentials: __message__", "error":"Error loading credentials: __message__",

View File

@ -0,0 +1,22 @@
<script type="text/javascript">
RED.plugins.registerPlugin("node-red-library-filestore", {
type: "node-red-library-source",
name: "Local File-System Library",
icon: "font-awesome/fa-hdd-o",
defaults: {
path: { value: ""},
// secret: { type: "password" }
}
})
RED.plugins.registerPlugin("node-red-library-dbstore", {
type: "node-red-library-source",
name: "Database Library",
icon: "font-awesome/fa-database",
defaults: {
connection: { value: ""}
}
})
</script>

View File

@ -0,0 +1,37 @@
module.exports = function(RED) {
const PLUGIN_TYPE_ID = "node-red-library-filestore";
class FileStorePlugin {
constructor(config) {
this.type = PLUGIN_TYPE_ID;
this.id = config.id;
this.label = config.label;
this.config = config.config;
this.icon = config.icon;
console.log("FileStorePlugin",config)
}
async init() {
console.log("FileStorePlugin.init")
}
async getEntry(type,path) {
console.log("FileStorePlugin.getLibraryEntry",type,path)
return []
}
async saveEntry(type,path,meta,body) {
console.log("FileStorePlugin.saveLibraryEntry",type,path)
}
}
RED.plugins.registerPlugin(PLUGIN_TYPE_ID, {
type: "node-red-library-source",
class: FileStorePlugin,
defaults: {
"path": { value: "" },
// "secret": { type: "password" }
}
})
}

View File

@ -0,0 +1,8 @@
{
"label": {
"path": "Path"
},
"desc": {
"path":"The local file-system path to the library"
}
}

View File

@ -6,7 +6,8 @@
"plugins": { "plugins": {
"test": "test.js", "test": "test.js",
"test-editor-plugin": "test-editor-plugin.html", "test-editor-plugin": "test-editor-plugin.html",
"test-runtime-plugin": "test-runtime-plugin.js" "test-runtime-plugin": "test-runtime-plugin.js",
"library-filestore": "library-filestore.js"
} }
} }
} }

View File

@ -44,6 +44,11 @@ describe("runtime-api/settings", function() {
paletteCategories :["red","blue","green"], paletteCategories :["red","blue","green"],
exportNodeSettings: (obj) => { exportNodeSettings: (obj) => {
obj.testNodeSetting = "helloWorld"; obj.testNodeSetting = "helloWorld";
},
},
plugins: {
exportPluginSettings: (obj) => {
obj.testPluginSettings = "helloPluginWorld";
} }
}, },
nodes: { nodes: {
@ -51,13 +56,16 @@ describe("runtime-api/settings", function() {
installerEnabled: () => false, installerEnabled: () => false,
getCredentialKeyType: () => "test-key-type" getCredentialKeyType: () => "test-key-type"
}, },
library: {getLibraries: () => ["lib1"] },
storage: {} storage: {}
}) })
return settings.getRuntimeSettings({}).then(result => { return settings.getRuntimeSettings({}).then(result => {
result.should.have.property("httpNodeRoot","testHttpNodeRoot"); result.should.have.property("httpNodeRoot","testHttpNodeRoot");
result.should.have.property("version","testVersion"); result.should.have.property("version","testVersion");
result.should.have.property("paletteCategories",["red","blue","green"]); result.should.have.property("paletteCategories",["red","blue","green"]);
result.should.have.property("libraries",["lib1"]);
result.should.have.property("testNodeSetting","helloWorld"); result.should.have.property("testNodeSetting","helloWorld");
result.should.have.property("testPluginSettings","helloPluginWorld");
result.should.not.have.property("foo",123); result.should.not.have.property("foo",123);
result.should.have.property("flowEncryptionType","test-key-type"); result.should.have.property("flowEncryptionType","test-key-type");
result.should.not.have.property("user"); result.should.not.have.property("user");
@ -75,6 +83,11 @@ describe("runtime-api/settings", function() {
paletteCategories :["red","blue","green"], paletteCategories :["red","blue","green"],
exportNodeSettings: (obj) => { exportNodeSettings: (obj) => {
obj.testNodeSetting = "helloWorld"; obj.testNodeSetting = "helloWorld";
},
},
plugins: {
exportPluginSettings: (obj) => {
obj.testPluginSettings = "helloPluginWorld";
} }
}, },
nodes: { nodes: {
@ -82,6 +95,7 @@ describe("runtime-api/settings", function() {
installerEnabled: () => false, installerEnabled: () => false,
getCredentialKeyType: () => "test-key-type" getCredentialKeyType: () => "test-key-type"
}, },
library: {getLibraries: () => { ["lib1"]} },
storage: {} storage: {}
}) })
return settings.getRuntimeSettings({ return settings.getRuntimeSettings({
@ -111,6 +125,11 @@ describe("runtime-api/settings", function() {
paletteCategories :["red","blue","green"], paletteCategories :["red","blue","green"],
exportNodeSettings: (obj) => { exportNodeSettings: (obj) => {
obj.testNodeSetting = "helloWorld"; obj.testNodeSetting = "helloWorld";
},
},
plugins: {
exportPluginSettings: (obj) => {
obj.testPluginSettings = "helloPluginWorld";
} }
}, },
nodes: { nodes: {
@ -118,6 +137,7 @@ describe("runtime-api/settings", function() {
installerEnabled: () => false, installerEnabled: () => false,
getCredentialKeyType: () => "test-key-type" getCredentialKeyType: () => "test-key-type"
}, },
library: {getLibraries: () => { ["lib1"]} },
storage: { storage: {
projects: { projects: {
getActiveProject: () => 'test-active-project', getActiveProject: () => 'test-active-project',
@ -162,6 +182,11 @@ describe("runtime-api/settings", function() {
paletteCategories :["red","blue","green"], paletteCategories :["red","blue","green"],
exportNodeSettings: (obj) => { exportNodeSettings: (obj) => {
obj.testNodeSetting = "helloWorld"; obj.testNodeSetting = "helloWorld";
},
},
plugins: {
exportPluginSettings: (obj) => {
obj.testPluginSettings = "helloPluginWorld";
} }
}, },
nodes: { nodes: {
@ -169,6 +194,7 @@ describe("runtime-api/settings", function() {
installerEnabled: () => false, installerEnabled: () => false,
getCredentialKeyType: () => "test-key-type" getCredentialKeyType: () => "test-key-type"
}, },
library: {getLibraries: () => { ["lib1"]} },
storage: { storage: {
projects: { projects: {
getActiveProject: () => 'test-active-project', getActiveProject: () => 'test-active-project',
@ -203,6 +229,11 @@ describe("runtime-api/settings", function() {
paletteCategories :["red","blue","green"], paletteCategories :["red","blue","green"],
exportNodeSettings: (obj) => { exportNodeSettings: (obj) => {
obj.testNodeSetting = "helloWorld"; obj.testNodeSetting = "helloWorld";
},
},
plugins: {
exportPluginSettings: (obj) => {
obj.testPluginSettings = "helloPluginWorld";
} }
}, },
nodes: { nodes: {
@ -210,6 +241,7 @@ describe("runtime-api/settings", function() {
installerEnabled: () => false, installerEnabled: () => false,
getCredentialKeyType: () => "test-key-type" getCredentialKeyType: () => "test-key-type"
}, },
library: {getLibraries: () => { ["lib1"]} },
storage: { storage: {
projects: { projects: {
flowFileExists: () => true, flowFileExists: () => true,
@ -248,6 +280,11 @@ describe("runtime-api/settings", function() {
paletteCategories :["red","blue","green"], paletteCategories :["red","blue","green"],
exportNodeSettings: (obj) => { exportNodeSettings: (obj) => {
obj.testNodeSetting = "helloWorld"; obj.testNodeSetting = "helloWorld";
},
},
plugins: {
exportPluginSettings: (obj) => {
obj.testPluginSettings = "helloPluginWorld";
} }
}, },
nodes: { nodes: {
@ -255,6 +292,7 @@ describe("runtime-api/settings", function() {
installerEnabled: () => false, installerEnabled: () => false,
getCredentialKeyType: () => "test-key-type" getCredentialKeyType: () => "test-key-type"
}, },
library: {getLibraries: () => { ["lib1"]} },
storage: { storage: {
projects: { projects: {
flowFileExists: () => false, flowFileExists: () => false,

View File

@ -14,13 +14,14 @@
* limitations under the License. * limitations under the License.
**/ **/
var should = require("should"); const should = require("should");
var sinon = require("sinon"); const sinon = require("sinon");
var NR_TEST_UTILS = require("nr-test-utils"); const NR_TEST_UTILS = require("nr-test-utils");
var library = NR_TEST_UTILS.require("@node-red/runtime/lib/library/index") const library = NR_TEST_UTILS.require("@node-red/runtime/lib/library/index")
var localLibrary = NR_TEST_UTILS.require("@node-red/runtime/lib/library/local") const localLibrary = NR_TEST_UTILS.require("@node-red/runtime/lib/library/local")
var examplesLibrary = NR_TEST_UTILS.require("@node-red/runtime/lib/library/examples") const examplesLibrary = NR_TEST_UTILS.require("@node-red/runtime/lib/library/examples")
const events = NR_TEST_UTILS.require("@node-red/util/lib/events")
var mockLog = { var mockLog = {
log: sinon.stub(), log: sinon.stub(),
@ -72,6 +73,59 @@ describe("runtime/library", function() {
// should(()=>{library.register("unknown","/abc")} ).throw(); // should(()=>{library.register("unknown","/abc")} ).throw();
// }) // })
}) })
describe("getLibraries", function() {
before(function() {
library.init({});
});
it('returns the default and examples libraries', function() {
const libs = library.getLibraries();
libs.should.have.length(2);
libs[0].should.have.property('id', 'local');
libs[0].should.have.property('label','editor:library.types.local');
libs[0].should.have.property("user", false);
libs[0].should.have.property('icon', 'font-awesome/fa-hdd-o');
libs[1].should.have.property('id', 'examples');
libs[1].should.have.property('label','editor:library.types.examples');
libs[1].should.have.property("user", false);
libs[1].should.have.property('icon', 'font-awesome/fa-life-ring');
libs[1].should.have.property('readOnly', true);
libs[1].should.have.property('types', ['flows']);
});
it('returns the libraries from settings', function() {
library.init({
plugins: {
getPlugin: id => { return {
id: "test-library-plugin",
type: "node-red-library-source",
class: function() {}
}
}
},
settings: {
editorTheme: {
library: {
sources: [
{id: "test-plugin-id", type:"test-library-plugin"}
]
}
}
}
});
let libs = library.getLibraries();
libs.should.have.length(2);
events.emit("registry:plugin-added","test-library-plugin" )
libs = library.getLibraries();
libs.should.have.length(3);
libs[2].should.have.property('id', 'test-plugin-id');
libs[2].should.have.property("user", false);
});
})
describe("getEntry", function() { describe("getEntry", function() {
before(function() { before(function() {
library.init({}); library.init({});
@ -102,7 +156,7 @@ describe("runtime/library", function() {
}); });
it ('returns a flow example entry', function(done) { it ('returns a flow example entry', function(done) {
library.getEntry("_examples_","flows","/test-module/abc").then(function(result) { library.getEntry("examples","flows","/test-module/abc").then(function(result) {
result.should.have.property("library","_examples_") result.should.have.property("library","_examples_")
result.should.have.property("path","/test-module/abc") result.should.have.property("path","/test-module/abc")
done(); done();