From cfb1847e7ce0305ff4569e20d3fd6cd8eb4062c8 Mon Sep 17 00:00:00 2001 From: Ghalya AL-Eshaq Date: Sun, 20 Oct 2024 19:22:22 +0300 Subject: [PATCH] editing bug-archive tamplate to render data acuratly rend bugs in the bug archive --- .../templates/partials/sidebar-left.tpl | 2 +- src/controllers/admin/dashboard.js | 4 ++- src/views/admin/dashboard/bug-archive.tpl | 35 +++++++++---------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/node_modules/nodebb-theme-harmony/templates/partials/sidebar-left.tpl b/node_modules/nodebb-theme-harmony/templates/partials/sidebar-left.tpl index c814f1bf14..2198af7e64 100644 --- a/node_modules/nodebb-theme-harmony/templates/partials/sidebar-left.tpl +++ b/node_modules/nodebb-theme-harmony/templates/partials/sidebar-left.tpl @@ -126,7 +126,7 @@ form.onsubmit = function(event) { //event.preventDefault(); console.log("pressed the submit button"); - //alert('Thank you! We received your feedback and will get back to you soon.'); + alert('Thank you! We received your feedback and will get back to you soon.'); console.log("Submitted the form :p yay !"); console.log("fetchingggggg"); diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index e2524b882d..e9224e9808 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -405,7 +405,7 @@ exports.submitBug = async (req, res) => { } try { - const bug = { title, description, dateSubmitted: new Date().toISOString() }; + const bug = { title, description, submittedBy: req.uid, dateSubmitted: new Date().toISOString() }; bugArchive.push(bug); res.status(200).json({ message: 'Bug submitted successfully' }); } catch (error) { @@ -416,6 +416,8 @@ exports.submitBug = async (req, res) => { // Get Bug Archive Handler exports.getBugArchive = async (req, res) => { console.log('im hereeeeeeeeeeee'); + console.log(bugArchive); // Log the bug archive before sending it + // res.json(bugArchive); try { // Render the 'bug-archive' template with the in-memory bug data res.render('admin/dashboard/bug-archive', { diff --git a/src/views/admin/dashboard/bug-archive.tpl b/src/views/admin/dashboard/bug-archive.tpl index 694ca84639..62f09c3df4 100644 --- a/src/views/admin/dashboard/bug-archive.tpl +++ b/src/views/admin/dashboard/bug-archive.tpl @@ -61,25 +61,22 @@ function fetchBugArchive() { console.log('Fetching bug archive...'); - fetch('/api/admin/dashboard/bug-archive') - .then(response => { - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - }) - .then(data => { - bugArchiveBody.innerHTML = ''; - if (data.archive && data.archive.length > 0) { - data.archive.forEach(bug => { - const row = document.createElement('tr'); - row.innerHTML = ` - ${bug.title} - ${bug.description} - ${bug.submittedBy} - ${bug.dateSubmitted} - `; - bugArchiveBody.appendChild(row); + fetch('/api/admin/get-bug-archive') // Adjust endpoint as necessary + .then(response => response.json()) + .then(data => { + const bugArchiveBody = document.getElementById('bug-archive-body'); + bugArchiveBody.innerHTML = ''; // Clear existing data + + if (data.archive && data.archive.length > 0) { + data.archive.forEach(bug => { + const row = document.createElement('tr'); + row.innerHTML = ` + ${validator.escape(bug.title)} + ${validator.escape(bug.description)} + ${bug.submittedBy || 'Unknown'} + ${new Date(bug.dateSubmitted).toLocaleString()} + `; + bugArchiveBody.appendChild(row) }); } else { const row = document.createElement('tr');