1
0

Added Ingredient visibility filter

Fixed index display (many? -> any? persisted)
This commit is contained in:
cryptogopher 2019-11-02 19:30:52 +01:00
parent 05c79782f5
commit 3294689cb4
8 changed files with 24 additions and 10 deletions

View File

@ -223,6 +223,9 @@ class IngredientsController < ApplicationController
if filters[:name].present? if filters[:name].present?
ingredients = ingredients.where("name LIKE ?", "%#{filters[:name]}%") ingredients = ingredients.where("name LIKE ?", "%#{filters[:name]}%")
end end
if filters[:visibility].present?
ingredients = ingredients.where(hidden: filters[:visibility] == "1" ? false : true)
end
ingredients ingredients
end end
end end

View File

@ -14,6 +14,11 @@ module IngredientsHelper
options_for_select(options, disabled: disabled) options_for_select(options, disabled: disabled)
end end
def visibility_options(selected)
options = [["all", nil], ["visible", 1], ["hidden", 0]]
options_for_select(options, selected)
end
def unit_options def unit_options
@project.units.map do |u| @project.units.map do |u|
[u.shortname, u.id] [u.shortname, u.id]

View File

@ -1,21 +1,26 @@
<fieldset id="filters" class="collapsible"> <fieldset id="filters" class="collapsible">
<legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend> <legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
<%= form_tag url, id: 'filters_form', method: :get, remote: true do %> <%= form_tag url, id: 'filters_form', method: :get, remote: true do %>
<table> <table class="filter">
<tr> <tr>
<td style="width:100%;"></td> <td style="width:100%;"></td>
<td> <td>
<%= text_field_tag 'filters[name]', session[:filters][:name], <%= text_field_tag 'filters[name]', session[:filters][:name],
placeholder: 'name filter' %> placeholder: 'name' %>
</td> </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", <%= link_to l(:button_apply), '#', :class => "icon icon-checked",
:onclick => '$("#filters_form").submit(); return false;' %> :onclick => '$("#filters_form").submit(); return false;' %>
</td> </td>
<td style="padding-left:8px;"> <td>
<%= link_to l(:button_clear), '#', :class => "icon icon-reload", <%= link_to l(:button_clear), '#', :class => "icon icon-reload",
:onclick => '$("#filters_form input").val(""); $("#filters_form").submit(); :onclick => '$("#filters_form input, #filters_form select").val("");
return false;' %> $("#filters_form").submit(); return false;' %>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -1,4 +1,4 @@
<% if @ingredients.many? %> <% if @ingredients.any? { |i| i.persisted? } %>
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>

View File

@ -1,4 +1,4 @@
<% if @quantities.many? %> <% if @quantities.any? { |q| q.persisted? } %>
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>

View File

@ -23,7 +23,7 @@
</div> </div>
<h2><%= t ".heading" %></h2> <h2><%= t ".heading" %></h2>
<% if @sources.many? %> <% if @sources.any? { |s| s.persisted? } %>
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>

View File

@ -23,7 +23,7 @@
</div> </div>
<h2><%= t ".heading" %></h2> <h2><%= t ".heading" %></h2>
<% if @units.many? %> <% if @units.any? { |u| u.persisted? } %>
<table class="list"> <table class="list">
<thead> <thead>
<tr> <tr>

View File

@ -15,6 +15,7 @@ table.list td.value {
white-space: nowrap; white-space: nowrap;
max-width: 1px; max-width: 1px;
} }
fieldset#filters table.filter td {padding-left: 8px;}
.icon-move-left { background-image: url(../images/1leftarrow.png); } .icon-move-left { background-image: url(../images/1leftarrow.png); }
.icon-move-right { background-image: url(../images/1rightarrow.png); } .icon-move-right { background-image: url(../images/1rightarrow.png); }