1
0

Renamed Ingredient -> Food

Ingredient is now part of composition (meal/recipe/dish)
This commit is contained in:
cryptogopher
2020-04-14 19:44:19 +02:00
parent c3010a70e8
commit 8e8160c41a
46 changed files with 204 additions and 199 deletions

View File

@@ -1,6 +0,0 @@
<% if User.current.allowed_to?(:manage_common, @project) %>
<%= link_to t(".link_import_ingredients"), '#', class: 'icon icon-multiple',
onclick: '$("#import-ingredients").show(); $("#filename").focus(); return false;' %>
<%= link_to t(".link_new_ingredient"), new_project_ingredient_path(@project, view: view),
{remote: true, class: 'icon icon-add'} %>
<% end %>

View File

@@ -1,15 +0,0 @@
<%= labelled_form_for @ingredient,
url: ingredient_path(@ingredient, view: view),
method: :patch, remote: true,
html: {id: 'ingredient-edit-form', name: 'ingredient-edit-form'} do |f| %>
<%= render partial: 'ingredients/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 %>

View File

@@ -1,51 +0,0 @@
<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[:i_filters][:name], placeholder: 'name' %>
</td>
<td>
<%= select_tag 'visibility', visibility_options(session[:i_filters][:visibility]),
prompt: t('.visibility_prompt'), onchange: '$("#filters-form").submit();' %>
</td>
<td style="width:100%;">
<%= text_field_tag 'formula[code]', session[:i_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>

View File

@@ -1,72 +0,0 @@
<%= error_messages_for @ingredient %>
<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>
<% @ingredient.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: (@ingredient.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 %>

View File

@@ -1,21 +0,0 @@
<div id="import-ingredients" style="display:none;">
<h2><%= t ".heading_import_ingredients" %></h2>
<%= form_tag import_project_ingredients_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-ingredients").hide(); return false;' %>
<% end %>
<hr>
</div>

View File

@@ -1,45 +0,0 @@
<%= render partial: 'ingredients/filters',
locals: {url: filter_project_ingredients_path(@project, view: :index)} %>
<% if @ingredients.any? { |i| i.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>
<% @ingredients.each do |i| %>
<% next if i.new_record? %>
<tr id="ingredient-<%= i.id %>"
class="ingredient primary<%= ' hidden' if i.hidden %>">
<td class="name ellipsible">
<%= link_to '', toggle_ingredient_path(i), {
remote: true,
method: :post,
class: "icon icon-eye"
} %>
<%= i.name %>
</td>
<td class="notes ellipsible"><%= i.notes %></td>
<td class="reference value"><%= i.ref_amount %> [<%= i.ref_unit.shortname %>]</td>
<td class="group"><%= i.group %></td>
<td class="source">
<%= i.source.name if i.source.present? %>
<%= ", #{i.source_ident}" if i.source_ident.present? %>
</td>
<td class="action unwrappable"><%= action_links(i, :index) %></td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>

View File

@@ -1,18 +0,0 @@
<h2><%= t ".heading_new_ingredient" %></h2>
<%= labelled_form_for @ingredient,
url: project_ingredients_path(@project, view: view),
remote: true,
html: {id: 'new-ingredient-form', name: 'new-ingredient-form'} do |f| %>
<%= render partial: 'ingredients/form', locals: {f: f} %>
<div class="tabular">
<p>
<%= submit_tag l(:button_create) %>
<%= link_to l(:button_cancel), "#",
onclick: '$("#new-ingredient").empty(); return false;' %>
</p>
</div>
<% end %>
<hr>

View File

@@ -1,85 +0,0 @@
<%= render partial: 'ingredients/filters',
locals: {url: filter_project_ingredients_path(@project, view: :nutrients)} %>
<% if @ingredients.any? %>
<%= render partial: 'ingredients/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_ingredients_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>
<% @ingredients.each_with_index do |i, index| %>
<% row_class = "ingredient#{' hidden' if i.hidden} #{cycle('odd', 'even')}" %>
<tr id="ingredient-<%= i.id %>" class="primary <%= row_class %>">
<td class="name ellipsible" style="cursor: pointer;"
onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', '.ingredient').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= i.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(i, :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', '.ingredient').toggle(); return false;">
<span class="icon icon-bullet-open"><%= i.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(i, :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 %>

View File

@@ -1,17 +0,0 @@
<fieldset id="options" class="collapsible">
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
<div>
<%= form_tag toggle_column_project_ingredients_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>

View File

@@ -1,6 +0,0 @@
$('#new-ingredient').empty();
<% if params[:view] == 'index' %>
$('#ingredients').html('<%= j render partial: 'ingredients/index' %>');
<% else %>
$('#nutrients').html('<%= j render partial: 'ingredients/nutrients' %>');
<% end %>

View File

@@ -1,3 +0,0 @@
<% if @ingredient.destroyed? %>
$('tr[id=ingredient-<%= @ingredient.id %>]').nextUntil('tr.primary').addBack().remove();
<% end %>

View File

@@ -1,8 +0,0 @@
$('tr[id=ingredient-<%= @ingredient.id %>]').nextUntil('tr.primary', ':not(.ingredient)')
.remove();
var columns = $('table > thead > tr > th').length;
$('tr[id=ingredient-<%= @ingredient.id %>]').nextUntil('tr.primary').addBack().last().after(
'<tr><td class="form" colspan="'+columns+'"><div id="edit-ingredient">' +
'<%= j render partial: 'ingredients/edit_form', locals: {view: params[:view]} %>' +
'</div></td></tr>'
);

View File

@@ -1,15 +0,0 @@
<div class="contextual">
<%= link_to t(".heading_nutrient_view"), nutrients_project_ingredients_path(@project),
class: 'icon icon-stats' %>
<%= render partial: 'ingredients/contextual', locals: {view: :index} %>
</div>
<%= render partial: 'ingredients/import' %>
<div id="new-ingredient">
</div>
<h2><%= t ".heading" %></h2>
<div id='ingredients'>
<%= render partial: 'ingredients/index' %>
</div>

View File

@@ -1,5 +0,0 @@
<% if params[:view] == 'index' %>
$('#ingredients').html('<%= j render partial: 'ingredients/index' %>');
<% else %>
$('#nutrients').html('<%= j render partial: 'ingredients/nutrients' %>');
<% end %>

View File

@@ -1,2 +0,0 @@
$('#new-ingredient')
.html('<%= j render partial: 'ingredients/new_form', locals: {view: params[:view]} %>');

View File

@@ -1,15 +0,0 @@
<div class="contextual">
<%= link_to t(".heading_ingredient_list"), project_ingredients_path(@project),
class: 'icon icon-list' %>
<%= render partial: 'ingredients/contextual', locals: {view: :nutrients} %>
</div>
<%= render partial: 'ingredients/import' %>
<div id="new-ingredient">
</div>
<h2><%= t ".heading" %></h2>
<div id='nutrients'>
<%= render partial: 'ingredients/nutrients' %>
</div>

View File

@@ -1 +0,0 @@
$('#ingredients').html('<%= j render partial: 'ingredients/index' %>');

View File

@@ -1 +0,0 @@
$('#nutrients').html('<%= j render partial: 'ingredients/nutrients' %>');