Updated search page to consolidate results into one list

This commit is contained in:
Gregory Ballantine 2022-12-17 23:43:26 -05:00
parent 421539f38c
commit 5139d8b492
4 changed files with 15 additions and 17 deletions

View File

@ -2,6 +2,10 @@ class Item < Sequel::Model
one_to_many :item_comments one_to_many :item_comments
def getLink()
return "/item/#{self.id}"
end
def type_selected?(option) def type_selected?(option)
if self.type == option if self.type == option
return 'selected' return 'selected'

View File

@ -2,4 +2,8 @@ class License < Sequel::Model
one_to_many :license_comments one_to_many :license_comments
def getLink()
return "/license/#{self.id}"
end
end end

View File

@ -4,10 +4,11 @@ namespace '/search' do
items = Item.where(Sequel.ilike(:name, "%#{search_parameter}%")).all() items = Item.where(Sequel.ilike(:name, "%#{search_parameter}%")).all()
licenses = License.where(Sequel.ilike(:name, "%#{search_parameter}%")).all() licenses = License.where(Sequel.ilike(:name, "%#{search_parameter}%")).all()
results = items.concat(licenses)
erb :'search/list', :locals => { erb :'search/list', :locals => {
:title => 'Search Results', :title => 'Search Results',
:items => items, :results => results,
:licenses => licenses,
:query => search_parameter :query => search_parameter
} }
end end

View File

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