Refactor routes and views for improved clarity and functionality
- Commented out console log in the home route to reduce clutter in logs. - Updated formatting and consistency in the sites route, including removing unused domain fetching functionality. - Added form action to the add-form view for submitting new sites, ensuring the input field is properly named for backend processing.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@ const sitesModel = new SiteModel();
|
|||||||
/* GET home page. */
|
/* GET home page. */
|
||||||
router.get('/', async function(req, res, next) {
|
router.get('/', async function(req, res, next) {
|
||||||
const sites = await sitesModel.getAll();
|
const sites = await sitesModel.getAll();
|
||||||
console.log('Sites:', sites);
|
// console.log('Sites:', sites);
|
||||||
res.render('index', { title: 'Playwright Testing Dashboard', sites: sites });
|
res.render('index', { title: 'Playwright Testing Dashboard', sites: sites });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const siteModel = new SiteModel();
|
|||||||
*
|
*
|
||||||
* Returns a list of all sites in JSON format.
|
* Returns a list of all sites in JSON format.
|
||||||
*/
|
*/
|
||||||
router.get('/', async function(req, res, next) {
|
router.get('/', async function (req, res, next) {
|
||||||
const sites = await siteModel.getAll();
|
const sites = await siteModel.getAll();
|
||||||
|
|
||||||
res.json(sites);
|
res.json(sites);
|
||||||
@@ -19,7 +19,7 @@ router.get('/', async function(req, res, next) {
|
|||||||
*
|
*
|
||||||
* Returns a specific site by its ID in JSON format.
|
* Returns a specific site by its ID in JSON format.
|
||||||
*/
|
*/
|
||||||
router.get('/:id', async function(req, res, next) {
|
router.get('/:id', async function (req, res, next) {
|
||||||
const siteId = req.params.id;
|
const siteId = req.params.id;
|
||||||
let site = null;
|
let site = null;
|
||||||
|
|
||||||
@@ -37,31 +37,6 @@ router.get('/:id', async function(req, res, next) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* GET site by domain name.
|
|
||||||
*
|
|
||||||
* Returns a specific site by its domain name in JSON format.
|
|
||||||
*/
|
|
||||||
router.get('/domain/:domain', async function(req, res, next) {
|
|
||||||
const domainName = req.params.domain;
|
|
||||||
let sites = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
sites = await siteModel.getByDomainName(domainName);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching site by domain name:', error);
|
|
||||||
return res.status(400).send('Error fetching site: ' + error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('Site found:', sites);
|
|
||||||
|
|
||||||
if (!sites || sites.length === 0) {
|
|
||||||
return res.status(404).send('Site not found');
|
|
||||||
} else {
|
|
||||||
res.json(sites[0]); // Return the first match
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST create a new site.
|
* POST create a new site.
|
||||||
*
|
*
|
||||||
@@ -69,7 +44,7 @@ router.get('/domain/:domain', async function(req, res, next) {
|
|||||||
*
|
*
|
||||||
* // TODO: Ability to add additional site properties (e.g., name, description)
|
* // TODO: Ability to add additional site properties (e.g., name, description)
|
||||||
*/
|
*/
|
||||||
router.post('/add', async function(req, res, next) {
|
router.post('/add', async function (req, res, next) {
|
||||||
const domain = req.body.domain;
|
const domain = req.body.domain;
|
||||||
let newSite = null;
|
let newSite = null;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<fieldset class="fieldset bg-base-100 rounded-box px-8 py-4 shadow-md">
|
<form action="/sites/add" method="POST" class="w-full">
|
||||||
<legend class="fieldset-legend h3">Start a new test</legend>
|
<fieldset class="fieldset bg-base-100 rounded-box px-8 py-4 shadow-md">
|
||||||
<div class="flex gap-0">
|
<legend class="fieldset-legend h3">Start a new test</legend>
|
||||||
<div class="w-fit m-0 p-0">
|
<div class="flex gap-0">
|
||||||
<input type="text" class="input w-full border-r-0 rounded-r-none" placeholder="Site/URL to test" />
|
<div class="w-fit m-0 p-0">
|
||||||
<p class="label">Add either single URL or link to sitemap</p>
|
<input type="text" class="input w-full border-r-0 rounded-r-none" name="domain" id="domain" placeholder="Site/URL to test" />
|
||||||
|
<p class="label">Add either single URL or link to sitemap</p>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-info">Test</button>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-info">Test</button>
|
</fieldset>
|
||||||
</div>
|
</form>
|
||||||
</fieldset>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user