From 4b97fafe8a1a3400f0e4e9aa364d1b79a900d26c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 16 Aug 2020 19:58:15 -0400 Subject: [PATCH 1/6] Delete extraneous blank lines This is a partial cherry-pick of: https://github.com/RpNation/ep_adminpads3/commit/0340247959c9a77871f1e53794915ea880334c3a --- index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/index.js b/index.js index 86d271b..a4c9a42 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,6 @@ RegExp.quote = function (x) { }; const isNumeric = function (arg) { return typeof (arg) == "number" || (typeof (arg) == "string" && parseInt(arg)); - }; let pads = { @@ -27,7 +26,6 @@ let pads = { , maxResult = 0 , result = [] ; - if (query["pattern"] != null && query["pattern"] !== "") { let pattern = "*" + query.pattern + "*"; pattern = RegExp.quote(pattern); @@ -132,6 +130,5 @@ exports.eejsBlock_adminMenu = async function (hook_name, args) { , hasTwoDirDown = (args.content.indexOf("Manage pads"; }; From d5b8ae54014494d279e37c02b7a0358db4fc59c3 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 16 Aug 2020 19:58:16 -0400 Subject: [PATCH 2/6] Replace double quotes with single quotes This is a partial cherry-pick of: https://github.com/RpNation/ep_adminpads3/commit/0340247959c9a77871f1e53794915ea880334c3a --- index.js | 60 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index a4c9a42..fb12424 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,13 @@ -const eejs = require("ep_etherpad-lite/node/eejs"); -const padManager = require("ep_etherpad-lite/node/db/PadManager"); -const api = require("ep_etherpad-lite/node/db/API"); +const eejs = require('ep_etherpad-lite/node/eejs'); +const padManager = require('ep_etherpad-lite/node/db/PadManager'); +const api = require('ep_etherpad-lite/node/db/API'); const queryLimit = 12; RegExp.quote = function (x) { - return x.toString().replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&") + return x.toString().replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&') }; const isNumeric = function (arg) { - return typeof (arg) == "number" || (typeof (arg) == "string" && parseInt(arg)); + return typeof (arg) == 'number' || (typeof (arg) == 'string' && parseInt(arg)); }; let pads = { @@ -19,19 +19,19 @@ let pads = { _do_search: async function (pads, query) { let data = { progress: 1 - , message: "Search done." + , message: 'Search done.' , query: query , total: pads.length } , maxResult = 0 , result = [] ; - if (query["pattern"] != null && query["pattern"] !== "") { - let pattern = "*" + query.pattern + "*"; + if (query['pattern'] != null && query['pattern'] !== '') { + let pattern = '*' + query.pattern + '*'; pattern = RegExp.quote(pattern); - pattern = pattern.replace(/(\\\*)+/g, ".*"); - pattern = "^" + pattern + "$"; - let regex = new RegExp(pattern, "i"); + pattern = pattern.replace(/(\\\*)+/g, '.*'); + pattern = '^' + pattern + '$'; + let regex = new RegExp(pattern, 'i'); pads.forEach(function (padID) { if (regex.test(padID)) { result.push(padID); @@ -66,7 +66,7 @@ let pads = { data.results = []; rs.forEach(function (value) { - entrySet = {padName: value, lastEdited: "", userCount: 0}; + entrySet = {padName: value, lastEdited: '', userCount: 0}; data.results.push(entrySet); }); @@ -78,57 +78,57 @@ let pads = { value.userCount = resultObject.padUsersCount; }); } else { - data.message = "No results"; + data.message = 'No results'; } return data; } }; exports.registerRoute = async function (hook_name, args) { - args.app.get("/admin/pads", function (req, res) { + args.app.get('/admin/pads', function (req, res) { let render_args = { errors: [] }; - res.send(eejs.require("ep_adminpads2/templates/admin/pads.html", render_args)); + res.send(eejs.require('ep_adminpads2/templates/admin/pads.html', render_args)); }); }; let io = null; exports.socketio = function (hook_name, args) { - io = args.io.of("/pluginfw/admin/pads"); - io.on("connection", function (socket) { - socket.on("load", async function (query) { - let result = await pads.search({pattern: "", offset: 0, limit: queryLimit}); - socket.emit("search-result", result); + io = args.io.of('/pluginfw/admin/pads'); + io.on('connection', function (socket) { + socket.on('load', async function (query) { + let result = await pads.search({pattern: '', offset: 0, limit: queryLimit}); + socket.emit('search-result', result); }); - socket.on("search", async function (query) { + socket.on('search', async function (query) { let result = await pads.search(query); - socket.emit("search-result", result); + socket.emit('search-result', result); }); - socket.on("delete", async function (padId) { + socket.on('delete', async function (padId) { let padExists = await padManager.doesPadExists(padId); if (padExists) { //pad exists, remove let pad = await padManager.getPad(padId); await pad.remove(); - socket.emit("progress", {progress: 1}); + socket.emit('progress', {progress: 1}); } }); }); }; exports.updatePads = async function (hook_name, args) { - io.emit("progress", {progress: 1}); + io.emit('progress', {progress: 1}); }; exports.eejsBlock_adminMenu = async function (hook_name, args) { - let hasAdminUrlPrefix = (args.content.indexOf("Manage pads"; + args.content = args.content + '
  • Manage pads
  • '; }; From cb78469e296f2bc5ad3ed8822ac63b3133b66acf Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 16 Aug 2020 19:58:17 -0400 Subject: [PATCH 3/6] Add missing semicolon This is a partial cherry-pick of: https://github.com/RpNation/ep_adminpads3/commit/0340247959c9a77871f1e53794915ea880334c3a --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index fb12424..0f52116 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const api = require('ep_etherpad-lite/node/db/API'); const queryLimit = 12; RegExp.quote = function (x) { - return x.toString().replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&') + return x.toString().replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); }; const isNumeric = function (arg) { return typeof (arg) == 'number' || (typeof (arg) == 'string' && parseInt(arg)); From 11a8b20113bb089c7a19d69a15efe969fa70c5f5 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 16 Aug 2020 19:58:17 -0400 Subject: [PATCH 4/6] Style cleanups This is a partial cherry-pick of: https://github.com/RpNation/ep_adminpads3/commit/0340247959c9a77871f1e53794915ea880334c3a --- index.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 0f52116..5471671 100644 --- a/index.js +++ b/index.js @@ -18,14 +18,13 @@ let pads = { }, _do_search: async function (pads, query) { let data = { - progress: 1 - , message: 'Search done.' - , query: query - , total: pads.length - } - , maxResult = 0 - , result = [] - ; + progress: 1, + message: 'Search done.', + query: query, + total: pads.length, + }, + maxResult = 0, + result = []; if (query['pattern'] != null && query['pattern'] !== '') { let pattern = '*' + query.pattern + '*'; pattern = RegExp.quote(pattern); @@ -81,13 +80,13 @@ let pads = { data.message = 'No results'; } return data; - } + }, }; exports.registerRoute = async function (hook_name, args) { args.app.get('/admin/pads', function (req, res) { let render_args = { - errors: [] + errors: [], }; res.send(eejs.require('ep_adminpads2/templates/admin/pads.html', render_args)); }); @@ -125,10 +124,9 @@ exports.updatePads = async function (hook_name, args) { }; exports.eejsBlock_adminMenu = async function (hook_name, args) { - let hasAdminUrlPrefix = (args.content.indexOf('Manage pads'; }; From 858cd4248b06e204d03835ee0f1ae2c73e7c3779 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 16 Aug 2020 19:58:18 -0400 Subject: [PATCH 5/6] Delete unnecessary parentheses This is a partial cherry-pick of: https://github.com/RpNation/ep_adminpads3/commit/0340247959c9a77871f1e53794915ea880334c3a --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5471671..a14d018 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ RegExp.quote = function (x) { return x.toString().replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); }; const isNumeric = function (arg) { - return typeof (arg) == 'number' || (typeof (arg) == 'string' && parseInt(arg)); + return typeof arg == 'number' || (typeof arg == 'string' && parseInt(arg)); }; let pads = { @@ -124,9 +124,9 @@ exports.updatePads = async function (hook_name, args) { }; exports.eejsBlock_adminMenu = async function (hook_name, args) { - let hasAdminUrlPrefix = (args.content.indexOf('Manage pads'; }; From 15750ad3fbf2d4b0383fddd6f53046d3c2c510c7 Mon Sep 17 00:00:00 2001 From: MShultz Date: Tue, 11 Aug 2020 00:06:25 -0600 Subject: [PATCH 6/6] Adds fix for empty last edited date. --- index.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a14d018..cd6c533 100644 --- a/index.js +++ b/index.js @@ -69,16 +69,22 @@ let pads = { data.results.push(entrySet); }); + let getEdited = []; if (data.results.length > 0) { data.results.forEach(function (value) { - let resultObject = api.getLastEdited(value.padName); - value.lastEdited = resultObject.lastEdited; - resultObject = api.padUsersCount(value.padName); - value.userCount = resultObject.padUsersCount; + getEdited.push( + api.getLastEdited(value.padName) + .then((resultObject) => { + value.lastEdited = resultObject.lastEdited; + resultObject = api.padUsersCount(value.padName); + value.userCount = resultObject.padUsersCount; + })); }); } else { data.message = 'No results'; } + + await Promise.all(getEdited); return data; }, };