Added an inventory search page

This commit is contained in:
Gregory Ballantine 2022-12-11 22:27:45 -05:00
parent 4c9d46f875
commit 421539f38c
5 changed files with 44 additions and 3 deletions

View File

@ -3,3 +3,5 @@ require_relative 'routes/index.rb'
require_relative 'routes/item.rb' require_relative 'routes/item.rb'
require_relative 'routes/license.rb' require_relative 'routes/license.rb'
require_relative 'routes/search.rb'

14
lib/routes/search.rb Normal file
View File

@ -0,0 +1,14 @@
namespace '/search' do
get '' do
search_parameter = params[:query]
items = Item.where(Sequel.ilike(:name, "%#{search_parameter}%")).all()
licenses = License.where(Sequel.ilike(:name, "%#{search_parameter}%")).all()
erb :'search/list', :locals => {
:title => 'Search Results',
:items => items,
:licenses => licenses,
:query => search_parameter
}
end
end

View File

@ -11,10 +11,10 @@
</head> </head>
<body> <body>
<!-- Main navigation --> <!-- Main navigation -->
<%= erb :'layout/navbar' %> <%= erb :'layout/navbar', :locals => locals %>
<!-- Inventory search/actions bar --> <!-- Inventory search/actions bar -->
<%= erb :'layout/actions' %> <%= erb :'layout/actions', :locals => locals %>
<div id="main-wrapper" class="container fluid card"> <div id="main-wrapper" class="container fluid card">
<%= yield %> <%= yield %>

View File

@ -2,7 +2,7 @@
<div class="row"> <div class="row">
<div class="six columns"> <div class="six columns">
<form action="/search" class="u-full-width"> <form action="/search" class="u-full-width">
<input id="search-field" class="u-full-width" type="text" placeholder="Search your inventory..." name="Search field"> <input id="search-field" class="u-full-width" type="text" placeholder="Search your inventory..." name="query" required <%= defined?(query) ? 'value="' + query + '"' : '' %>>
</form> </form>
</div> </div>
</div> </div>

25
views/search/list.erb Normal file
View File

@ -0,0 +1,25 @@
<div class="row">
<div class="twelve columns">
<h4>Matching hardware:</h4>
<% if items.length > 0 %>
<ul class="u-full-width">
<% items.each do |r| %>
<li><a href="/item/<%= r.id %>"><%= r.name %></a></li>
<% end %>
</ul>
<% else %>
<p>Sorry, nothing in your hardware inventory matches that search term.</p>
<% end %>
<h4>Matching licenses:</h4>
<% if licenses.length > 0 %>
<ul class="u-full-width">
<% licenses.each do |r| %>
<li><a href="/item/<%= r.id %>"><%= r.name %></a></li>
<% end %>
</ul>
<% else %>
<p>Sorry, nothing in your license inventory matches that search term.</p>
<% end %>
</div>
</div>