From cd1d322af426baafa91f04aa699abc0e26057b07 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Wed, 3 Feb 2021 23:05:58 -0500 Subject: [PATCH] /admin/plugins/info: Move logic to `.js` file --- src/node/hooks/express/adminplugins.js | 17 +++++++++++------ src/templates/admin/plugins-info.html | 11 ++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/node/hooks/express/adminplugins.js b/src/node/hooks/express/adminplugins.js index e2129c116..5963fb208 100644 --- a/src/node/hooks/express/adminplugins.js +++ b/src/node/hooks/express/adminplugins.js @@ -3,14 +3,15 @@ const eejs = require('../../eejs'); const settings = require('../../utils/Settings'); const installer = require('../../../static/js/pluginfw/installer'); -const plugins = require('../../../static/js/pluginfw/plugin_defs'); +const pluginDefs = require('../../../static/js/pluginfw/plugin_defs'); +const plugins = require('../../../static/js/pluginfw/plugins'); const semver = require('semver'); const UpdateCheck = require('../../utils/UpdateCheck'); exports.expressCreateServer = (hookName, args, cb) => { args.app.get('/admin/plugins', (req, res) => { res.send(eejs.require('ep_etherpad-lite/templates/admin/plugins.html', { - plugins: plugins.plugins, + plugins: pluginDefs.plugins, req, errors: [], })); @@ -23,6 +24,10 @@ exports.expressCreateServer = (hookName, args, cb) => { res.send(eejs.require('ep_etherpad-lite/templates/admin/plugins-info.html', { gitCommit, epVersion, + installedPlugins: `
${plugins.formatPlugins().replace(/, /g, '\n')}
`, + installedParts: `
${plugins.formatParts()}
`, + installedServerHooks: `
${plugins.formatHooks()}
`, + installedClientHooks: `
${plugins.formatHooks('client_hooks')}
`, latestVersion: UpdateCheck.getLatestVersion(), req, })); @@ -40,7 +45,7 @@ exports.socketio = (hookName, args, cb) => { socket.on('getInstalled', (query) => { // send currently installed plugins const installed = - Object.keys(plugins.plugins).map((plugin) => plugins.plugins[plugin].package); + Object.keys(pluginDefs.plugins).map((plugin) => pluginDefs.plugins[plugin].package); socket.emit('results:installed', {installed}); }); @@ -50,11 +55,11 @@ exports.socketio = (hookName, args, cb) => { try { const results = await installer.getAvailablePlugins(/* maxCacheAge:*/ 60 * 10); - const updatable = Object.keys(plugins.plugins).filter((plugin) => { + const updatable = Object.keys(pluginDefs.plugins).filter((plugin) => { if (!results[plugin]) return false; const latestVersion = results[plugin].version; - const currentVersion = plugins.plugins[plugin].package.version; + const currentVersion = pluginDefs.plugins[plugin].package.version; return semver.gt(latestVersion, currentVersion); }); @@ -82,7 +87,7 @@ exports.socketio = (hookName, args, cb) => { const results = await installer.search(query.searchTerm, /* maxCacheAge:*/ 60 * 10); let res = Object.keys(results) .map((pluginName) => results[pluginName]) - .filter((plugin) => !plugins.plugins[plugin.name]); + .filter((plugin) => !pluginDefs.plugins[plugin.name]); res = sortPluginList(res, query.sortBy, query.sortDir) .slice(query.offset, query.offset + query.limit); socket.emit('results:search', {results: res, query}); diff --git a/src/templates/admin/plugins-info.html b/src/templates/admin/plugins-info.html index b960ff32f..a737ea05b 100644 --- a/src/templates/admin/plugins-info.html +++ b/src/templates/admin/plugins-info.html @@ -1,6 +1,3 @@ -<% - var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); -%> @@ -31,17 +28,17 @@

Git sha: <%= gitCommit %>

Installed plugins

-
<%- plugins.formatPlugins().replace(/, /g,"\n") %>
+ <%- installedPlugins %>

Installed parts

-
<%= plugins.formatParts() %>
+ <%- installedParts %>

Installed hooks

Server-side hooks

-
<%- plugins.formatHooks() %>
+ <%- installedServerHooks %>

Client-side hooks

-
<%- plugins.formatHooks("client_hooks") %>
+ <%- installedClientHooks %>