Commit e785b1fb authored by Piotr Gawron's avatar Piotr Gawron
Browse files

admin can mark plugin as default or not

parent e74d5784
......@@ -1394,6 +1394,25 @@ ServerConnector.removePlugin = function (params) {
return self.sendDeleteRequest(self.getPluginUrl(params));
};
/**
*
* @param {Object} params
* @param {string} params.hash
* @param {boolean} [params.isDefault]
*
* @returns {Promise<PluginData[]>}
*/
ServerConnector.updatePlugin = function (params) {
var self = this;
var content = {
plugin: {
hash: params.hash,
isDefault: params.isDefault
}
};
return self.sendPatchRequest(self.getPluginUrl(params), content);
};
/**
*
* @param {string} login
......
......@@ -63,6 +63,8 @@ PluginAdminPanel.prototype._createGui = function () {
title: 'Version'
}, {
title: 'Url'
}, {
title: 'Default'
}, {
title: 'Remove',
orderable: false
......@@ -89,6 +91,14 @@ PluginAdminPanel.prototype._createGui = function () {
}).catch(GuiConnector.alert);
});
$(pluginsTable).on("click", "[name='edit-default-plugin']", function () {
var checkbox = this;
var hash = $(this).attr("data");
return self.getServerConnector().updatePlugin({hash: hash, isDefault: $(checkbox).is(':checked')}).then(function () {
return self.onRefreshClicked();
}).catch(GuiConnector.alert);
});
pluginDiv.appendChild(self._createMenuRow());
};
......@@ -196,7 +206,14 @@ PluginAdminPanel.prototype.pluginToTableRow = function (plugin) {
row[0] = plugin.getName();
row[1] = plugin.getVersion();
row[2] = plugin.getUrls();
row[3] = "<button name='removePlugin' data='" + plugin.getHash() + "' ><i class='fa fa-trash-alt'></button>";
var checked = "";
if (plugin.isDefault()) {
checked = " checked ";
}
row[3] = "<input type='checkbox' name='edit-default-plugin' " + checked + " data='" + plugin.getHash() + "' />";
row[4] = "<button name='removePlugin' data='" + plugin.getHash() + "' ><i class='fa fa-trash-alt'></button>";
return row;
};
......
......@@ -10,6 +10,7 @@ var Functions = require('../../Functions');
* @param {string} params.name
* @param {string} params.version
* @param {boolean} [params.isPublic=false]
* @param {boolean} [params.isDefault=false]
* @constructor
*/
function PluginData(params) {
......@@ -17,6 +18,7 @@ function PluginData(params) {
this.setUrls(params.urls);
this.setName(params.name);
this.setPublic(params.isPublic);
this.setDefault(params.isDefault);
this.setVersion(params.version);
}
......@@ -38,16 +40,25 @@ PluginData.prototype.getHash = function () {
/**
*
* @param {string|boolean} isPublic
* @param {?null|string|boolean} value
* @return {boolean}
*/
PluginData.prototype.setPublic = function (isPublic) {
if (isPublic === null || isPublic === undefined) {
this._public = false;
} else if (Functions.isString(isPublic)) {
this._public = (isPublic === "true");
function getBooleanValue(value) {
if (value === null || value === undefined) {
return false;
} else if (Functions.isString(value)) {
return (value === "true");
} else {
this._public = isPublic;
return value;
}
}
/**
*
* @param {?null|string|boolean} isPublic
*/
PluginData.prototype.setPublic = function (isPublic) {
this._public = getBooleanValue(isPublic);
};
/**
......@@ -58,6 +69,22 @@ PluginData.prototype.isPublic = function () {
return this._public;
};
/**
*
* @param {?null|string|boolean} isDefault
*/
PluginData.prototype.setDefault = function (isDefault) {
this._default = getBooleanValue(isDefault);
};
/**
*
* @returns {boolean}
*/
PluginData.prototype.isDefault = function () {
return this._default;
};
/**
*
* @param {string[]} urls
......
......@@ -64,6 +64,7 @@ public class PluginRestImpl extends BaseRestImpl {
result.put("name", plugin.getName());
result.put("version", plugin.getVersion());
result.put("isPublic", plugin.isPublic());
result.put("isDefault", plugin.isDefault());
List<String> urls = new ArrayList<>(plugin.getUrls());
Collections.sort(urls);
result.put("urls", urls);
......
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