Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Bug Archive Feature in Admin Dashboard - User Story 2 #53

Open
wants to merge 56 commits into
base: f24
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
75a6da3
adding the bug archive button on the admin dashboared to show all sub…
Sep 26, 2024
32b09b5
adding the route to the admin dashboard/ bug archive button
Sep 26, 2024
2cb2541
adding a new method (getBugArchive) in the dashbaord contorller for …
Sep 26, 2024
a54658a
fixed the indentation of the getBugArchive method
Sep 26, 2024
1aeaba8
editing the getBugArchive method in admin dashboared controller
Sep 26, 2024
3dcdad9
created bug-archive.tpl under src/views/admin/dashbooard to show all …
Sep 26, 2024
8c75fe8
ceated bug archive.js under public src admin dashbored
Sep 27, 2024
28b36b4
added an id to the submit button feedback in sidebar-left.tpl to easi…
Sep 27, 2024
4f8603e
added an event listener for the submit bug/feedback button in bug-arc…
Sep 27, 2024
7b8a4ee
adding code in sidebar-left.tpl to ensure the form submission sends t…
Sep 27, 2024
87fe1f6
ensuring that bug-archive.js fetches and displays the latest bug dat…
Sep 27, 2024
0bb6620
created a new file bug-routes under routes to connect the button with…
Sep 27, 2024
914df1a
editing the dashbored in the admin page
Sep 27, 2024
cc3dd53
editing sidevar-left.tpl to stop the form from submiting and ensuring…
Sep 30, 2024
b15a10c
added the css style of the bug-archive in the file src/views/admin/da…
Sep 30, 2024
c1389d7
added the correct API routes to the bug archive page in the admin das…
Oct 11, 2024
87df287
handleing the logic for sending the title and description from the fo…
Oct 11, 2024
9d94cdb
changing the logic of the two functions in admin controller of the su…
Oct 11, 2024
1a2f8d7
editing the routes in admin.js file
Oct 11, 2024
5026343
editing the routes in admin.js file to ensure that the client can sub…
Oct 11, 2024
94e16ce
adding the action and method attributes to the <form> to handle the f…
Oct 11, 2024
a3f2e1e
redefining the routes in admin.js for sumiting and retreiving bugs
Oct 11, 2024
766f655
editing the fetch method for submiting the data in sidebar-left.tpl
Oct 11, 2024
2d5c1f5
fixing the csrf token error in sidebar-left.tpl
Oct 17, 2024
cb6e826
fixing syntax errors in src/routes/admin.js
Oct 17, 2024
0dab00f
added a new file called bug-archive.yaml under public/openapi/admin/d…
Oct 18, 2024
6416bb6
added the content of the file public/openapi/admin/dashboared/bug-arc…
Oct 18, 2024
339b339
fixing the bug archive tamplate to include the right content only
Oct 18, 2024
efc1c67
fixing the bug archive tamplate
Oct 18, 2024
0f1c65a
fixing the bug archive json file
Oct 18, 2024
66cee14
debugging bug-archive.js
Oct 18, 2024
42d89f4
added the bug-archive.yaml in a new path which is public/openapi/read…
Oct 18, 2024
fd509a5
added the test file for the bug archive page
Oct 18, 2024
84c86de
added the tests in the test/bug-archive.js file
Oct 18, 2024
aabc8d4
defined the GET /api/admin/dashboard/bug-archive in the schma docs un…
Oct 18, 2024
b489151
editing the test file for bug archive
Oct 18, 2024
f6c7d5b
fixing the bug-archive test file
Oct 19, 2024
43cfe6b
creating the test file for the bug form tamplate to test the form aut…
Oct 19, 2024
a5de48c
adding the tests in the bug form test file under the path test/bug-fo…
Oct 19, 2024
244773f
editing the test form automated tests
Oct 19, 2024
de6c52b
fixing errors in the autometed test file for the bug form
Oct 19, 2024
3483e24
editing the bug archive test file
Oct 19, 2024
4709ac9
fixing linter errors in bug-archive.js file
Oct 19, 2024
25b6fd5
recreating and readding the bug-form.js after fixing the errors it cr…
Oct 19, 2024
a591ead
edited and added the testing code for the bug form testing file
Oct 19, 2024
9ff93fb
deleted the testing files because i realized that i need to add them…
Oct 19, 2024
6f061d0
created the testing file for the bug archive page in the admin dashbo…
Oct 19, 2024
87a9c41
added the testing logic in test/bug-archive.js file to automatically …
Oct 19, 2024
0bfe71c
fixed synax errors in test/bug-archive.js file
Oct 19, 2024
1f030d9
created the testing file for the s page in the admin dashboared in th…
Oct 19, 2024
f6edbd2
created the testing file for submititng the bug form and button in th…
Oct 19, 2024
61d09ee
added the testing logic in test/bug-form.js file to automatically tes…
Oct 19, 2024
e9ef124
fixed the csrf token error
Oct 20, 2024
1bf006e
edited admin routes
Oct 20, 2024
468bddd
fixed lint errors
Oct 20, 2024
e0c9ca6
Merge pull request #56 from CMU-17313Q/auto-test-us2 into sprint2 bra…
galishaq Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions public/openapi/read/admin/bug-archive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.0.0
info:
title: Bug Archive API
version: 1.0.0
paths:
/api/admin/dashboard/bug-archive:
get:
summary: Retrieve the bug archive
responses:
'200':
description: A list of bugs in the archive
content:
application/json:
schema:
type: object
properties:
archive:
type: array
items:
type: object
properties:
title:
type: string
description:
type: string
submittedBy:
type: string
dateSubmitted:
type: string
format: date
'400':
description: Bad request
'500':
description: Internal server error
52 changes: 52 additions & 0 deletions public/src/admin/dashboard/bug-archive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

define('admin/dashboard/bug-archive', ['hooks'], (hooks) => {
const ACP = {};

ACP.init = () => {
// Fetch the bug data and update the table
ACP.updateTable();
hooks.onPage('action:admin.dashboard.updateGraph', ACP.updateTable);

// Add event listener for the button click
const submitButton = document.getElementById('submit-bug-feedback');
if (submitButton) {
submitButton.addEventListener('click', () => {
ACP.updateTable();
});
} else {
console.error('Submit button not found');
}
};

ACP.updateTable = () => {
if (window.fetch) {
const url = `${config.relative_path}/api/admin/get-bug-archive`;
fetch(url, { credentials: 'include' })
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((payload) => {
app.parseAndTranslate(ajaxify.data.template.name, 'bugs', payload, (html) => {
const tbodyEl = document.querySelector('.bugs-list tbody');
if (tbodyEl) {
tbodyEl.innerHTML = '';
tbodyEl.append(...html.map((idx, el) => el));
} else {
console.error('Table body element not found');
}
});
})
.catch((error) => {
console.error('Error fetching bug archive:', error);
});
} else {
console.error('Fetch API not supported');
}
};

return ACP;
});
40 changes: 40 additions & 0 deletions src/controllers/admin/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ dashboardController.get = async function (req, res) {
getLastRestart(),
user.isAdministrator(req.uid),
getPopularSearches(),
// getBugArchive()
// bug method
// this.submitBug(req, res)
]);
const version = nconf.get('version');

Expand Down Expand Up @@ -389,3 +392,40 @@ dashboardController.getSearches = async (req, res) => {
endDate: req.query.end ? validator.escape(String(req.query.end)) : null,
});
};

// In-memory storage for submitted bugs
const bugArchive = [];

// Submit Bug Handler
exports.submitBug = async (req, res) => {
const { title, description } = req.body;

if (!title || !description) {
return res.status(400).json({ message: 'Title and description are required' });
}

try {
const bug = { title, description, dateSubmitted: new Date().toISOString() };
bugArchive.push(bug);
res.status(200).json({ message: 'Bug submitted successfully' });
} catch (error) {
res.status(500).json({ message: 'Failed to submit bug', error });
}
};

// Get Bug Archive Handler
exports.getBugArchive = async (req, res) => {
console.log('im hereeeeeeeeeeee');
try {
// Render the 'bug-archive' template with the in-memory bug data
res.render('admin/dashboard/bug-archive', {
archive: bugArchive,
});
} catch (err) {
// Handle any errors that occur during the retrieval process
res.status(500).send(err.message);
}
};



28 changes: 28 additions & 0 deletions src/routes/admin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const helpers = require('./helpers');
// const { csrfSynchronisedProtection } = require('../middleware/csrf');

module.exports = function (app, name, middleware, controllers) {
const middlewares = [middleware.pluginHooks];
Expand All @@ -12,6 +13,8 @@ module.exports = function (app, name, middleware, controllers) {
helpers.setupAdminPageRoute(app, `/${name}/dashboard/users`, middlewares, controllers.admin.dashboard.getUsers);
helpers.setupAdminPageRoute(app, `/${name}/dashboard/topics`, middlewares, controllers.admin.dashboard.getTopics);
helpers.setupAdminPageRoute(app, `/${name}/dashboard/searches`, middlewares, controllers.admin.dashboard.getSearches);
// route to the admin dashboard / bug archive button
helpers.setupAdminPageRoute(app, `/${name}/dashboard/bug-archive`, middlewares, controllers.admin.dashboard.getBugArchive);

helpers.setupAdminPageRoute(app, `/${name}/manage/categories`, middlewares, controllers.admin.categories.getAll);
helpers.setupAdminPageRoute(app, `/${name}/manage/categories/:category_id`, middlewares, controllers.admin.categories.get);
Expand Down Expand Up @@ -61,12 +64,25 @@ module.exports = function (app, name, middleware, controllers) {


function apiRoutes(router, name, middleware, controllers) {
// Define the endpoint for fetching the bug archive
router.get(`/api/${name}/get-bug-archive`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.dashboard.getBugArchive));

// Define the endpoint for submitting bugs
router.post(`/api/${name}/submit-bug`, [], helpers.tryRoute(controllers.admin.dashboard.submitBug));
router.get(`/api/${name}/submit-bug`, [], helpers.tryRoute(controllers.admin.dashboard.submitBug));


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));
router.get(`/api/${name}/groups/:groupname/csv`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.groups.getCSV));
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-archive`, middleware.ensureLoggedIn,
// helpers.tryRoute(controllers.admin.dashboard.getBugArchive));
// router.post(`/api/${name}/submit-bug`, helpers.tryRoute(controllers.admin.dashboard.submitBug));
// router.get(`/api/${name}/submit-bug`, helpers.tryRoute(controllers.admin.dashboard.submitBug));

const multipart = require('connect-multiparty');
const multipartMiddleware = multipart();

Expand All @@ -80,4 +96,16 @@ function apiRoutes(router, name, middleware, controllers) {
router.post(`/api/${name}/uploadOgImage`, middlewares, helpers.tryRoute(controllers.admin.uploads.uploadOgImage));
router.post(`/api/${name}/upload/file`, middlewares, helpers.tryRoute(controllers.admin.uploads.uploadFile));
router.post(`/api/${name}/uploadDefaultAvatar`, middlewares, helpers.tryRoute(controllers.admin.uploads.uploadDefaultAvatar));

// Define the endpoint for submitting bugs
// router.post(`/api/${name}/submit-bug`, middlewares, helpers.tryRoute(controllers.admin.dashboard.submitBug));

// router.post(`/api/${name}/settings`, middleware.ensureLoggedIn, helpers.tryRoute(controllers.admin.settings.set));

// Define the endpoint for fetching the bug archive
// router.get(`/api/${name}/get-bug-archive`,
// middlewares, helpers.tryRoute(controllers.admin.dashboard.getBugArchive));
// router.get(`/api/${name}/get-bug-archive`, middlewares, helpers.tryRoute(controllers.admin.getConfig));
}


Loading
Loading