Added licenses to search page
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2024-05-21 10:33:07 -04:00
parent f44b0e217a
commit 6171a968c1
2 changed files with 65 additions and 22 deletions

View File

@ -9,7 +9,20 @@ exports.getSearch = async function(req, res) {
let query = req.query.query;
// fetch inventory items from database based on search query
const results = await Item.findAll({
const item_results = await Item.findAll({
where: {
name: {
[Op.like]: '%' + query + '%',
}
},
limit: 10,
order: [
['updatedAt', 'DESC'],
],
});
// fetch licenses from database based on search query
const license_results = await License.findAll({
where: {
name: {
[Op.like]: '%' + query + '%',
@ -23,6 +36,7 @@ exports.getSearch = async function(req, res) {
res.render('search.twig', {
query: query,
results: results,
item_results: item_results,
license_results: license_results,
});
};

View File

@ -11,8 +11,10 @@
</div>
</header>
{% if item_results|len > 0 %}
<section id="search-results" class="row">
<div class="columns twelve">
<h3>Hardware components:</h3>
<table class="u-full-width">
<thead>
<tr>
@ -22,7 +24,7 @@
</tr>
</thead>
<tbody>
{% for item in results %}
{% for item in item_results %}
<tr>
<td><a href="/item/{{ item.id }}">{{ item.name }}</a></td>
<td>{{ item.type }}</td>
@ -33,5 +35,32 @@
</table>
</div>
</section>
{% endif %}
{% if license_results|len > 0 %}
<section id="search-results" class="row">
<div class="columns twelve">
<h3>Software licenses:</h3>
<table class="u-full-width">
<thead>
<tr>
<th>Name</th>
<th>Vendor</th>
<th>Updated at</th>
</tr>
</thead>
<tbody>
{% for license in license_results %}
<tr>
<td><a href="/item/{{ license.id }}">{{ license.name }}</a></td>
<td>{{ license.manufacturer }}</td>
<td>{{ license.updatedAt | date("m/d/Y h:i:s A") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
{% endif %}
{% endblock %}