From 66d6c49ed401ebd696d3602a0f2159bdd2499531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 23 Feb 2015 15:55:35 -0500 Subject: [PATCH] closes #2749 --- public/src/admin/extend/plugins.js | 32 ++++++++++++++++++++++++++++++ src/plugins.js | 7 +++++-- src/plugins/install.js | 4 ++++ src/socket.io/admin.js | 14 +++++++++++++ src/views/admin/extend/plugins.tpl | 29 ++++++++++++++++++++++++++- 5 files changed, 83 insertions(+), 3 deletions(-) diff --git a/public/src/admin/extend/plugins.js b/public/src/admin/extend/plugins.js index 66ffc19d7f..220c4e1980 100644 --- a/public/src/admin/extend/plugins.js +++ b/public/src/admin/extend/plugins.js @@ -93,6 +93,38 @@ define('admin/extend/plugins', function() { $(this).toggleClass('hide', pluginId && pluginId.indexOf(term) === -1); }); }); + + $('#plugin-order').on('click', function() { + $('#order-active-plugins-modal').modal('show'); + socket.emit('admin.plugins.getActive', function(err, activePlugins) { + if (err) { + return app.alertError(err); + } + var html = ''; + activePlugins.forEach(function(plugin) { + html += '
  • ' + plugin + '
  • '; + }); + if (!activePlugins.length) { + html = 'No Active Plugins'; + } + $('#order-active-plugins-modal .plugin-list').html(html).sortable(); + }); + }); + + $('#save-plugin-order').on('click', function() { + var plugins = $('#order-active-plugins-modal .plugin-list').children(); + var data = []; + plugins.each(function(index, el) { + data.push({name: $(el).text(), order: index}); + }); + + socket.emit('admin.plugins.orderActivePlugins', data, function(err) { + if (err) { + return app.alertError(err.message); + } + $('#order-active-plugins-modal').modal('hide'); + }); + }); }; function confirmInstall(pluginID, callback) { diff --git a/src/plugins.js b/src/plugins.js index 091a54daa6..fbc74e85ac 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -110,7 +110,7 @@ var fs = require('fs'), }); async.filter(plugins, fs.exists, function(plugins){ - async.each(plugins, Plugins.loadPlugin, next); + async.eachSeries(plugins, Plugins.loadPlugin, next); }); }, function(next) { @@ -262,7 +262,10 @@ var fs = require('fs'), function(dirs, next) { dirs = dirs.filter(function(dir){ - return dir.startsWith('nodebb-plugin-') || dir.startsWith('nodebb-widget-') || dir.startsWith('nodebb-rewards-') || dir.startsWith('nodebb-theme-') + return dir.startsWith('nodebb-plugin-') || + dir.startsWith('nodebb-widget-') || + dir.startsWith('nodebb-rewards-') || + dir.startsWith('nodebb-theme-'); }).map(function(dir){ return path.join(npmPluginPath, dir); }); diff --git a/src/plugins/install.js b/src/plugins/install.js index 06dcbbf659..de63cd9f3b 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -130,4 +130,8 @@ module.exports = function(Plugins) { Plugins.isActive = function(id, callback) { db.isSortedSetMember('plugins:active', id, callback); }; + + Plugins.getActive = function(callback) { + db.getSortedSetRange('plugins:active', 0, -1, callback); + }; }; \ No newline at end of file diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index 542c1d2751..30782f4d6e 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -110,6 +110,20 @@ SocketAdmin.plugins.toggleInstall = function(socket, data, callback) { plugins.toggleInstall(data.id, data.version, callback); }; +SocketAdmin.plugins.getActive = function(socket, data, callback) { + plugins.getActive(callback); +}; + +SocketAdmin.plugins.orderActivePlugins = function(socket, data, callback) { + async.each(data, function(plugin, next) { + if (plugin && plugin.name) { + db.sortedSetAdd('plugins:active', plugin.order || 0, plugin.name, next); + } else { + next(); + } + }, callback); +}; + SocketAdmin.plugins.upgrade = function(socket, data, callback) { plugins.upgrade(data.id, data.version, callback); }; diff --git a/src/views/admin/extend/plugins.tpl b/src/views/admin/extend/plugins.tpl index b44c2461bc..2fdccebfdd 100644 --- a/src/views/admin/extend/plugins.tpl +++ b/src/views/admin/extend/plugins.tpl @@ -83,7 +83,8 @@
    Plugin Search
    - +
    +
    @@ -96,4 +97,30 @@ + + + + + + +