From 7b05e953e46addd26f9eea9f49fd24a4dfcfa28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cakobaidan=E2=80=9D?= Date: Tue, 15 Oct 2024 10:51:13 +0200 Subject: [PATCH 1/8] updated bug-log controller for correct rendering --- src/controllers/admin/dashboard.js | 40 +++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 222b8b863f..204aed4a01 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -390,6 +390,44 @@ 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 + 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) { + 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 }); + + 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' }); + } +}; \ No newline at end of file From 97759af27baf2922433afabb9451f46f78e9f915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cakobaidan=E2=80=9D?= Date: Tue, 15 Oct 2024 10:54:08 +0200 Subject: [PATCH 2/8] updated bug-log route handler to handle logs and reports --- public/src/admin/dashboard/bug-logs.js | 55 +++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/public/src/admin/dashboard/bug-logs.js b/public/src/admin/dashboard/bug-logs.js index c16d722db8..a2bb5f9ac5 100644 --- a/public/src/admin/dashboard/bug-logs.js +++ b/public/src/admin/dashboard/bug-logs.js @@ -1,6 +1,59 @@ '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-bug-report').on('click', submitBugReport); + }; + + function fetchBugLogs() { + api.get('/api/admin/get-bug-log') + .then((data) => { + const bugLogsContainer = $('#bug-logs-container'); + bugLogsContainer.empty(); + + if (data.bugLogs && data.bugLogs.length > 0) { + data.bugLogs.forEach((log) => { + const logElement = $('
').addClass('bug-log'); + logElement.append($('

').text(`User: ${log.user}`)); + logElement.append($('

').text(`Description: ${log.description}`)); + 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; }); From 9ce1a638b27260144183e3a0a66ed6cbd134c236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cakobaidan=E2=80=9D?= Date: Tue, 15 Oct 2024 10:58:11 +0200 Subject: [PATCH 3/8] updated report form with event listener --- src/views/bug-report-form.tpl | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/views/bug-report-form.tpl b/src/views/bug-report-form.tpl index 3ef158b38c..99a743fc3d 100644 --- a/src/views/bug-report-form.tpl +++ b/src/views/bug-report-form.tpl @@ -95,21 +95,6 @@

- + \ No newline at end of file From 1f154cc75879d5175655d91a001fa6c4040f48c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cakobaidan=E2=80=9D?= Date: Tue, 15 Oct 2024 10:58:54 +0200 Subject: [PATCH 4/8] updated report form with console log --- src/views/bug-report-form.tpl | 61 +++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/views/bug-report-form.tpl b/src/views/bug-report-form.tpl index 99a743fc3d..2d4d29933d 100644 --- a/src/views/bug-report-form.tpl +++ b/src/views/bug-report-form.tpl @@ -4,6 +4,7 @@ Bug Report Form +