Added a page to view info about an item
This commit is contained in:
parent
1b46e7c3fb
commit
4a0241dd2b
1
index.js
1
index.js
@ -26,6 +26,7 @@ const itemRoutes = require('./src/routes/item');
|
||||
|
||||
// register route handlers
|
||||
app.get('/', homeRoutes.getIndex);
|
||||
app.get('/item/:id', itemRoutes.getItem);
|
||||
app.get('/item/add', itemRoutes.getAdd);
|
||||
app.post('/item/add', itemRoutes.postAdd);
|
||||
|
||||
|
@ -1,6 +1,17 @@
|
||||
const db = require('../models');
|
||||
const Item = db.items;
|
||||
|
||||
// GET - /item/{name}
|
||||
exports.getItem = async function (req, res) {
|
||||
const item = await Item.findAll({ where: {
|
||||
id: req.params.id,
|
||||
}});
|
||||
|
||||
res.render('item/view.twig', {
|
||||
item: item[0],
|
||||
});
|
||||
};
|
||||
|
||||
// GET - /item/add
|
||||
exports.getAdd = async function (req, res) {
|
||||
res.render('item/add.twig');
|
||||
|
@ -39,7 +39,7 @@
|
||||
<tbody>
|
||||
{% for item in inventory %}
|
||||
<tr>
|
||||
<td>{{ item.name }}</td>
|
||||
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
|
||||
<td>{{ item.manufacturer }}</td>
|
||||
<td>{{ item.type }}</td>
|
||||
</tr>
|
||||
|
36
views/item/view.twig
Normal file
36
views/item/view.twig
Normal file
@ -0,0 +1,36 @@
|
||||
{% extends 'layout.twig' %}
|
||||
|
||||
{% block title %}{{ item.name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<!-- page header -->
|
||||
<header class="row">
|
||||
<div class="columns twelve">
|
||||
<h1>{{ item.name }}</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- item information -->
|
||||
<section class="row">
|
||||
<table class="columns twelve">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Manufacturer</th>
|
||||
<th>Type</th>
|
||||
<th>Created date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ item.name }}</td>
|
||||
<td>{{ item.manufacturer }}</td>
|
||||
<td>{{ item.type }}</td>
|
||||
<td>{{ item.createdAt | date("m/d/Y h:i:s A") }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user