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

Merge branch '495-error-at-plugin-load' into 'devel_12.1.x'

Resolve "Error at plugin load leaves an empty left panel"

See merge request !403
parents 92e8bb33 09ff0ed8
No related branches found
No related tags found
2 merge requests!412changes from 12.1.0~beta.1 into master,!403Resolve "Error at plugin load leaves an empty left panel"
Pipeline #6416 passed
......@@ -181,12 +181,21 @@ Plugin.prototype.getMinWidth = function () {
*/
Plugin.prototype.unload = function () {
var self = this;
var validPlugin = true;
if (self.getLoadedPluginData() === undefined) {
validPlugin = false;
logger.warn("Plugin wasn't loaded properly");
}
return Promise.resolve().then(function () {
return self.getLoadedPluginData().unregister();
if (validPlugin) {
return self.getLoadedPluginData().unregister();
}
}).then(function () {
var removedListeners = self.getMinervaPluginProxy().project.map.removeAllListeners();
if (removedListeners.length > 0) {
logger.warn("'" + self.getLoadedPluginData().getName() + "' plugin didn't remove all registered listeners");
if (validPlugin) {
var removedListeners = self.getMinervaPluginProxy().project.map.removeAllListeners();
if (removedListeners.length > 0) {
logger.warn("'" + self.getLoadedPluginData().getName() + "' plugin didn't remove all registered listeners");
}
}
return self.callListeners("onUnload");
}).then(function () {
......
......@@ -70,8 +70,8 @@ PluginManager.prototype.getGuiUtils = function () {
*/
PluginManager.prototype.addPlugin = function (options) {
var self = this;
$(self.getElement()).show();
if (self._panels === undefined) {
$(self.getElement()).show();
self.getGuiUtils().initTabContent(self);
}
var element = Functions.createElement({type: "div"});
......@@ -79,31 +79,36 @@ PluginManager.prototype.addPlugin = function (options) {
self.getGuiUtils().addTab(self, {name: "PLUGIN", content: element});
var plugin;
if (options instanceof Plugin) {
plugin = options;
plugin.setOptions({
element: element,
configuration: self.getConfiguration(),
map: self.getMap(),
serverConnector: self.getServerConnector()
});
} else {
if (!self.isValidUrl(options.url)) {
return Promise.reject(new InvalidArgumentError("url: '" + options.url + "' is invalid"));
return Promise.resolve().then(function () {
if (options instanceof Plugin) {
plugin = options;
plugin.setOptions({
element: element,
configuration: self.getConfiguration(),
map: self.getMap(),
serverConnector: self.getServerConnector()
});
} else {
plugin = new Plugin({
url: options.url,
element: element,
configuration: self.getConfiguration(),
map: self.getMap(),
serverConnector: self.getServerConnector()
});
plugin.addListener("onUnload", function () {
self.getGuiUtils().hideTab(self, element);
if ($("li", self.getElement()).children(':visible').length === 0) {
$(self.getElement()).hide();
}
});
if (!self.isValidUrl(options.url)) {
return Promise.reject(new InvalidArgumentError("url: '" + options.url + "' is invalid"));
}
}
plugin = new Plugin({
url: options.url,
element: element,
configuration: self.getConfiguration(),
map: self.getMap(),
serverConnector: self.getServerConnector()
});
plugin.addListener("onUnload", function () {
self.getGuiUtils().hideTab(self, element);
});
}
self._plugins.push(plugin);
return plugin.load().then(function () {
self._plugins.push(plugin);
return plugin.load();
}).then(function () {
$("a[href='#" + element.parentNode.id + "']", $(self.getElement()))[0].innerHTML = plugin.getName();
var tab = $(element.parentNode);
var adjustHeight = function () {
......@@ -120,6 +125,10 @@ PluginManager.prototype.addPlugin = function (options) {
}
}).then(function () {
return plugin;
}).catch(function (e) {
return plugin.unload().then(function () {
GuiConnector.alert("Problem with loading plugin:<br/>" + e.message);
});
});
};
......
......@@ -77,6 +77,26 @@ describe('PluginManager', function () {
});
});
it('with error', function () {
var manager = createPluginManager();
return manager.addPlugin({url: "./invalid.js"}).then(function (plugin) {
assert.notOk("Expected error");
}).catch(function (e) {
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0)
});
});
it('with invalid url', function () {
var manager = createPluginManager();
manager.isValidUrl = function () {
return false;
};
return manager.addPlugin({url: "xx"}).then(function (plugin) {
assert.notOk("Expected error");
}).catch(function (e) {
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0)
});
});
});
......
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