diff --git a/app/controllers/ingredients_controller.rb b/app/controllers/ingredients_controller.rb index 74d0a85..1bd12b4 100644 --- a/app/controllers/ingredients_controller.rb +++ b/app/controllers/ingredients_controller.rb @@ -223,6 +223,9 @@ class IngredientsController < ApplicationController if filters[:name].present? ingredients = ingredients.where("name LIKE ?", "%#{filters[:name]}%") end + if filters[:visibility].present? + ingredients = ingredients.where(hidden: filters[:visibility] == "1" ? false : true) + end ingredients end end diff --git a/app/helpers/ingredients_helper.rb b/app/helpers/ingredients_helper.rb index 7bd404b..94cdc17 100644 --- a/app/helpers/ingredients_helper.rb +++ b/app/helpers/ingredients_helper.rb @@ -14,6 +14,11 @@ module IngredientsHelper options_for_select(options, disabled: disabled) end + def visibility_options(selected) + options = [["all", nil], ["visible", 1], ["hidden", 0]] + options_for_select(options, selected) + end + def unit_options @project.units.map do |u| [u.shortname, u.id] diff --git a/app/views/ingredients/_filters.html.erb b/app/views/ingredients/_filters.html.erb index 1fbea5f..fe492d4 100644 --- a/app/views/ingredients/_filters.html.erb +++ b/app/views/ingredients/_filters.html.erb @@ -1,21 +1,26 @@
<%= l(:label_filter_plural) %> <%= form_tag url, id: 'filters_form', method: :get, remote: true do %> - +
- + -
<%= text_field_tag 'filters[name]', session[:filters][:name], - placeholder: 'name filter' %> + placeholder: 'name' %> + + <%= select_tag 'filters[visibility]', + visibility_options(session[:filters][:visibility]), + :onchange => '$("#filters_form").submit(); return false;' %> + <%= link_to l(:button_apply), '#', :class => "icon icon-checked", :onclick => '$("#filters_form").submit(); return false;' %> + <%= link_to l(:button_clear), '#', :class => "icon icon-reload", - :onclick => '$("#filters_form input").val(""); $("#filters_form").submit(); - return false;' %> + :onclick => '$("#filters_form input, #filters_form select").val(""); + $("#filters_form").submit(); return false;' %>
diff --git a/app/views/ingredients/_list.html.erb b/app/views/ingredients/_list.html.erb index 350ead2..766b161 100644 --- a/app/views/ingredients/_list.html.erb +++ b/app/views/ingredients/_list.html.erb @@ -1,4 +1,4 @@ -<% if @ingredients.many? %> +<% if @ingredients.any? { |i| i.persisted? } %> diff --git a/app/views/quantities/_list.html.erb b/app/views/quantities/_list.html.erb index 2a1bb3f..6061275 100644 --- a/app/views/quantities/_list.html.erb +++ b/app/views/quantities/_list.html.erb @@ -1,4 +1,4 @@ -<% if @quantities.many? %> +<% if @quantities.any? { |q| q.persisted? } %>
diff --git a/app/views/sources/index.html.erb b/app/views/sources/index.html.erb index fef940a..4ba91dc 100644 --- a/app/views/sources/index.html.erb +++ b/app/views/sources/index.html.erb @@ -23,7 +23,7 @@

<%= t ".heading" %>

-<% if @sources.many? %> +<% if @sources.any? { |s| s.persisted? } %>
diff --git a/app/views/units/index.html.erb b/app/views/units/index.html.erb index bde47ad..531ea0b 100644 --- a/app/views/units/index.html.erb +++ b/app/views/units/index.html.erb @@ -23,7 +23,7 @@

<%= t ".heading" %>

-<% if @units.many? %> +<% if @units.any? { |u| u.persisted? } %>
diff --git a/assets/stylesheets/body_tracking.css b/assets/stylesheets/body_tracking.css index e5e30bb..da09caf 100644 --- a/assets/stylesheets/body_tracking.css +++ b/assets/stylesheets/body_tracking.css @@ -15,6 +15,7 @@ table.list td.value { white-space: nowrap; max-width: 1px; } +fieldset#filters table.filter td {padding-left: 8px;} .icon-move-left { background-image: url(../images/1leftarrow.png); } .icon-move-right { background-image: url(../images/1rightarrow.png); }