v1.18.x
Julian Lam 10 years ago
parent 02a63c0a45
commit 74f2f7caef

@ -181,28 +181,32 @@ define('admin/extend/plugins', function() {
socket.emit('admin.plugins.toggleInstall', {
id: pluginID,
version: version
}, function(err, status) {
}, function(err, pluginData) {
if (err) {
return app.alertError(err.message);
}
if (status.installed) {
btn.html('<i class="fa fa-trash-o"></i> Uninstall');
} else {
btn.html('<i class="fa fa-download"></i> Install');
}
var targetList = (pluginData.installed ? 'installed' : 'download'),
otherList = (pluginData.installed ? 'download' : 'installed'),
payload = {};
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)
.toggleClass('btn-success', !status.installed)
.attr('disabled', false)
.attr('data-installed', status.installed ? 1 : 0);
pluginList.append(html);
$('ul.' + otherList).find('li[data-plugin-id="' + pluginID + '"]').slideUp('slow', function() {
$(this).remove();
$('html,body').animate({
scrollTop: pluginList.find('li').last().offset().top - 48
}, 1000);
});
});
app.alert({
alert_id: 'plugin_toggled',
title: 'Plugin ' + (status.installed ? 'Installed' : 'Uninstalled'),
message: status.installed ? 'Plugin successfully installed, please activate the plugin.' : 'The plugin has been successfully deactivated and uninstalled.',
title: 'Plugin ' + (pluginData.installed ? 'Installed' : 'Uninstalled'),
message: pluginData.installed ? 'Plugin successfully installed, please activate the plugin.' : 'The plugin has been successfully deactivated and uninstalled.',
type: 'info',
timeout: 5000
});

@ -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) {
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 = [];
try {
plugins = JSON.parse(body);
} catch(err) {
if (err) {
winston.error('Error parsing plugins : ' + err.message);
plugins = [];
}
var pluginMap = {};
for(var i=0; i<plugins.length; ++i) {
plugins[i].id = plugins[i].name;
plugins[i].installed = false;
plugins[i].active = false;
plugins[i].url = plugins[i].url ? plugins[i].url : plugins[i].repository ? plugins[i].repository.url : '';
plugins[i].latest = plugins[i].latest;
pluginMap[plugins[i].name] = plugins[i];
Plugins.normalise(body, callback);
});
};
Plugins.normalise = function(apiReturn, callback) {
var pluginMap = {};
for(var i=0; i<apiReturn.length; ++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) {
return callback(err);
}
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();
}
var pluginArray = [];
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) {
return callback(err);
for (var key in pluginMap) {
if (pluginMap.hasOwnProperty(key)) {
pluginArray.push(pluginMap[key]);
}
}
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;
}
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) {
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-heading"><i class="fa fa-code-fork"></i> Installed Plugins</div>
<div class="panel-body">
<ul>
<ul class="installed">
<!-- BEGIN installed -->
<!-- IMPORT admin/partials/installed_plugin_item.tpl -->
<!-- END installed -->
@ -14,7 +14,7 @@
<div class="panel panel-default">
<div class="panel-heading"><i class="fa fa-code-fork"></i> Download Plugins</div>
<div class="panel-body">
<ul>
<ul class="download">
<!-- BEGIN download -->
<!-- IMPORT admin/partials/download_plugin_item.tpl -->
<!-- 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">
<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>

@ -1,5 +1,5 @@
<!-- 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">
<!-- IF installed.isTheme -->
<a href="{config.relative_path}/admin/appearance/themes" class="btn btn-info">Themes</a>

Loading…
Cancel
Save