1
0

Updated Ingredients to use ItemsWithQuantities

This commit is contained in:
cryptogopher
2019-12-29 15:12:05 +01:00
parent 61bd34fdc5
commit 20deb944c3
19 changed files with 125 additions and 226 deletions

View File

@@ -19,7 +19,7 @@
onchange: '$("#filters-form").submit();' %>
</td>
<td style="width:100%;">
<%= text_field_tag 'filters[nutrients]', session[:i_filters][:nutrients],
<%= text_field_tag 'filters[formula]', session[:i_filters][:formula],
placeholder: 'conditional expression including nutrients', size: 40,
style: 'box-sizing:border-box; width:100%;',
onblur: '$("#filters-form").submit(); return false;' %>

View File

@@ -32,9 +32,7 @@
<%= i.source.name if i.source.present? %>
<%= ", #{i.source_ident}" if i.source_ident.present? %>
</td>
<td class="action unwrappable">
<%= delete_link ingredient_path(i), {remote: true, data: {}} %>
</td>
<td class="action unwrappable"><%= action_links(i) %></td>
</tr>
<% end %>
</tbody>

View File

@@ -1,72 +0,0 @@
<%= render partial: 'ingredients/filters',
locals: {url: filter_nutrients_project_ingredients_path(@project)} %>
<% if @nutrients.any? %>
<%= render partial: 'ingredients/options' %>
<table class="nutrients list odd-even">
<thead>
<tr>
<% total_width = 3 + @quantities.length %>
<th style="width:<%= 3 * 100/total_width%>%"><%= l(:field_name) %></th>
<% @quantities.each do |q| %>
<th style="width:<%= 100/total_width %>%"><%= q.name %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @nutrients.each do |i, values| %>
<% 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', 'tr').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= i.name %></span>
</td>
<% values.each do |*, value| %>
<td class="primary value"><%= value %></td>
<% end %>
</tr>
<tr class="<%= row_class %>" style="display:none">
<td class="name" style="cursor: pointer;" onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', 'tr').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= i.name %></span>
</td>
<% values.each do |q_name, *| %>
<td class="primary quantity"><%= q_name %></td>
<% end %>
</tr>
<tr class="<%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |*, value| %>
<td class="primary value"><%= value %></td>
<% end %>
</tr>
<% extras = @extra_nutrients[i] %>
<% extras.each_slice(@quantities.length).with_index do |values, index| %>
<tr class="extra <%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |q_name, *| %>
<td class="extra quantity"><%= q_name %></td>
<% end %>
<% if @quantities.length > values.length %>
<td class="space" colspan="<%= @quantities.length-values.length %>"></td>
<% end %>
</tr>
<tr class="extra <%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |*, value| %>
<td class="extra value"><%= value %></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

@@ -0,0 +1,79 @@
<%= render partial: 'ingredients/filters',
locals: {url: filter_nutrients_project_ingredients_path(@project)} %>
<% if @ingredients.any? %>
<%= render partial: 'ingredients/options' %>
<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) %></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_name, 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) %></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_name, value| %>
<td class="extra quantity ellipsible">
<%= q_name %>
<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

@@ -8,28 +8,10 @@
<table>
<tr>
<td style="width:100%"></td>
<td>
<%= select_tag 'quantity_id', toggle_column_options %>
</td>
<td>
<%= submit_tag l(:button_add) %>
</td>
<td><%= select_tag 'quantity_id', toggle_column_options %></td>
<td><%= submit_tag l(:button_add) %></td>
</tr>
</table>
<% end %>
</div>
</fieldset>
<table class="list" style="border:none; width:100%">
<tr>
<% total_width = 3 + @quantities.length %>
<td style="visibility: hidden; border: none; width:<%= 3 * 100/total_width%>%"></td>
<% @quantities.each do |q| %>
<td class="action" style="width:<%= 100/total_width %>%">
<%= link_to l(:button_hide),
toggle_column_project_ingredients_path(@project, quantity_id: q.id),
{class: "icon icon-close", method: :post, remote: true} %>
</td>
<% end %>
</tr>
</table>

View File

@@ -10,5 +10,5 @@
<h2><%= t ".heading" %></h2>
<div id='ingredients'>
<%= render partial: 'ingredients/list' %>
<%= render partial: 'ingredients/index' %>
</div>

View File

@@ -10,5 +10,5 @@
<h2><%= t ".heading" %></h2>
<div id='nutrients'>
<%= render partial: 'ingredients/list_nutrients' %>
<%= render partial: 'ingredients/nutrients' %>
</div>

View File

@@ -1,3 +1,3 @@
$('div[id^=flash_]').remove();
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
$('#ingredients').html('<%= escape_javascript(render partial: 'ingredients/list') %>');
$('#ingredients').html('<%= escape_javascript(render partial: 'ingredients/index') %>');

View File

@@ -1,3 +1,3 @@
$('div[id^=flash_]').remove();
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
$('#nutrients').html('<%= escape_javascript(render partial: 'ingredients/list_nutrients') %>');
$('#nutrients').html('<%= escape_javascript(render partial: 'ingredients/nutrients') %>');