Commit 8febaad4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '672-plugins-in-the-admin-panel' into 'devel_12.2.x'

Resolve "PLUGINS in the admin panel - review"

See merge request minerva/core!623
parents a998165d e1abdbe8
Pipeline #8635 passed with stage
in 9 minutes and 38 seconds
......@@ -123,7 +123,7 @@ PluginDialog.prototype._createPluginGui = function () {
return pluginManager.removePlugin(pluginToRemove).then(function () {
self.close();
}).then(null, GuiConnector.alert);
}
};
})();
pluginUrl = Functions.createElement({
type: "input",
......
......@@ -4,6 +4,8 @@ var Promise = require("bluebird");
var AbstractGuiElement = require('../AbstractGuiElement');
var GuiConnector = require('../../GuiConnector');
var NetworkError = require('../../NetworkError');
var ValidationError = require('../../ValidationError');
var Functions = require('../../Functions');
var PluginData = require('../../map/data/PluginData');
......@@ -89,6 +91,9 @@ AddPluginDialog.prototype.createGui = function () {
$(self.getElement()).on("click", "[name='validateUrl']", function () {
return self.onValidateClicked().catch(GuiConnector.alert);
});
$(self.getElement()).on("input", "[name='pluginUrl']", function () {
$('[name="savePlugin"]', self.getElement()).attr("disabled", true);
});
return self.getElement().appendChild(result);
};
......@@ -167,8 +172,23 @@ AddPluginDialog.prototype.onValidateClicked = function () {
version: pluginRawData.getVersion(),
isPublic: true
}));
return self.getServerConnector().getPluginsData();
}).then(function (plugins) {
for (var i = 0; i < plugins.length; i++) {
var pluginData = plugins[i];
if (pluginData.getUrls().indexOf(url) >= 0) {
throw new ValidationError("Plugin is already registered");
}
}
var saveUserButton = $('[name="savePlugin"]');
saveUserButton.attr("disabled", false);
}).catch(function (e) {
if (e instanceof NetworkError) {
logger.warn(e);
throw new ValidationError("Problem with accessing plugin file (url: '" + url + "')");
} else {
throw e;
}
});
};
......@@ -237,9 +257,18 @@ AddPluginDialog.prototype.open = function () {
height: window.innerHeight / 2
});
}
self.clear();
$(div).dialog("open");
};
AddPluginDialog.prototype.clear = function () {
var self = this;
$("[name='pluginUrl']", self.getElement()).val("");
$("[name='pluginName']", self.getElement()).val("");
$("[name='pluginVersion']", self.getElement()).val("");
$('[name="savePlugin"]', self.getElement()).attr("disabled", true);
};
/**
*
*/
......
......@@ -61,6 +61,32 @@ describe('AddPluginDialog', function () {
});
});
describe('onValidateClicked', function () {
it('invalid file', function () {
helper.loginAsAdmin();
var dialog = createDialog();
return dialog.init().then(function () {
return dialog.onValidateClicked();
}).then(function () {
assert.notOk("error expected");
}).catch(function (e) {
assert.ok(e instanceof ValidationError);
}).finally(function () {
return dialog.destroy();
});
});
it('valid file', function () {
helper.loginAsAdmin();
var dialog = createDialog();
return dialog.init().then(function () {
$("[name='pluginUrl']").val("./testFiles/plugin/empty.js");
return dialog.onValidateClicked();
}).finally(function () {
return dialog.destroy();
});
});
});
})
;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment