improved item information page

This commit is contained in:
Sören Oesterwind 2023-07-05 20:18:52 +02:00
parent b785dd8ca7
commit a7864b3c11
4 changed files with 62 additions and 1 deletions

View 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") %>

View File

@ -2,6 +2,7 @@ import express from 'express';
// Route imports
import skuRoute from './:id.js';
import skuRouteDash from './itemInfo.js'
import testRoute from './test.js';
import dashboardRoute from './dashboard.js';
import itemsRoute from './items.js';
@ -14,6 +15,7 @@ Router.route('/test').get(testRoute.get);
Router.route('/items').get(itemsRoute.get);
Router.route('/:id(\\w{8})').get(skuRoute.get);
Router.route('/s/:id').get(skuRouteDash.get);
Router.use('/manage', manage_routes);

View 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 };

View File

@ -72,7 +72,7 @@ function handleSearchChange(e) {
let htmlResult = ""
result.forEach(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;