mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Initial plugin runtime api implementation
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
}
|
||||
},
|
||||
"event": {
|
||||
"loadPlugins": "Loading Plugins",
|
||||
"loadPalette": "Loading Palette",
|
||||
"loadNodeCatalogs": "Loading Node catalogs",
|
||||
"loadNodes": "Loading Nodes __count__",
|
||||
|
@@ -108,6 +108,31 @@ RED.i18n = (function() {
|
||||
}
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
loadPluginCatalogs: function(done) {
|
||||
var languageList = i18n.functions.toLanguages(localStorage.getItem("editor-language")||i18n.detectLanguage());
|
||||
var toLoad = languageList.length;
|
||||
|
||||
languageList.forEach(function(lang) {
|
||||
$.ajax({
|
||||
headers: {
|
||||
"Accept":"application/json"
|
||||
},
|
||||
cache: false,
|
||||
url: apiRootUrl+'plugins/messages?lng='+lang,
|
||||
success: function(data) {
|
||||
var namespaces = Object.keys(data);
|
||||
namespaces.forEach(function(ns) {
|
||||
i18n.addResourceBundle(lang,ns,data[ns]);
|
||||
});
|
||||
toLoad--;
|
||||
if (toLoad === 0) {
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
@@ -15,19 +15,66 @@
|
||||
**/
|
||||
var RED = (function() {
|
||||
|
||||
function appendNodeConfig(nodeConfig,done) {
|
||||
|
||||
function loadPluginList() {
|
||||
loader.reportProgress(RED._("event.loadPlugins"), 10)
|
||||
$.ajax({
|
||||
headers: {
|
||||
"Accept":"application/json"
|
||||
},
|
||||
cache: false,
|
||||
url: 'plugins',
|
||||
success: function(data) {
|
||||
console.log(data);
|
||||
loader.reportProgress(RED._("event.loadPlugins"), 13)
|
||||
RED.i18n.loadPluginCatalogs(function() {
|
||||
loadPlugins(function() {
|
||||
loadNodeList();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function loadPlugins(done) {
|
||||
loader.reportProgress(RED._("event.loadPlugins",{count:""}), 17)
|
||||
var lang = localStorage.getItem("editor-language")||i18n.detectLanguage();
|
||||
|
||||
$.ajax({
|
||||
headers: {
|
||||
"Accept":"text/html",
|
||||
"Accept-Language": lang
|
||||
},
|
||||
cache: false,
|
||||
url: 'plugins',
|
||||
success: function(data) {
|
||||
var configs = data.trim().split(/(?=<!-- --- \[red-plugin:\S+\] --- -->)/);
|
||||
var totalCount = configs.length;
|
||||
var stepConfig = function() {
|
||||
// loader.reportProgress(RED._("event.loadNodes",{count:(totalCount-configs.length)+"/"+totalCount}), 30 + ((totalCount-configs.length)/totalCount)*40 )
|
||||
if (configs.length === 0) {
|
||||
done();
|
||||
} else {
|
||||
var config = configs.shift();
|
||||
appendPluginConfig(config,stepConfig);
|
||||
}
|
||||
}
|
||||
stepConfig();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function appendConfig(config, moduleIdMatch, targetContainer, done) {
|
||||
done = done || function(){};
|
||||
var m = /<!-- --- \[red-module:(\S+)\] --- -->/.exec(nodeConfig.trim());
|
||||
var moduleId;
|
||||
if (m) {
|
||||
moduleId = m[1];
|
||||
if (moduleIdMatch) {
|
||||
moduleId = moduleIdMatch[1];
|
||||
} else {
|
||||
moduleId = "unknown";
|
||||
}
|
||||
try {
|
||||
var hasDeferred = false;
|
||||
|
||||
var nodeConfigEls = $("<div>"+nodeConfig+"</div>");
|
||||
var hasDeferred = false;
|
||||
var nodeConfigEls = $("<div>"+config+"</div>");
|
||||
var scripts = nodeConfigEls.find("script");
|
||||
var scriptCount = scripts.length;
|
||||
scripts.each(function(i,el) {
|
||||
@@ -38,14 +85,14 @@ var RED = (function() {
|
||||
newScript.onload = function() {
|
||||
scriptCount--;
|
||||
if (scriptCount === 0) {
|
||||
$("#red-ui-editor-node-configs").append(nodeConfigEls);
|
||||
$(targetContainer).append(nodeConfigEls);
|
||||
done()
|
||||
}
|
||||
}
|
||||
if ($(el).attr('type') === "module") {
|
||||
newScript.type = "module";
|
||||
}
|
||||
$("#red-ui-editor-node-configs").append(newScript);
|
||||
$(targetContainer).append(newScript);
|
||||
newScript.src = RED.settings.apiRootUrl+srcUrl;
|
||||
hasDeferred = true;
|
||||
} else {
|
||||
@@ -61,7 +108,7 @@ var RED = (function() {
|
||||
}
|
||||
})
|
||||
if (!hasDeferred) {
|
||||
$("#red-ui-editor-node-configs").append(nodeConfigEls);
|
||||
$(targetContainer).append(nodeConfigEls);
|
||||
done();
|
||||
}
|
||||
} catch(err) {
|
||||
@@ -73,6 +120,23 @@ var RED = (function() {
|
||||
done();
|
||||
}
|
||||
}
|
||||
function appendPluginConfig(pluginConfig,done) {
|
||||
appendConfig(
|
||||
pluginConfig,
|
||||
/<!-- --- \[red-plugin:(\S+)\] --- -->/.exec(pluginConfig.trim()),
|
||||
"#red-ui-editor-plugin-configs",
|
||||
done
|
||||
);
|
||||
}
|
||||
|
||||
function appendNodeConfig(nodeConfig,done) {
|
||||
appendConfig(
|
||||
nodeConfig,
|
||||
/<!-- --- \[red-module:(\S+)\] --- -->/.exec(nodeConfig.trim()),
|
||||
"#red-ui-editor-node-configs",
|
||||
done
|
||||
);
|
||||
}
|
||||
|
||||
function loadNodeList() {
|
||||
loader.reportProgress(RED._("event.loadPalette"), 20)
|
||||
@@ -580,7 +644,7 @@ var RED = (function() {
|
||||
|
||||
RED.actions.add("core:show-about", showAbout);
|
||||
|
||||
loadNodeList();
|
||||
loadPluginList();
|
||||
}
|
||||
|
||||
|
||||
@@ -596,6 +660,7 @@ var RED = (function() {
|
||||
'<div id="red-ui-sidebar"></div>'+
|
||||
'<div id="red-ui-sidebar-separator"></div>'+
|
||||
'</div>').appendTo(options.target);
|
||||
$('<div id="red-ui-editor-plugin-configs"></div>').appendTo(options.target);
|
||||
$('<div id="red-ui-editor-node-configs"></div>').appendTo(options.target);
|
||||
$('<div id="red-ui-full-shade" class="hide"></div>').appendTo(options.target);
|
||||
|
||||
|
Reference in New Issue
Block a user