From ab7657d4456460b9ba2d4ff78b6b5ae20621034a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 22 Oct 2018 07:30:48 -0400 Subject: [PATCH] closes #6854 --- public/language/en-GB/admin/menu.json | 1 + public/less/admin/admin.less | 1 + public/less/admin/advanced/hooks.less | 3 +++ src/controllers/admin.js | 1 + src/controllers/admin/hooks.js | 32 +++++++++++++++++++++++++++ src/routes/admin.js | 1 + src/views/admin/advanced/hooks.tpl | 31 ++++++++++++++++++++++++++ src/views/admin/partials/menu.tpl | 6 +++-- 8 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 public/less/admin/advanced/hooks.less create mode 100644 src/controllers/admin/hooks.js create mode 100644 src/views/admin/advanced/hooks.tpl diff --git a/public/language/en-GB/admin/menu.json b/public/language/en-GB/admin/menu.json index 7e0d46d86b..cd95b5891f 100644 --- a/public/language/en-GB/admin/menu.json +++ b/public/language/en-GB/admin/menu.json @@ -57,6 +57,7 @@ "section-advanced": "Advanced", "advanced/database": "Database", "advanced/events": "Events", + "advanced/hooks": "Hooks", "advanced/logs": "Logs", "advanced/errors": "Errors", "advanced/cache": "Cache", diff --git a/public/less/admin/admin.less b/public/less/admin/admin.less index 18c4556926..59eb225e5f 100644 --- a/public/less/admin/admin.less +++ b/public/less/admin/admin.less @@ -25,6 +25,7 @@ @import "./advanced/database"; @import "./advanced/logs"; @import "./advanced/errors"; +@import "./advanced/hooks"; @import "./settings"; @import "../flags"; diff --git a/public/less/admin/advanced/hooks.less b/public/less/admin/advanced/hooks.less new file mode 100644 index 0000000000..790a539c5a --- /dev/null +++ b/public/less/admin/advanced/hooks.less @@ -0,0 +1,3 @@ +.admin .hooks-list .panel.panel-default .panel-heading { + text-transform: none; +} diff --git a/src/controllers/admin.js b/src/controllers/admin.js index dc3b6862ae..019192fd3c 100644 --- a/src/controllers/admin.js +++ b/src/controllers/admin.js @@ -15,6 +15,7 @@ var adminController = { rewards: require('./admin/rewards'), }, events: require('./admin/events'), + hooks: require('./admin/hooks'), logs: require('./admin/logs'), errors: require('./admin/errors'), database: require('./admin/database'), diff --git a/src/controllers/admin/hooks.js b/src/controllers/admin/hooks.js new file mode 100644 index 0000000000..8c88c21a08 --- /dev/null +++ b/src/controllers/admin/hooks.js @@ -0,0 +1,32 @@ +'use strict'; + +var plugins = require('../../plugins'); + +var hooksController = module.exports; + +hooksController.get = function (req, res) { + var hooks = []; + Object.keys(plugins.loadedHooks).forEach(function (key, hookIndex) { + var current = { + hookName: key, + methods: [], + index: 'hook-' + hookIndex, + count: plugins.loadedHooks[key].length, + }; + + plugins.loadedHooks[key].forEach(function (hookData, methodIndex) { + current.methods.push({ + id: hookData.id, + priority: hookData.priority, + method: hookData.method ? hookData.method.toString() : 'No plugin function!', + index: hookIndex + '-code-' + methodIndex, + }); + }); + hooks.push(current); + }); + + hooks.sort((a, b) => b.count - a.count); + + res.render('admin/advanced/hooks', { hooks: hooks }); +}; + diff --git a/src/routes/admin.js b/src/routes/admin.js index 98008cfeec..f0ec9038e3 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -90,6 +90,7 @@ function addRoutes(router, middleware, controllers) { router.get('/advanced/database', middlewares, controllers.admin.database.get); router.get('/advanced/events', middlewares, controllers.admin.events.get); + router.get('/advanced/hooks', middlewares, controllers.admin.hooks.get); router.get('/advanced/logs', middlewares, controllers.admin.logs.get); router.get('/advanced/errors', middlewares, controllers.admin.errors.get); router.get('/advanced/errors/export', middlewares, controllers.admin.errors.export); diff --git a/src/views/admin/advanced/hooks.tpl b/src/views/admin/advanced/hooks.tpl new file mode 100644 index 0000000000..c948c37e3b --- /dev/null +++ b/src/views/admin/advanced/hooks.tpl @@ -0,0 +1,31 @@ +
+ +
+ +
+
+ +
+ {hooks.methods.id} + Priority: {hooks.methods.priority} + + +
+
+
{hooks.methods.method}
+
+ +
+
+
+ +
\ No newline at end of file diff --git a/src/views/admin/partials/menu.tpl b/src/views/admin/partials/menu.tpl index d6ad00f0db..fc8cf398a7 100644 --- a/src/views/admin/partials/menu.tpl +++ b/src/views/admin/partials/menu.tpl @@ -8,7 +8,7 @@ - +