This commit is contained in:
parent
f44b0e217a
commit
6171a968c1
@ -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,
|
||||
});
|
||||
};
|
||||
|
@ -11,8 +11,10 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="search-results" class="row">
|
||||
{% 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>
|
||||
@ -32,6 +34,33 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
</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 %}
|
||||
|
Loading…
Reference in New Issue
Block a user