Added a page to view info about an item
This commit is contained in:
		
							
								
								
									
										1
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								index.js
									
									
									
									
									
								
							@@ -26,6 +26,7 @@ const itemRoutes = require('./src/routes/item');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// register route handlers
 | 
					// register route handlers
 | 
				
			||||||
app.get('/', homeRoutes.getIndex);
 | 
					app.get('/', homeRoutes.getIndex);
 | 
				
			||||||
 | 
					app.get('/item/:id', itemRoutes.getItem);
 | 
				
			||||||
app.get('/item/add', itemRoutes.getAdd);
 | 
					app.get('/item/add', itemRoutes.getAdd);
 | 
				
			||||||
app.post('/item/add', itemRoutes.postAdd);
 | 
					app.post('/item/add', itemRoutes.postAdd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,17 @@
 | 
				
			|||||||
const db = require('../models');
 | 
					const db = require('../models');
 | 
				
			||||||
const Item = db.items;
 | 
					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
 | 
					// GET - /item/add
 | 
				
			||||||
exports.getAdd = async function (req, res) {
 | 
					exports.getAdd = async function (req, res) {
 | 
				
			||||||
  res.render('item/add.twig');
 | 
					  res.render('item/add.twig');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,7 +39,7 @@
 | 
				
			|||||||
    <tbody>
 | 
					    <tbody>
 | 
				
			||||||
      {% for item in inventory %}
 | 
					      {% for item in inventory %}
 | 
				
			||||||
        <tr>
 | 
					        <tr>
 | 
				
			||||||
          <td>{{ item.name }}</td>
 | 
					          <td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
 | 
				
			||||||
          <td>{{ item.manufacturer }}</td>
 | 
					          <td>{{ item.manufacturer }}</td>
 | 
				
			||||||
          <td>{{ item.type }}</td>
 | 
					          <td>{{ item.type }}</td>
 | 
				
			||||||
        </tr>
 | 
					        </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 %}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user