diff --git a/pidfile 2 b/pidfile 2 deleted file mode 100644 index f37c12d8d0..0000000000 --- a/pidfile 2 +++ /dev/null @@ -1 +0,0 @@ -7263 \ No newline at end of file diff --git a/public/openapi/read.yaml b/public/openapi/read.yaml index cf971ca0ac..b451e58045 100644 --- a/public/openapi/read.yaml +++ b/public/openapi/read.yaml @@ -340,3 +340,13 @@ paths: description: Bug reported successfully '400': description: Bad request + + /api/admin/get-bug-log: + get: + summary: Get bug logs + description: Endpoint to get bug logs + responses: + '200': + description: Bug logs retrieved successfully + '400': + description: Bad request diff --git a/public/src/admin/dashboard/bug-logs.js b/public/src/admin/dashboard/bug-logs.js index c16d722db8..7fcbd48901 100644 --- a/public/src/admin/dashboard/bug-logs.js +++ b/public/src/admin/dashboard/bug-logs.js @@ -1,6 +1,62 @@ 'use strict'; -define('admin/dashboard/bug-logs', [], () => { +define('admin/dashboard/bug-logs', ['jquery', 'api'], ($, api) => { + const BugLogs = {}; + BugLogs.init = () => { + // Fetch and display bug logs + fetchBugLogs(); + // Handle bug report submission + $('#submit').on('click', submitBugReport); + }; + + function fetchBugLogs() { + api.get('/api/admin/get-bug-log') + .then((data) => { + const bugLogsContainer = $('#bug-logs-container'); + console.log(bugLogsContainer); + bugLogsContainer.empty(); + + if (data.bugLogs && data.bugLogs.length > 0) { + console.log(data.bugLogs); + data.bugLogs.forEach((log) => { + const logElement = $('
').text(`Name: ${log.name}`)); + logElement.append($('
').text(`Email: ${log.email}`)); + logElement.append($('
').text(`Description: ${log.bugDescription}`)); + logElement.append($('
').text(`Timestamp: ${log.timestamp}`)); + bugLogsContainer.append(logElement); + }); + } else { + bugLogsContainer.append($('
').text('No bug logs found.')); + } + }) + .catch((err) => { + console.error('Error fetching bug logs:', err); + $('#bug-logs-container').append($('
').text('Error fetching bug logs.')); + }); + } + + function submitBugReport() { + const description = $('#bug-report-description').val().trim(); + + if (!description) { + alert('Description is required'); + return; + } + + api.post('/api/admin/submit-bug-report', { description }) + .then(() => { + alert('Bug report submitted successfully'); + $('#bug-report-description').val(''); + fetchBugLogs(); + }) + .catch((err) => { + console.error('Error submitting bug report:', err); + alert('Error submitting bug report'); + }); + } + + return BugLogs; }); diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 222b8b863f..28395fd08e 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -390,6 +390,46 @@ dashboardController.getSearches = async (req, res) => { }); }; +const bugLogs = []; + dashboardController.getBugLogs = async function (req, res) { - res.render('admin/dashboard/bug-logs', {}); + console.log('getbuglogs'); // Add logging + try { + // Sanitize and format bug logs before rendering + console.log('bugLogs:', bugLogs); + const sanitizedBugLogs = bugLogs.map(log => ({ + user: validator.escape(String(log.user)), + description: validator.escape(String(log.description)), + timestamp: new Date(log.timestamp).toISOString(), + })); + + // Pass the sanitized bug logs to the view for rendering + res.render('admin/dashboard/bug-logs', { bugLogs: sanitizedBugLogs }); + } catch (error) { + console.error('Error fetching bug logs:', error); // Log the error for debugging + res.status(500).json({ message: 'Internal server error' }); + } +}; + +dashboardController.submitBugReport = async function (req, res) { + console.log('submitBugReport'); // Add logging + console.log('req.body:', req.body); // Add logging + try { + const { description } = req.body; + if (!description) { + return res.status(400).json({ message: 'Description is required' }); + } + + const sanitizedDescription = validator.escape(description); + const timestamp = Date.now(); + const user = req.user ? req.user.username : 'Anonymous'; // Assuming req.user contains the user information + + // Add the bug report to the in-memory array + bugLogs.push({ user, description: sanitizedDescription, timestamp }); + console.log('Bug report submitted:', { user, description: sanitizedDescription, timestamp }); + res.status(201).json({ message: 'Bug report submitted successfully' }); + } catch (error) { + console.error('Error submitting bug report:', error); // Log the error for debugging + res.status(500).json({ message: 'Internal server error' }); + } }; diff --git a/src/routes/admin.js b/src/routes/admin.js index 6054700921..7baff43dc5 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -60,7 +60,6 @@ module.exports = function (app, name, middleware, controllers) { apiRoutes(app, name, middleware, controllers); }; - function apiRoutes(router, name, middleware, controllers) { router.get(`/api/${name}/config`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.getConfig)); router.get(`/api/${name}/users/csv`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.users.getCSV)); @@ -68,6 +67,9 @@ function apiRoutes(router, name, middleware, controllers) { router.get(`/api/${name}/analytics`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.dashboard.getAnalytics)); router.get(`/api/${name}/advanced/cache/dump`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.cache.dump)); + router.get(`/api/${name}/get-bug-log`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.dashboard.getBugLogs)); + router.post(`/api/${name}/submit-bug-report`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.dashboard.submitBugReport)); + const multipart = require('connect-multiparty'); const multipartMiddleware = multipart(); diff --git a/src/views/admin/dashboard/bug-logs.tpl b/src/views/admin/dashboard/bug-logs.tpl index 3d4e05d7c9..f0a7eae20a 100644 --- a/src/views/admin/dashboard/bug-logs.tpl +++ b/src/views/admin/dashboard/bug-logs.tpl @@ -10,7 +10,7 @@