mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
fixes #3307
This commit is contained in:
@@ -181,28 +181,32 @@ define('admin/extend/plugins', function() {
|
|||||||
socket.emit('admin.plugins.toggleInstall', {
|
socket.emit('admin.plugins.toggleInstall', {
|
||||||
id: pluginID,
|
id: pluginID,
|
||||||
version: version
|
version: version
|
||||||
}, function(err, status) {
|
}, function(err, pluginData) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.installed) {
|
var targetList = (pluginData.installed ? 'installed' : 'download'),
|
||||||
btn.html('<i class="fa fa-trash-o"></i> Uninstall');
|
otherList = (pluginData.installed ? 'download' : 'installed'),
|
||||||
} else {
|
payload = {};
|
||||||
btn.html('<i class="fa fa-download"></i> Install');
|
|
||||||
}
|
|
||||||
|
|
||||||
activateBtn.toggleClass('hidden', !status.installed);
|
payload[targetList] = pluginData;
|
||||||
|
templates.parse('admin/partials/' + targetList + '_plugin_item', payload, function(html) {
|
||||||
|
var pluginList = $('ul.' + targetList);
|
||||||
|
|
||||||
btn.toggleClass('btn-danger', status.installed)
|
pluginList.append(html);
|
||||||
.toggleClass('btn-success', !status.installed)
|
$('ul.' + otherList).find('li[data-plugin-id="' + pluginID + '"]').slideUp('slow', function() {
|
||||||
.attr('disabled', false)
|
$(this).remove();
|
||||||
.attr('data-installed', status.installed ? 1 : 0);
|
$('html,body').animate({
|
||||||
|
scrollTop: pluginList.find('li').last().offset().top - 48
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
app.alert({
|
app.alert({
|
||||||
alert_id: 'plugin_toggled',
|
alert_id: 'plugin_toggled',
|
||||||
title: 'Plugin ' + (status.installed ? 'Installed' : 'Uninstalled'),
|
title: 'Plugin ' + (pluginData.installed ? 'Installed' : 'Uninstalled'),
|
||||||
message: status.installed ? 'Plugin successfully installed, please activate the plugin.' : 'The plugin has been successfully deactivated and uninstalled.',
|
message: pluginData.installed ? 'Plugin successfully installed, please activate the plugin.' : 'The plugin has been successfully deactivated and uninstalled.',
|
||||||
type: 'info',
|
type: 'info',
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
});
|
});
|
||||||
|
|||||||
131
src/plugins.js
131
src/plugins.js
@@ -164,81 +164,100 @@ var fs = require('fs'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugins.get = function(id, callback) {
|
||||||
|
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins/' + id;
|
||||||
|
console.log(url);
|
||||||
|
|
||||||
|
require('request')(url, {
|
||||||
|
json: true
|
||||||
|
}, function(err, res, body) {
|
||||||
|
Plugins.normalise([body.payload], function(err, normalised) {
|
||||||
|
return callback(err, !err ? normalised[0] : undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Plugins.getAll = function(callback) {
|
Plugins.getAll = function(callback) {
|
||||||
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins?version=' + require('../package.json').version;
|
var url = (nconf.get('registry') || 'https://packages.nodebb.org') + '/api/v1/plugins?version=' + require('../package.json').version;
|
||||||
|
|
||||||
require('request')(url, function(err, res, body) {
|
require('request')(url, {
|
||||||
|
json: true
|
||||||
|
}, function(err, res, body) {
|
||||||
var plugins = [];
|
var plugins = [];
|
||||||
|
|
||||||
try {
|
if (err) {
|
||||||
plugins = JSON.parse(body);
|
|
||||||
} catch(err) {
|
|
||||||
winston.error('Error parsing plugins : ' + err.message);
|
winston.error('Error parsing plugins : ' + err.message);
|
||||||
plugins = [];
|
plugins = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginMap = {};
|
Plugins.normalise(body, callback);
|
||||||
for(var i=0; i<plugins.length; ++i) {
|
});
|
||||||
plugins[i].id = plugins[i].name;
|
};
|
||||||
plugins[i].installed = false;
|
|
||||||
plugins[i].active = false;
|
Plugins.normalise = function(apiReturn, callback) {
|
||||||
plugins[i].url = plugins[i].url ? plugins[i].url : plugins[i].repository ? plugins[i].repository.url : '';
|
var pluginMap = {};
|
||||||
plugins[i].latest = plugins[i].latest;
|
for(var i=0; i<apiReturn.length; ++i) {
|
||||||
pluginMap[plugins[i].name] = plugins[i];
|
apiReturn[i].id = apiReturn[i].name;
|
||||||
|
apiReturn[i].installed = false;
|
||||||
|
apiReturn[i].active = false;
|
||||||
|
apiReturn[i].url = apiReturn[i].url ? apiReturn[i].url : apiReturn[i].repository ? apiReturn[i].repository.url : '';
|
||||||
|
apiReturn[i].latest = apiReturn[i].latest;
|
||||||
|
pluginMap[apiReturn[i].name] = apiReturn[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
Plugins.showInstalled(function(err, installedPlugins) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugins.showInstalled(function(err, installedPlugins) {
|
async.each(installedPlugins, function(plugin, next) {
|
||||||
|
// If it errored out because a package.json or plugin.json couldn't be read, no need to do this stuff
|
||||||
|
if (plugin.error) {
|
||||||
|
pluginMap[plugin.id] = pluginMap[plugin.id] || {};
|
||||||
|
pluginMap[plugin.id].installed = true;
|
||||||
|
pluginMap[plugin.id].error = true;
|
||||||
|
return next();
|
||||||
|
} else if (!pluginMap.hasOwnProperty(plugin.id)) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
pluginMap[plugin.id] = pluginMap[plugin.id] || {};
|
||||||
|
pluginMap[plugin.id].id = pluginMap[plugin.id].id || plugin.id;
|
||||||
|
pluginMap[plugin.id].name = plugin.name || pluginMap[plugin.id].name;
|
||||||
|
pluginMap[plugin.id].description = plugin.description;
|
||||||
|
pluginMap[plugin.id].url = pluginMap[plugin.id].url || plugin.url;
|
||||||
|
pluginMap[plugin.id].installed = true;
|
||||||
|
pluginMap[plugin.id].isTheme = !!plugin.id.match('nodebb-theme-');
|
||||||
|
pluginMap[plugin.id].error = plugin.error || false;
|
||||||
|
pluginMap[plugin.id].active = plugin.active;
|
||||||
|
pluginMap[plugin.id].version = plugin.version;
|
||||||
|
pluginMap[plugin.id].latest = pluginMap[plugin.id].latest || plugin.version;
|
||||||
|
pluginMap[plugin.id].outdated = semver.gt(pluginMap[plugin.id].latest, pluginMap[plugin.id].version);
|
||||||
|
next();
|
||||||
|
}, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.each(installedPlugins, function(plugin, next) {
|
var pluginArray = [];
|
||||||
// If it errored out because a package.json or plugin.json couldn't be read, no need to do this stuff
|
|
||||||
if (plugin.error) {
|
for (var key in pluginMap) {
|
||||||
pluginMap[plugin.id] = pluginMap[plugin.id] || {};
|
if (pluginMap.hasOwnProperty(key)) {
|
||||||
pluginMap[plugin.id].installed = true;
|
pluginArray.push(pluginMap[key]);
|
||||||
pluginMap[plugin.id].error = true;
|
|
||||||
return next();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pluginMap[plugin.id] = pluginMap[plugin.id] || {};
|
pluginArray.sort(function(a, b) {
|
||||||
pluginMap[plugin.id].id = pluginMap[plugin.id].id || plugin.id;
|
if (a.name > b.name ) {
|
||||||
pluginMap[plugin.id].name = plugin.name || pluginMap[plugin.id].name;
|
return 1;
|
||||||
pluginMap[plugin.id].description = plugin.description;
|
} else if (a.name < b.name ){
|
||||||
pluginMap[plugin.id].url = pluginMap[plugin.id].url || plugin.url;
|
return -1;
|
||||||
pluginMap[plugin.id].installed = true;
|
} else {
|
||||||
pluginMap[plugin.id].isTheme = !!plugin.id.match('nodebb-theme-');
|
return 0;
|
||||||
pluginMap[plugin.id].error = plugin.error || false;
|
|
||||||
pluginMap[plugin.id].active = plugin.active;
|
|
||||||
pluginMap[plugin.id].version = plugin.version;
|
|
||||||
pluginMap[plugin.id].latest = pluginMap[plugin.id].latest || plugin.version;
|
|
||||||
pluginMap[plugin.id].outdated = semver.gt(pluginMap[plugin.id].latest, pluginMap[plugin.id].version);
|
|
||||||
next();
|
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginArray = [];
|
|
||||||
|
|
||||||
for (var key in pluginMap) {
|
|
||||||
if (pluginMap.hasOwnProperty(key)) {
|
|
||||||
pluginArray.push(pluginMap[key]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pluginArray.sort(function(a, b) {
|
|
||||||
if (a.name > b.name ) {
|
|
||||||
return 1;
|
|
||||||
} else if (a.name < b.name ){
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
callback(null, pluginArray);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
callback(null, pluginArray);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -96,8 +96,11 @@ module.exports = function(Plugins) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
Plugins.fireHook('action:plugin.' + type, id);
|
|
||||||
callback(null, {id: id, installed: !installed});
|
Plugins.get(id, function(err, pluginData) {
|
||||||
|
Plugins.fireHook('action:plugin.' + type, id);
|
||||||
|
callback(null, pluginData);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading"><i class="fa fa-code-fork"></i> Installed Plugins</div>
|
<div class="panel-heading"><i class="fa fa-code-fork"></i> Installed Plugins</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<ul>
|
<ul class="installed">
|
||||||
<!-- BEGIN installed -->
|
<!-- BEGIN installed -->
|
||||||
<!-- IMPORT admin/partials/installed_plugin_item.tpl -->
|
<!-- IMPORT admin/partials/installed_plugin_item.tpl -->
|
||||||
<!-- END installed -->
|
<!-- END installed -->
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading"><i class="fa fa-code-fork"></i> Download Plugins</div>
|
<div class="panel-heading"><i class="fa fa-code-fork"></i> Download Plugins</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<ul>
|
<ul class="download">
|
||||||
<!-- BEGIN download -->
|
<!-- BEGIN download -->
|
||||||
<!-- IMPORT admin/partials/download_plugin_item.tpl -->
|
<!-- IMPORT admin/partials/download_plugin_item.tpl -->
|
||||||
<!-- END download -->
|
<!-- END download -->
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<li data-plugin-id="{download.id}" class="clearfix">
|
<li id="{download.id}" data-plugin-id="{download.id}" class="clearfix">
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<button data-action="toggleActive" class="btn btn-success hidden"><i class="fa fa-power-off"></i> Activate</button>
|
<button data-action="toggleActive" class="btn btn-success hidden"><i class="fa fa-power-off"></i> Activate</button>
|
||||||
<button data-action="toggleInstall" data-installed="0" class="btn btn-success"><i class="fa fa-download"></i> Install</button>
|
<button data-action="toggleInstall" data-installed="0" class="btn btn-success"><i class="fa fa-download"></i> Install</button>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!-- IF !installed.error -->
|
<!-- IF !installed.error -->
|
||||||
<li data-plugin-id="{installed.id}" data-version="{installed.version}" class="clearfix">
|
<li id="{installed.id}" data-plugin-id="{installed.id}" data-version="{installed.version}" class="clearfix">
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<!-- IF installed.isTheme -->
|
<!-- IF installed.isTheme -->
|
||||||
<a href="{config.relative_path}/admin/appearance/themes" class="btn btn-info">Themes</a>
|
<a href="{config.relative_path}/admin/appearance/themes" class="btn btn-info">Themes</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user