Skip to content
Snippets Groups Projects
Commit eef9fb5d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

plugins loaded few times have few entries in plugin dialog

parent 996f1e2d
No related branches found
No related tags found
1 merge request!140Plugin framework fixes
Pipeline #
"use strict";
var Promise = require('bluebird');
var AbstractGuiElement = require('./AbstractGuiElement');
var GuiConnector = require('../GuiConnector');
var GuiUtils = require('./leftPanel/GuiUtils');
......@@ -56,12 +53,10 @@ PluginDialog.prototype._createPluginGui = function () {
var pluginManager = self.getPluginManager();
var loadedPlugins = [];
var processedPlugins = [];
var plugins = pluginManager.getPlugins();
var i;
for (i = 0; i < plugins.length; i++) {
loadedPlugins[plugins[i].getOptions().url] = true;
processedPlugins[plugins[i].getOptions().url] = false;
}
for (i = 0; i < self._knownPlugins.length; i++) {
......@@ -75,23 +70,7 @@ PluginDialog.prototype._createPluginGui = function () {
});
pluginUrl.readOnly = true;
var button;
if (loadedPlugins[url]) {
button = Functions.createElement({
type: "button",
content: "UNLOAD",
onclick: function () {
var promises = [];
for (var i = 0; i < plugins.length; i++) {
if (plugins[i].getOptions().url === $(this).data("url")) {
promises.push(pluginManager.removePlugin(plugins[i]));
}
}
return Promise.all(promises).then(function () {
self.close();
}).then(null, GuiConnector.alert);
}
});
} else {
if (!loadedPlugins[url]) {
button = Functions.createElement({
type: "button",
content: "LOAD",
......@@ -103,39 +82,33 @@ PluginDialog.prototype._createPluginGui = function () {
});
}
$(button).data("url", url);
processedPlugins[url] = true;
pluginFormTab.appendChild(guiUtils.createTableRow([Functions.createElement({type: "span"}), pluginUrl, button]));
}
for (url in loadedPlugins) {
if (loadedPlugins.hasOwnProperty(url) && !processedPlugins[url]) {
pluginUrl = Functions.createElement({
type: "input",
value: url,
style: "color:#999999"
});
pluginUrl.readOnly = true;
button = Functions.createElement({
type: "button",
content: "UNLOAD",
onclick: function () {
var promises = [];
for (var i = 0; i < plugins.length; i++) {
if (plugins[i].getOptions().url === $(this).data("url")) {
promises.push(pluginManager.removePlugin(plugins[i]));
}
}
return Promise.all(promises).then(function () {
self.close();
}).then(null, GuiConnector.alert);
}
});
$(button).data("url", url);
for (i = 0; i < plugins.length; i++) {
var plugin = plugins[i];
var removePlugin = (function () {
var pluginToRemove = plugin;
return function () {
return pluginManager.removePlugin(pluginToRemove).then(function () {
self.close();
}).then(null, GuiConnector.alert);
}
})();
pluginUrl = Functions.createElement({
type: "input",
value: plugins[i].getOptions().url,
style: "color:#999999"
});
pluginUrl.readOnly = true;
button = Functions.createElement({
type: "button",
content: "UNLOAD",
onclick: removePlugin
});
pluginFormTab.appendChild(guiUtils.createTableRow([Functions.createElement({type: "span"}), pluginUrl, button]));
pluginFormTab.appendChild(guiUtils.createTableRow([Functions.createElement({type: "span"}), pluginUrl, button]));
}
}
};
......@@ -173,8 +146,8 @@ PluginDialog.prototype.close = function () {
PluginDialog.prototype.destroy = function () {
var self = this;
var div = self.getElement();
if ($(self.getElement()).hasClass("ui-dialog-content")) {
$(self.getElement()).dialog("destroy");
if ($(div).hasClass("ui-dialog-content")) {
$(div).dialog("destroy");
}
};
......
......@@ -47,5 +47,4 @@ describe('OptionsMenu', function () {
return pluginManager.destroy();
});
});
})
;
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment