lint: Fix ESLint errors in /admin/plugins code

This commit is contained in:
Richard Hansen 2020-11-27 10:40:05 -05:00 committed by John McLear
parent 6a5f905090
commit 973644c7dd
2 changed files with 76 additions and 60 deletions

View file

@ -1,12 +1,14 @@
const eejs = require('ep_etherpad-lite/node/eejs'); 'use strict';
const settings = require('ep_etherpad-lite/node/utils/Settings');
const installer = require('ep_etherpad-lite/static/js/pluginfw/installer'); const eejs = require('../../eejs');
const plugins = require('ep_etherpad-lite/static/js/pluginfw/plugin_defs'); const settings = require('../../utils/Settings');
const installer = require('../../../static/js/pluginfw/installer');
const plugins = require('../../../static/js/pluginfw/plugin_defs');
const _ = require('underscore'); const _ = require('underscore');
const semver = require('semver'); const semver = require('semver');
const UpdateCheck = require('ep_etherpad-lite/node/utils/UpdateCheck'); const UpdateCheck = require('../../utils/UpdateCheck');
exports.expressCreateServer = function (hook_name, args, cb) { exports.expressCreateServer = (hookName, args, cb) => {
args.app.get('/admin/plugins', (req, res) => { args.app.get('/admin/plugins', (req, res) => {
res.send(eejs.require('ep_etherpad-lite/templates/admin/plugins.html', { res.send(eejs.require('ep_etherpad-lite/templates/admin/plugins.html', {
plugins: plugins.plugins, plugins: plugins.plugins,
@ -30,14 +32,16 @@ exports.expressCreateServer = function (hook_name, args, cb) {
return cb(); return cb();
}; };
exports.socketio = function (hook_name, args, cb) { exports.socketio = (hookName, args, cb) => {
const io = args.io.of('/pluginfw/installer'); const io = args.io.of('/pluginfw/installer');
io.on('connection', (socket) => { io.on('connection', (socket) => {
if (!socket.conn.request.session || !socket.conn.request.session.user || !socket.conn.request.session.user.is_admin) return; const {session: {user: {is_admin: isAdmin} = {}} = {}} = socket.conn.request;
if (!isAdmin) return;
socket.on('getInstalled', (query) => { socket.on('getInstalled', (query) => {
// send currently installed plugins // send currently installed plugins
const installed = Object.keys(plugins.plugins).map((plugin) => plugins.plugins[plugin].package); const installed =
Object.keys(plugins.plugins).map((plugin) => plugins.plugins[plugin].package);
socket.emit('results:installed', {installed}); socket.emit('results:installed', {installed});
}); });
@ -90,27 +94,30 @@ exports.socketio = function (hook_name, args, cb) {
} }
}); });
socket.on('install', (plugin_name) => { socket.on('install', (pluginName) => {
installer.install(plugin_name, (er) => { installer.install(pluginName, (er) => {
if (er) console.warn(er); if (er) console.warn(er);
socket.emit('finished:install', {plugin: plugin_name, code: er ? er.code : null, error: er ? er.message : null}); socket.emit('finished:install', {
plugin: pluginName,
code: er ? er.code : null,
error: er ? er.message : null,
});
}); });
}); });
socket.on('uninstall', (plugin_name) => { socket.on('uninstall', (pluginName) => {
installer.uninstall(plugin_name, (er) => { installer.uninstall(pluginName, (er) => {
if (er) console.warn(er); if (er) console.warn(er);
socket.emit('finished:uninstall', {plugin: plugin_name, error: er ? er.message : null}); socket.emit('finished:uninstall', {plugin: pluginName, error: er ? er.message : null});
}); });
}); });
}); });
return cb(); return cb();
}; };
function sortPluginList(plugins, property, /* ASC?*/dir) { const sortPluginList = (plugins, property, /* ASC?*/dir) => plugins.sort((a, b) => {
return plugins.sort((a, b) => {
if (a[property] < b[property]) { if (a[property] < b[property]) {
return dir ? -1 : 1; return dir ? -1 : 1;
} }
@ -121,5 +128,4 @@ function sortPluginList(plugins, property, /* ASC?*/dir) {
// a must be equal to b // a must be equal to b
return 0; return 0;
}); });
}

View file

@ -1,7 +1,8 @@
'use strict';
$(document).ready(() => { $(document).ready(() => {
let socket;
const loc = document.location; const loc = document.location;
const port = loc.port == '' ? (loc.protocol == 'https:' ? 443 : 80) : loc.port; const port = loc.port === '' ? (loc.protocol === 'https:' ? 443 : 80) : loc.port;
const url = `${loc.protocol}//${loc.hostname}:${port}/`; const url = `${loc.protocol}//${loc.hostname}:${port}/`;
const pathComponents = location.pathname.split('/'); const pathComponents = location.pathname.split('/');
// Strip admin/plugins // Strip admin/plugins
@ -10,23 +11,29 @@ $(document).ready(() => {
// connect // connect
const room = `${url}pluginfw/installer`; const room = `${url}pluginfw/installer`;
socket = io.connect(room, {path: `${baseURL}socket.io`, resource}); const socket = io.connect(room, {path: `${baseURL}socket.io`, resource});
function search(searchTerm, limit) { const search = (searchTerm, limit) => {
if (search.searchTerm != searchTerm) { if (search.searchTerm !== searchTerm) {
search.offset = 0; search.offset = 0;
search.results = []; search.results = [];
search.end = false; search.end = false;
} }
limit = limit ? limit : search.limit; limit = limit ? limit : search.limit;
search.searchTerm = searchTerm; search.searchTerm = searchTerm;
socket.emit('search', {searchTerm, offset: search.offset, limit, sortBy: search.sortBy, sortDir: search.sortDir}); socket.emit('search', {
searchTerm,
offset: search.offset,
limit,
sortBy: search.sortBy,
sortDir: search.sortDir,
});
search.offset += limit; search.offset += limit;
$('#search-progress').show(); $('#search-progress').show();
search.messages.show('fetching'); search.messages.show('fetching');
search.searching = true; search.searching = true;
} };
search.searching = false; search.searching = false;
search.offset = 0; search.offset = 0;
search.limit = 999; search.limit = 999;
@ -35,12 +42,12 @@ $(document).ready(() => {
search.sortDir = /* DESC?*/true; search.sortDir = /* DESC?*/true;
search.end = true;// have we received all results already? search.end = true;// have we received all results already?
search.messages = { search.messages = {
show(msg) { show: (msg) => {
// $('.search-results .messages').show() // $('.search-results .messages').show()
$(`.search-results .messages .${msg}`).show(); $(`.search-results .messages .${msg}`).show();
$(`.search-results .messages .${msg} *`).show(); $(`.search-results .messages .${msg} *`).show();
}, },
hide(msg) { hide: (msg) => {
$('.search-results .messages').hide(); $('.search-results .messages').hide();
$(`.search-results .messages .${msg}`).hide(); $(`.search-results .messages .${msg}`).hide();
$(`.search-results .messages .${msg} *`).hide(); $(`.search-results .messages .${msg} *`).hide();
@ -49,22 +56,24 @@ $(document).ready(() => {
const installed = { const installed = {
progress: { progress: {
show(plugin, msg) { show: (plugin, msg) => {
$(`.installed-results .${plugin} .progress`).show(); $(`.installed-results .${plugin} .progress`).show();
$(`.installed-results .${plugin} .progress .message`).text(msg); $(`.installed-results .${plugin} .progress .message`).text(msg);
if ($(window).scrollTop() > $(`.${plugin}`).offset().top)$(window).scrollTop($(`.${plugin}`).offset().top - 100); if ($(window).scrollTop() > $(`.${plugin}`).offset().top) {
$(window).scrollTop($(`.${plugin}`).offset().top - 100);
}
}, },
hide(plugin) { hide: (plugin) => {
$(`.installed-results .${plugin} .progress`).hide(); $(`.installed-results .${plugin} .progress`).hide();
$(`.installed-results .${plugin} .progress .message`).text(''); $(`.installed-results .${plugin} .progress .message`).text('');
}, },
}, },
messages: { messages: {
show(msg) { show: (msg) => {
$('.installed-results .messages').show(); $('.installed-results .messages').show();
$(`.installed-results .messages .${msg}`).show(); $(`.installed-results .messages .${msg}`).show();
}, },
hide(msg) { hide: (msg) => {
$('.installed-results .messages').hide(); $('.installed-results .messages').hide();
$(`.installed-results .messages .${msg}`).hide(); $(`.installed-results .messages .${msg}`).hide();
}, },
@ -72,12 +81,12 @@ $(document).ready(() => {
list: [], list: [],
}; };
function displayPluginList(plugins, container, template) { const displayPluginList = (plugins, container, template) => {
plugins.forEach((plugin) => { plugins.forEach((plugin) => {
const row = template.clone(); const row = template.clone();
for (attr in plugin) { for (const attr in plugin) {
if (attr == 'name') { // Hack to rewrite URLS into name if (attr === 'name') { // Hack to rewrite URLS into name
const link = $('<a>'); const link = $('<a>');
link.attr('href', `https://npmjs.org/package/${plugin.name}`); link.attr('href', `https://npmjs.org/package/${plugin.name}`);
link.attr('plugin', 'Plugin details'); link.attr('plugin', 'Plugin details');
@ -94,18 +103,16 @@ $(document).ready(() => {
container.append(row); container.append(row);
}); });
updateHandlers(); updateHandlers();
} };
function sortPluginList(plugins, property, /* ASC?*/dir) { const sortPluginList = (plugins, property, /* ASC?*/dir) => plugins.sort((a, b) => {
return plugins.sort((a, b) => {
if (a[property] < b[property]) return dir ? -1 : 1; if (a[property] < b[property]) return dir ? -1 : 1;
if (a[property] > b[property]) return dir ? 1 : -1; if (a[property] > b[property]) return dir ? 1 : -1;
// a must be equal to b // a must be equal to b
return 0; return 0;
}); });
}
function updateHandlers() { const updateHandlers = () => {
// Search // Search
$('#search-query').unbind('keyup').keyup(() => { $('#search-query').unbind('keyup').keyup(() => {
search($('#search-query').val()); search($('#search-query').val());
@ -134,7 +141,7 @@ $(document).ready(() => {
const pluginName = $row.data('plugin'); const pluginName = $row.data('plugin');
socket.emit('uninstall', pluginName); socket.emit('uninstall', pluginName);
installed.progress.show(pluginName, 'Uninstalling'); installed.progress.show(pluginName, 'Uninstalling');
installed.list = installed.list.filter((plugin) => plugin.name != pluginName); installed.list = installed.list.filter((plugin) => plugin.name !== pluginName);
}); });
// Sort // Sort
@ -152,11 +159,11 @@ $(document).ready(() => {
search(search.searchTerm, search.results.length); search(search.searchTerm, search.results.length);
search.results = []; search.results = [];
}); });
} };
socket.on('results:search', (data) => { socket.on('results:search', (data) => {
if (!data.results.length) search.end = true; if (!data.results.length) search.end = true;
if (data.query.offset == 0) search.results = []; if (data.query.offset === 0) search.results = [];
search.messages.hide('nothing-found'); search.messages.hide('nothing-found');
search.messages.hide('fetching'); search.messages.hide('fetching');
$('#search-query').removeAttr('disabled'); $('#search-query').removeAttr('disabled');
@ -178,7 +185,8 @@ $(document).ready(() => {
const searchWidget = $('.search-results'); const searchWidget = $('.search-results');
searchWidget.find('.results *').remove(); searchWidget.find('.results *').remove();
if (search.results.length > 0) { if (search.results.length > 0) {
displayPluginList(search.results, searchWidget.find('.results'), searchWidget.find('.template tr')); displayPluginList(
search.results, searchWidget.find('.results'), searchWidget.find('.template tr'));
} else { } else {
search.messages.show('nothing-found'); search.messages.show('nothing-found');
} }
@ -195,7 +203,7 @@ $(document).ready(() => {
sortPluginList(installed.list, 'name', /* ASC?*/true); sortPluginList(installed.list, 'name', /* ASC?*/true);
// filter out epl // filter out epl
installed.list = installed.list.filter((plugin) => plugin.name != 'ep_etherpad-lite'); installed.list = installed.list.filter((plugin) => plugin.name !== 'ep_etherpad-lite');
// remove all installed plugins (leave plugins that are still being installed) // remove all installed plugins (leave plugins that are still being installed)
installed.list.forEach((plugin) => { installed.list.forEach((plugin) => {
@ -237,7 +245,9 @@ $(document).ready(() => {
}); });
socket.on('finished:uninstall', (data) => { socket.on('finished:uninstall', (data) => {
if (data.error) alert(`An error occurred while uninstalling the ${data.plugin} \n${data.error}`); if (data.error) {
alert(`An error occurred while uninstalling the ${data.plugin} \n${data.error}`);
}
// remove plugin from installed list // remove plugin from installed list
$(`#installed-plugins .${data.plugin}`).remove(); $(`#installed-plugins .${data.plugin}`).remove();