diff --git a/lib/routes.rb b/lib/routes.rb index 96c5f5b..55e4212 100644 --- a/lib/routes.rb +++ b/lib/routes.rb @@ -3,3 +3,5 @@ require_relative 'routes/index.rb' require_relative 'routes/item.rb' require_relative 'routes/license.rb' + +require_relative 'routes/search.rb' diff --git a/lib/routes/search.rb b/lib/routes/search.rb new file mode 100644 index 0000000..9741866 --- /dev/null +++ b/lib/routes/search.rb @@ -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 diff --git a/views/layout.erb b/views/layout.erb index ffbf137..89460f9 100644 --- a/views/layout.erb +++ b/views/layout.erb @@ -11,10 +11,10 @@ - <%= erb :'layout/navbar' %> + <%= erb :'layout/navbar', :locals => locals %> - <%= erb :'layout/actions' %> + <%= erb :'layout/actions', :locals => locals %>
<%= yield %> diff --git a/views/layout/actions.erb b/views/layout/actions.erb index c140d9c..1d1edb7 100644 --- a/views/layout/actions.erb +++ b/views/layout/actions.erb @@ -2,7 +2,7 @@
- + >
diff --git a/views/search/list.erb b/views/search/list.erb new file mode 100644 index 0000000..0a855c1 --- /dev/null +++ b/views/search/list.erb @@ -0,0 +1,25 @@ +
+
+

Matching hardware:

+ <% if items.length > 0 %> + + <% else %> +

Sorry, nothing in your hardware inventory matches that search term.

+ <% end %> + +

Matching licenses:

+ <% if licenses.length > 0 %> + + <% else %> +

Sorry, nothing in your license inventory matches that search term.

+ <% end %> +
+