improved item information page
This commit is contained in:
parent
b785dd8ca7
commit
a7864b3c11
22
src/frontend/itemInfo.eta.html
Normal file
22
src/frontend/itemInfo.eta.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<%~ E.includeFile("partials/head.eta.html", {"title": "Item Info"}) %> <%~ E.includeFile("partials/controls.eta.html", {"active": "ItemInfo"}) %> <%~ E.includeFile("./partials/deleteModal.eta.html") %>
|
||||||
|
|
||||||
|
|
||||||
|
<h1><%= it.name %></h1>
|
||||||
|
<div class="container">
|
||||||
|
<p><strong>Comment:</strong> <%= it.comment %></p>
|
||||||
|
<p><strong>Category:</strong> <%= it.category.name %></p>
|
||||||
|
<p><strong>Amount:</strong> <%= it.amount %></p>
|
||||||
|
<p><strong>SKU:</strong> <%= it.SKU %></p>
|
||||||
|
<p><strong>Status: </strong><% if(it.status == "normal") { %>
|
||||||
|
|
||||||
|
<span class="badge text-bg-success"><%= it.status %></span>
|
||||||
|
<% } else if(it.status == "stolen") { %>
|
||||||
|
<span class="badge text-bg-danger"><%= it.status %></span>
|
||||||
|
<% } else if(it.status == "lost") { %>
|
||||||
|
<span class="badge text-bg-warning"><%= it.status %></span>
|
||||||
|
<% } else if(it.status == "borrowed") { %>
|
||||||
|
<span class="badge text-bg-info"><%= it.status %></span>
|
||||||
|
<% } %></p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<%~ E.includeFile("partials/controlsFoot.eta.html") %> <%~ E.includeFile("partials/foot.eta.html") %>
|
@ -2,6 +2,7 @@ import express from 'express';
|
|||||||
|
|
||||||
// Route imports
|
// Route imports
|
||||||
import skuRoute from './:id.js';
|
import skuRoute from './:id.js';
|
||||||
|
import skuRouteDash from './itemInfo.js'
|
||||||
import testRoute from './test.js';
|
import testRoute from './test.js';
|
||||||
import dashboardRoute from './dashboard.js';
|
import dashboardRoute from './dashboard.js';
|
||||||
import itemsRoute from './items.js';
|
import itemsRoute from './items.js';
|
||||||
@ -14,6 +15,7 @@ Router.route('/test').get(testRoute.get);
|
|||||||
Router.route('/items').get(itemsRoute.get);
|
Router.route('/items').get(itemsRoute.get);
|
||||||
|
|
||||||
Router.route('/:id(\\w{8})').get(skuRoute.get);
|
Router.route('/:id(\\w{8})').get(skuRoute.get);
|
||||||
|
Router.route('/s/:id').get(skuRouteDash.get);
|
||||||
|
|
||||||
Router.use('/manage', manage_routes);
|
Router.use('/manage', manage_routes);
|
||||||
|
|
||||||
|
37
src/routes/frontend/itemInfo.ts
Normal file
37
src/routes/frontend/itemInfo.ts
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import { Request, Response } from 'express';
|
||||||
|
import { prisma, __path } from '../../index.js';
|
||||||
|
import * as Eta from 'eta';
|
||||||
|
|
||||||
|
function get(req: Request, res: Response) {
|
||||||
|
// Get data from database using sku from url.
|
||||||
|
prisma.item
|
||||||
|
.findFirst({
|
||||||
|
where: {
|
||||||
|
SKU: req.params.id
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
SKU: true,
|
||||||
|
name: true,
|
||||||
|
comment: true,
|
||||||
|
amount: true,
|
||||||
|
status: true,
|
||||||
|
// Get category name from relation.
|
||||||
|
category: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((item) => {
|
||||||
|
if (item) {
|
||||||
|
Eta.renderFile(__path + '/src/frontend/itemInfo.eta.html', item).then((html) => {
|
||||||
|
res.send(html);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.send('Item not found');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default { get };
|
@ -72,7 +72,7 @@ function handleSearchChange(e) {
|
|||||||
let htmlResult = ""
|
let htmlResult = ""
|
||||||
result.forEach(element => {
|
result.forEach(element => {
|
||||||
console.log(element);
|
console.log(element);
|
||||||
htmlResult += `<a href="/${element.SKU}">${element.name}</a><br>`
|
htmlResult += `<a href="/s/${element.SKU}">${element.name}</a><br>`
|
||||||
});
|
});
|
||||||
|
|
||||||
autocompleteBox.innerHTML = htmlResult;
|
autocompleteBox.innerHTML = htmlResult;
|
||||||
|
Loading…
Reference in New Issue
Block a user