Added Ingredient visibility filter
Fixed index display (many? -> any? persisted)
This commit is contained in:
parent
05c79782f5
commit
3294689cb4
@ -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
|
||||
|
@ -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]
|
||||
|
@ -1,21 +1,26 @@
|
||||
<fieldset id="filters" class="collapsible">
|
||||
<legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
|
||||
<%= form_tag url, id: 'filters_form', method: :get, remote: true do %>
|
||||
<table>
|
||||
<table class="filter">
|
||||
<tr>
|
||||
<td style="width:100%;"></td>
|
||||
<td>
|
||||
<%= text_field_tag 'filters[name]', session[:filters][:name],
|
||||
placeholder: 'name filter' %>
|
||||
placeholder: 'name' %>
|
||||
</td>
|
||||
<td style="padding-left:8px;">
|
||||
<td>
|
||||
<%= select_tag 'filters[visibility]',
|
||||
visibility_options(session[:filters][:visibility]),
|
||||
:onchange => '$("#filters_form").submit(); return false;' %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to l(:button_apply), '#', :class => "icon icon-checked",
|
||||
:onclick => '$("#filters_form").submit(); return false;' %>
|
||||
</td>
|
||||
<td style="padding-left:8px;">
|
||||
<td>
|
||||
<%= 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;' %>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<% if @ingredients.many? %>
|
||||
<% if @ingredients.any? { |i| i.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<% if @quantities.many? %>
|
||||
<% if @quantities.any? { |q| q.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -23,7 +23,7 @@
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<% if @sources.many? %>
|
||||
<% if @sources.any? { |s| s.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -23,7 +23,7 @@
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<% if @units.many? %>
|
||||
<% if @units.any? { |u| u.persisted? } %>
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -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); }
|
||||
|
Reference in New Issue
Block a user