mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
@@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
46
packages/node_modules/@node-red/editor-client/src/js/plugins.js
vendored
Normal file
46
packages/node_modules/@node-red/editor-client/src/js/plugins.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
RED.plugins = (function() {
|
||||
var plugins = {};
|
||||
var pluginsByType = {};
|
||||
|
||||
function registerPlugin(id,definition) {
|
||||
plugins[id] = definition;
|
||||
if (definition.type) {
|
||||
pluginsByType[definition.type] = pluginsByType[definition.type] || [];
|
||||
pluginsByType[definition.type].push(definition);
|
||||
}
|
||||
if (RED._loadingModule) {
|
||||
definition.module = RED._loadingModule;
|
||||
definition["_"] = function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var originalKey = args[0];
|
||||
if (!/:/.test(args[0])) {
|
||||
args[0] = definition.module+":"+args[0];
|
||||
}
|
||||
var result = RED._.apply(null,args);
|
||||
if (result === args[0]) {
|
||||
return originalKey;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
definition["_"] = RED["_"]
|
||||
}
|
||||
if (definition.onadd && typeof definition.onadd === 'function') {
|
||||
definition.onadd();
|
||||
}
|
||||
RED.events.emit("registry:plugin-added",id);
|
||||
}
|
||||
|
||||
function getPlugin(id) {
|
||||
return plugins[id]
|
||||
}
|
||||
|
||||
function getPluginsByType(type) {
|
||||
return pluginsByType[type] || [];
|
||||
}
|
||||
return {
|
||||
registerPlugin: registerPlugin,
|
||||
getPlugin: getPlugin,
|
||||
getPluginsByType: getPluginsByType
|
||||
}
|
||||
})();
|
@@ -15,19 +15,65 @@
|
||||
**/
|
||||
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) {
|
||||
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];
|
||||
RED._loadingModule = moduleId;
|
||||
} else {
|
||||
moduleId = "unknown";
|
||||
}
|
||||
try {
|
||||
var hasDeferred = false;
|
||||
|
||||
var nodeConfigEls = $("<div>"+nodeConfig+"</div>");
|
||||
var nodeConfigEls = $("<div>"+config+"</div>");
|
||||
var scripts = nodeConfigEls.find("script");
|
||||
var scriptCount = scripts.length;
|
||||
scripts.each(function(i,el) {
|
||||
@@ -38,14 +84,15 @@ var RED = (function() {
|
||||
newScript.onload = function() {
|
||||
scriptCount--;
|
||||
if (scriptCount === 0) {
|
||||
$("#red-ui-editor-node-configs").append(nodeConfigEls);
|
||||
$(targetContainer).append(nodeConfigEls);
|
||||
delete RED._loadingModule;
|
||||
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,8 @@ var RED = (function() {
|
||||
}
|
||||
})
|
||||
if (!hasDeferred) {
|
||||
$("#red-ui-editor-node-configs").append(nodeConfigEls);
|
||||
$(targetContainer).append(nodeConfigEls);
|
||||
delete RED._loadingModule;
|
||||
done();
|
||||
}
|
||||
} catch(err) {
|
||||
@@ -70,9 +118,27 @@ var RED = (function() {
|
||||
timeout: 10000
|
||||
});
|
||||
console.log("["+moduleId+"] "+err.toString());
|
||||
delete RED._loadingModule;
|
||||
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 +646,7 @@ var RED = (function() {
|
||||
|
||||
RED.actions.add("core:show-about", showAbout);
|
||||
|
||||
loadNodeList();
|
||||
loadPluginList();
|
||||
}
|
||||
|
||||
|
||||
@@ -596,6 +662,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