1
0

Extra quantities styling in Nutrients listing

Fixed decimal precision/scale
This commit is contained in:
cryptogopher 2019-10-31 22:13:39 +01:00
parent 2f0b34d3fe
commit fcec8364bc
3 changed files with 21 additions and 12 deletions

View File

@ -14,7 +14,7 @@
<h2><%= t ".heading" %></h2>
<% if @primary_nutrients.any? %>
<table class="nutrients list">
<table class="nutrients list odd-even">
<thead>
<tr>
<th style="width:30%"><%= l(:field_name) %></th>
@ -25,7 +25,7 @@
</thead>
<tbody>
<% @primary_nutrients.each do |i, values| %>
<% row_class = "ingredient #{'hidden' if i.hidden}" %>
<% row_class = "ingredient#{' hidden' if i.hidden} #{cycle('odd', 'even')}" %>
<tr id="ingredient-<%= i.id %>" class="primary <%= row_class %>">
<td class="name">
<%= link_to '', '#', {
@ -40,16 +40,21 @@
</td>
<% end %>
</tr>
<% @extra_nutrients[i].keys.each_slice(@primary_quantities.length) do |names| %>
<% extras = @extra_nutrients[i].keys %>
<% extras.each_slice(@primary_quantities.length).with_index do |names, index| %>
<tr class="extra <%= row_class %>" style="display:none">
<td rowspan="2"></td>
<% if index == 0 %>
<td rowspan="<%= 2*(extras.length.to_d / @primary_quantities.length).ceil %>"
class="space">
</td>
<% end %>
<% names.each do |name| %>
<td class="extra name">
<td class="extra quantity">
<%= name %>
</td>
<% end %>
<% for index in names.length...@primary_quantities.length do %>
<td rowspan="2"></td>
<% if @primary_quantities.length > names.length %>
<td rowspan="2" colspan="<%= @primary_quantities.length-names.length %>"></td>
<% end %>
</tr>
<tr class="extra <%= row_class %>" style="display:none">

View File

@ -1,10 +1,14 @@
table.list tr.quantity.primary td.name {font-weight: bold;}
table.nutrients.list td.name,
table.list td.quantity.extra {text-align: left; border-bottom: none;}
table.nutrients.list td.space,
table.list td.value.extra {border-top: none;}
table.list tr.ingredient.hidden {opacity: 0.4}
table.list td.action,
table.list td.value {text-align: right;}
table.list th,
table.list td.action,
table.list td.name,
table.nutrients.list th,
table.nutrients.list td.name,
table.list td.quantity,
table.list td.value {
overflow: hidden;
text-overflow: ellipsis;

View File

@ -27,7 +27,7 @@ class CreateUnits < ActiveRecord::Migration
create_table :ingredients do |t|
t.references :project
t.string :name
t.decimal :ref_amount
t.decimal :ref_amount, precision: 12, scale: 6
t.references :ref_unit
t.integer :group
t.references :source
@ -38,7 +38,7 @@ class CreateUnits < ActiveRecord::Migration
create_table :nutrients do |t|
t.references :ingredient
t.references :quantity
t.decimal :amount
t.decimal :amount, precision: 12, scale: 6
t.references :unit
end