Renamed Ingredient -> Food
Ingredient is now part of composition (meal/recipe/dish)
This commit is contained in:
6
app/views/foods/_contextual.html.erb
Normal file
6
app/views/foods/_contextual.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<% if User.current.allowed_to?(:manage_common, @project) %>
|
||||
<%= link_to t(".link_import_foods"), '#', class: 'icon icon-multiple',
|
||||
onclick: '$("#import-foods").show(); $("#filename").focus(); return false;' %>
|
||||
<%= link_to t(".link_new_food"), new_project_food_path(@project, view: view),
|
||||
{remote: true, class: 'icon icon-add'} %>
|
||||
<% end %>
|
||||
15
app/views/foods/_edit_form.html.erb
Normal file
15
app/views/foods/_edit_form.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<%= labelled_form_for @food,
|
||||
url: food_path(@food, view: view),
|
||||
method: :patch, remote: true,
|
||||
html: {id: 'food-edit-form', name: 'food-edit-form'} do |f| %>
|
||||
|
||||
<%= render partial: 'foods/form', locals: {f: f} %>
|
||||
|
||||
<div class="tabular">
|
||||
<p>
|
||||
<%= submit_tag l(:button_save) %>
|
||||
<%= link_to l(:button_cancel), "#",
|
||||
onclick: '$(this).closest("tr").remove(); return false;' %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
51
app/views/foods/_filters.html.erb
Normal file
51
app/views/foods/_filters.html.erb
Normal file
@@ -0,0 +1,51 @@
|
||||
<fieldset id="filters" class="collapsible">
|
||||
<legend onclick="toggleFieldset(this);"><%= l(:label_filter_plural) %></legend>
|
||||
<div>
|
||||
<%= error_messages_for @formula_q %>
|
||||
|
||||
<%= form_tag url, id: 'filters-form', name: 'filters-form',
|
||||
method: :get, remote: true do %>
|
||||
|
||||
<table class="filter">
|
||||
<tr>
|
||||
<td>
|
||||
<%= text_field_tag 'name', session[:f_filters][:name], placeholder: 'name' %>
|
||||
</td>
|
||||
<td>
|
||||
<%= select_tag 'visibility', visibility_options(session[:f_filters][:visibility]),
|
||||
prompt: t('.visibility_prompt'), onchange: '$("#filters-form").submit();' %>
|
||||
</td>
|
||||
<td style="width:100%;">
|
||||
<%= text_field_tag 'formula[code]', session[:f_filters][:formula][:code],
|
||||
placeholder: 'conditional expression including nutrients', size: 40,
|
||||
style: 'box-sizing:border-box; width:100%;' %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to l(:button_apply), '#', class: "icon icon-checked",
|
||||
onclick: '$("#filters-form").submit(); return false;' %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to l(:button_clear), '#', class: "icon icon-reload",
|
||||
onclick: '$("#filters-form input, #filters-form select").val("");
|
||||
$("#filters-form").submit(); return false;' %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td style="padding-top:4px;">
|
||||
<%= label_tag do %>
|
||||
<%= hidden_field_tag 'formula[zero_nil]', 0 %>
|
||||
<%= check_box_tag 'formula[zero_nil]', 1,
|
||||
@formula_q ? @formula_q.formula.zero_nil : Formula.new.zero_nil %>
|
||||
<%= t 'quantities.form.zero_nil' %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
<%= submit_tag '', style: 'display:none;' %>
|
||||
<% end %>
|
||||
</div>
|
||||
</fieldset>
|
||||
72
app/views/foods/_form.html.erb
Normal file
72
app/views/foods/_form.html.erb
Normal file
@@ -0,0 +1,72 @@
|
||||
<%= error_messages_for @food %>
|
||||
|
||||
<div class="box tabular">
|
||||
<p><%= f.text_field :name, size: 40, required: true %></p>
|
||||
<p><%= f.text_area :notes, cols: 40, rows: 3, required: false,
|
||||
style: "width: 100%;" %></p>
|
||||
<div class="splitcontent">
|
||||
<div class="splitcontentleft">
|
||||
<p><%= f.select :group, group_options, required: true %></p>
|
||||
<p>
|
||||
<%= f.number_field :ref_amount, size: 8, required: true, min: 0,
|
||||
label: :field_reference %>
|
||||
<%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>
|
||||
</p>
|
||||
</div>
|
||||
<div class="splitcontentright">
|
||||
<p>
|
||||
<%= f.select :source_id, source_options,
|
||||
{required: false, include_blank: t('.null_source')} %>
|
||||
</p>
|
||||
<p><%= f.text_field :source_ident, size: 25, required: false %></p>
|
||||
</div>
|
||||
</div>
|
||||
<% @food.nutrients.each_with_index do |n, index| %>
|
||||
<%= f.fields_for 'nutrients_attributes', n, index: '' do |ff| %>
|
||||
<p class="nutrient">
|
||||
<%= ff.hidden_field :id %>
|
||||
<%= ff.select :quantity_id, quantity_options,
|
||||
{include_blank: true, required: true, label: (index > 0 ? '' : :field_nutrients)} %>
|
||||
<%= ff.number_field :amount, {size: 8, min: 0, step: :any, label: ''} %>
|
||||
<%= ff.select :unit_id, unit_options, {label: ''} %>
|
||||
<%= ff.hidden_field :_destroy %>
|
||||
<%= link_to t(".button_delete_nutrient"), '#',
|
||||
class: 'icon icon-del',
|
||||
style: (@food.nutrients.length > 1 ? "" : "display:none"),
|
||||
onclick: "deleteNutrient(); return false;" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<p>
|
||||
<%= link_to t(".button_new_nutrient"), '#', class: 'icon icon-add',
|
||||
onclick: 'newNutrient(); return false;' %>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<%= javascript_tag do %>
|
||||
function newNutrient() {
|
||||
var form = $(event.target).closest('form');
|
||||
var row = form.find('p.nutrient:visible:last');
|
||||
var new_row = row.clone().insertAfter(row);
|
||||
new_row.find('input[id$=__id], input[id$=__amount], select[id$=_quantity__id]').val('');
|
||||
new_row.find('select[id$=__unit_id]').val(row.find('select[id$=__unit_id]').val());
|
||||
new_row.find('input[id$=__destroy]').val('');
|
||||
new_row.find('label:first').hide();
|
||||
form.find('p.nutrient:visible a.icon-del').show();
|
||||
}
|
||||
|
||||
function deleteNutrient() {
|
||||
var form = $(event.target).closest('form');
|
||||
var row = $(event.target).closest('p.nutrient');
|
||||
if (row.find('input[id$=__id]').val()) {
|
||||
row.hide();
|
||||
row.find('input[id$=__destroy]').val('1');
|
||||
} else {
|
||||
row.remove();
|
||||
}
|
||||
form.find('p.nutrient:visible:first label:first').show();
|
||||
if (form.find('p.nutrient:visible').length <= 1) {
|
||||
form.find('p.nutrient:visible a.icon-del').hide();
|
||||
}
|
||||
}
|
||||
<% end %>
|
||||
20
app/views/foods/_import.html.erb
Normal file
20
app/views/foods/_import.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<div id="import-foods" style="display:none;">
|
||||
<h2><%= t ".heading_import_foods" %></h2>
|
||||
|
||||
<%= form_tag import_project_foods_path(@project),
|
||||
id: 'import-form', name: 'import-form', multipart: true do %>
|
||||
|
||||
<div class="box tabular">
|
||||
<p>
|
||||
<label><%= t ".label_import_select_csv_file" %></label>
|
||||
<%= file_field_tag 'file' %>
|
||||
</p>
|
||||
<p>
|
||||
<%= t ".import_hints" %>
|
||||
</p>
|
||||
</div>
|
||||
<%= submit_tag l(:button_import) %>
|
||||
<%= link_to l(:button_cancel), "#", onclick: '$("#import-foods").hide(); return false;' %>
|
||||
<% end %>
|
||||
<hr>
|
||||
</div>
|
||||
45
app/views/foods/_index.html.erb
Normal file
45
app/views/foods/_index.html.erb
Normal file
@@ -0,0 +1,45 @@
|
||||
<%= render partial: 'foods/filters',
|
||||
locals: {url: filter_project_foods_path(@project, view: :index)} %>
|
||||
|
||||
<% if @foods.any? { |f| f.persisted? } %>
|
||||
<%= error_messages_for @formula_q.formula if @formula_q %>
|
||||
|
||||
<table class="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:50%"><%= l(:field_name) %></th>
|
||||
<th><%= l(:field_notes) %></th>
|
||||
<th><%= l(:field_reference) %></th>
|
||||
<th><%= l(:field_group) %></th>
|
||||
<th><%= l(:field_source) %></th>
|
||||
<th style="width:5%"><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @foods.each do |f| %>
|
||||
<% next if f.new_record? %>
|
||||
<tr id="food-<%= f.id %>"
|
||||
class="food primary<%= ' hidden' if f.hidden %>">
|
||||
<td class="name ellipsible">
|
||||
<%= link_to '', toggle_food_path(f), {
|
||||
remote: true,
|
||||
method: :post,
|
||||
class: "icon icon-eye"
|
||||
} %>
|
||||
<%= f.name %>
|
||||
</td>
|
||||
<td class="notes ellipsible"><%= f.notes %></td>
|
||||
<td class="reference value"><%= f.ref_amount %> [<%= f.ref_unit.shortname %>]</td>
|
||||
<td class="group"><%= f.group %></td>
|
||||
<td class="source">
|
||||
<%= f.source.name if f.source.present? %>
|
||||
<%= ", #{f.source_ident}" if f.source_ident.present? %>
|
||||
</td>
|
||||
<td class="action unwrappable"><%= action_links(f, :index) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
18
app/views/foods/_new_form.html.erb
Normal file
18
app/views/foods/_new_form.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<h2><%= t ".heading_new_food" %></h2>
|
||||
|
||||
<%= labelled_form_for @food,
|
||||
url: project_foods_path(@project, view: view),
|
||||
remote: true,
|
||||
html: {id: 'new-food-form', name: 'new-food-form'} do |f| %>
|
||||
|
||||
<%= render partial: 'foods/form', locals: {f: f} %>
|
||||
|
||||
<div class="tabular">
|
||||
<p>
|
||||
<%= submit_tag l(:button_create) %>
|
||||
<%= link_to l(:button_cancel), "#",
|
||||
onclick: '$("#new-food").empty(); return false;' %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
<hr>
|
||||
85
app/views/foods/_nutrients.html.erb
Normal file
85
app/views/foods/_nutrients.html.erb
Normal file
@@ -0,0 +1,85 @@
|
||||
<%= render partial: 'foods/filters',
|
||||
locals: {url: filter_project_foods_path(@project, view: :nutrients)} %>
|
||||
|
||||
<% if @foods.any? %>
|
||||
<%= render partial: 'foods/options' %>
|
||||
|
||||
<% formulas = @quantities.map { |q| q.formula } %>
|
||||
<% formulas.unshift(@formula_q.formula) if @formula_q %>
|
||||
<%= error_messages_for *formulas %>
|
||||
|
||||
<table class="nutrients list odd-even">
|
||||
<thead>
|
||||
<tr>
|
||||
<% total_width = 4 + @quantities.length %>
|
||||
<th style="width:<%= 3 * 100/total_width%>%"><%= l(:field_name) %></th>
|
||||
<% @quantities.each do |q| %>
|
||||
<th style="width:<%= 100/total_width %>%" class="closable ellipsible">
|
||||
<div style="float:right;position:relative;">
|
||||
<%= link_to '',
|
||||
toggle_column_project_foods_path(@project, quantity_id: q.id),
|
||||
{class: "icon icon-close", method: :post, remote: true} %>
|
||||
</div>
|
||||
<%= q.name %>
|
||||
</th>
|
||||
<% end %>
|
||||
<th style="width:<%= 100/total_width %>%"><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @foods.each_with_index do |f, index| %>
|
||||
<% row_class = "food#{' hidden' if f.hidden} #{cycle('odd', 'even')}" %>
|
||||
<tr id="food-<%= f.id %>" class="primary <%= row_class %>">
|
||||
<td class="name ellipsible" style="cursor: pointer;"
|
||||
onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', '.food').toggle(); return false;">
|
||||
<span class="icon icon-bullet-closed"><%= f.name %></span>
|
||||
</td>
|
||||
<% @requested_n[index].each do |*, value| %>
|
||||
<td class="primary value ellipsible"><%= format_value(value) %></td>
|
||||
<% end %>
|
||||
<td class="action unwrappable"><%= action_links(f, :nutrients) %></td>
|
||||
</tr>
|
||||
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
<% if @quantities.length > 0
|
||||
rows = (@extra_n[index].length - 1) / @quantities.length + 2
|
||||
else
|
||||
rows = 1
|
||||
end %>
|
||||
<td rowspan="<%= rows %>" class="name ellipsible" style="cursor: pointer;"
|
||||
onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', '.food').toggle(); return false;">
|
||||
<span class="icon icon-bullet-open"><%= f.name %></span>
|
||||
</td>
|
||||
<% @requested_n[index].each do |q, value| %>
|
||||
<td class="primary quantity ellipsible">
|
||||
<%= q.name %>
|
||||
<p class="value"><%= format_value(value) %></p>
|
||||
</td>
|
||||
<% end %>
|
||||
<td rowspan="<%= rows %>" class="action unwrappable">
|
||||
<%= action_links(f, :nutrients) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% next unless @quantities.length > 0 %>
|
||||
<% @extra_n[index].each_slice(@quantities.length) do |values| %>
|
||||
<tr class="extra <%= row_class %>" style="display:none">
|
||||
<% values.each do |q, value| %>
|
||||
<td class="extra quantity ellipsible">
|
||||
<%= q.name if value %>
|
||||
<p class="value"><%= format_value(value) %></p>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if @quantities.length > values.length %>
|
||||
<td class="space" colspan="<%= @quantities.length-values.length %>"></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
17
app/views/foods/_options.html.erb
Normal file
17
app/views/foods/_options.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<fieldset id="options" class="collapsible">
|
||||
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
||||
<div>
|
||||
<%= form_tag toggle_column_project_foods_path(@project),
|
||||
id: 'toggle-column-form', name: 'toggle-column-form',
|
||||
method: :post, remote: true do %>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:100%"></td>
|
||||
<td><%= select_tag 'quantity_id', toggle_column_options %></td>
|
||||
<td><%= submit_tag l(:button_add) %></td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
</div>
|
||||
</fieldset>
|
||||
6
app/views/foods/create.js.erb
Normal file
6
app/views/foods/create.js.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
$('#new-food').empty();
|
||||
<% if params[:view] == 'index' %>
|
||||
$('#foods').html('<%= j render partial: 'foods/index' %>');
|
||||
<% else %>
|
||||
$('#nutrients').html('<%= j render partial: 'foods/nutrients' %>');
|
||||
<% end %>
|
||||
3
app/views/foods/destroy.js.erb
Normal file
3
app/views/foods/destroy.js.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<% if @food.destroyed? %>
|
||||
$('tr[id=food-<%= @food.id %>]').nextUntil('tr.primary').addBack().remove();
|
||||
<% end %>
|
||||
8
app/views/foods/edit.js.erb
Normal file
8
app/views/foods/edit.js.erb
Normal file
@@ -0,0 +1,8 @@
|
||||
$('tr[id=food-<%= @food.id %>]').nextUntil('tr.primary', ':not(.food)')
|
||||
.remove();
|
||||
var columns = $('table > thead > tr > th').length;
|
||||
$('tr[id=food-<%= @food.id %>]').nextUntil('tr.primary').addBack().last().after(
|
||||
'<tr><td class="form" colspan="'+columns+'"><div id="edit-food">' +
|
||||
'<%= j render partial: 'foods/edit_form', locals: {view: params[:view]} %>' +
|
||||
'</div></td></tr>'
|
||||
);
|
||||
15
app/views/foods/index.html.erb
Normal file
15
app/views/foods/index.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<div class="contextual">
|
||||
<%= link_to t(".heading_nutrient_view"), nutrients_project_foods_path(@project),
|
||||
class: 'icon icon-stats' %>
|
||||
<%= render partial: 'foods/contextual', locals: {view: :index} %>
|
||||
</div>
|
||||
|
||||
<%= render partial: 'foods/import' %>
|
||||
|
||||
<div id="new-food">
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<div id='foods'>
|
||||
<%= render partial: 'foods/index' %>
|
||||
</div>
|
||||
5
app/views/foods/index.js.erb
Normal file
5
app/views/foods/index.js.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
<% if params[:view] == 'index' %>
|
||||
$('#foods').html('<%= j render partial: 'foods/index' %>');
|
||||
<% else %>
|
||||
$('#nutrients').html('<%= j render partial: 'foods/nutrients' %>');
|
||||
<% end %>
|
||||
2
app/views/foods/new.js.erb
Normal file
2
app/views/foods/new.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
$('#new-food')
|
||||
.html('<%= j render partial: 'foods/new_form', locals: {view: params[:view]} %>');
|
||||
15
app/views/foods/nutrients.html.erb
Normal file
15
app/views/foods/nutrients.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<div class="contextual">
|
||||
<%= link_to t(".heading_food_list"), project_foods_path(@project),
|
||||
class: 'icon icon-list' %>
|
||||
<%= render partial: 'foods/contextual', locals: {view: :nutrients} %>
|
||||
</div>
|
||||
|
||||
<%= render partial: 'foods/import' %>
|
||||
|
||||
<div id="new-food">
|
||||
</div>
|
||||
|
||||
<h2><%= t ".heading" %></h2>
|
||||
<div id='nutrients'>
|
||||
<%= render partial: 'foods/nutrients' %>
|
||||
</div>
|
||||
1
app/views/foods/toggle.js.erb
Normal file
1
app/views/foods/toggle.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$('#foods').html('<%= j render partial: 'foods/index' %>');
|
||||
1
app/views/foods/toggle_column.js.erb
Normal file
1
app/views/foods/toggle_column.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$('#nutrients').html('<%= j render partial: 'foods/nutrients' %>');
|
||||
Reference in New Issue
Block a user