Added a search page
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2024-05-21 10:20:54 -04:00
parent 4cfffbd219
commit 43e70e243c
3 changed files with 65 additions and 1 deletions

27
src/routes/search.js Normal file
View File

@ -0,0 +1,27 @@
const db = require('../models');
const Item = db.items;
const License = db.licenses;
// GET - /search
exports.getIndex = async function(req, res) {
// decode URL search query
let query = req.params.query;
// fetch inventory items from database based on search query
const results = await Item.find({
where: {
name: {
[Op.like]: query,
}
},
limit: 10,
order: [
['updatedAt', 'DESC'],
],
});
res.render('search.twig', {
query: query,
results: results,
});
};

View File

@ -27,7 +27,7 @@
<ul>
<li>
<form id="search-form" action="/search" method="GET">
<input type="text" name="search" placeholder="enter a search query...">
<input type="text" name="query" placeholder="enter a search query...">
</form>
<button id="search-button" type="submit" for="search-form"><i class="fa-solid fa-magnifying-glass"></i></button>

37
views/search.twig Normal file
View File

@ -0,0 +1,37 @@
{% extends 'layout.twig' %}
{% block title %}Search{% endblock %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>Searching for "{{ query }}"</h1>
</div>
</header>
<section id="search-results" class="row">
<div class="columns twelve">
<table class="u-full-width">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for item in results %}
<tr>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.type }}</td>
<td>{{ item.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
{% endblock %}