Skip to content

Commit

Permalink
Merge pull request #92 from Vizzuality/fix/figures-format-and-missing…
Browse files Browse the repository at this point in the history
…-practices

Separate large numbers with commas. don't include insignificant zeros
  • Loading branch information
dhakelila authored Oct 31, 2016
2 parents 35f5b40 + 9a4d332 commit 4e27535
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
5 changes: 5 additions & 0 deletions app/helpers/analyses_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ def icon_to_add_more(f, association)
end
link_to(image_tag("add.svg", size: "18x18"), "#", class: "-js-add-fields add-fields", data: {id: id, fields: fields.gsub("\n", "")})
end

def printable_value value
val = value.to_i == value ? value.to_i : value
number_with_delimiter(val, delimiter: ",")
end
end
40 changes: 30 additions & 10 deletions app/views/analyses/_printable_inputs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
<% unless analysis.fertilizers.select{|t| t.amount && t.amount > 0}.empty? %>
<% analysis.fertilizers.each do |fert| %>
<p>
<span class="text -print-figure"><%= fert.amount %></span>
<span class="text -print-figure">
<%= printable_value(fert.amount) %>
</span>
<span class="text -print-units">kg/ha/year</span>
<span class="text -print-product">of <%= fert.fertilizer_name %></span>
</p>
Expand All @@ -23,7 +25,9 @@
<% unless analysis.manures.select{|t| t.amount && t.amount > 0}.empty? %>
<% analysis.manures.each do |manure| %>
<p>
<span class="text -print-figure"><%= manure.amount %></span>
<span class="text -print-figure">
<%= printable_value(manure.amount) %>
</span>
<span class="text -print-units">kg/ha/year</span>
<span class="text -print-product">of <%= manure.manure_name %></span>
</p>
Expand Down Expand Up @@ -68,23 +72,29 @@

<% if analysis.lime_amount.present? && analysis.lime_amount > 0 %>
<p>
<span class="text -print-figure"><%= analysis.lime_amount %></span>
<span class="text -print-figure">
<%= printable_value(analysis.lime_amount) %>
</span>
<span class="text -print-units">kg/ha/year</span>
<span class="text -print-product">of Lime applied</span>
</p>
<% end %>

<% if analysis.dolomite_amount.present? && analysis.dolomite_amount > 0 %>
<p>
<span class="text -print-figure"><%= analysis.dolomite_amount %></span>
<span class="text -print-figure">
<%= printable_value(analysis.dolomite_amount) %>
</span>
<span class="text -print-units">kg/ha/year</span>
<span class="text -print-product">of Dolomite applied</span>
</p>
<% end %>

<% if analysis.agrochemical_amount.present? && analysis.agrochemical_amount > 0%>
<p>
<span class="text -print-figure"><%= analysis.agrochemical_amount %></span>
<span class="text -print-figure">
<%= printable_value(analysis.agrochemical_amount) %>
</span>
<span class="text -print-units">kg/ha/year</span>
<span class="text -print-product">of pesticides and/or herbicides</span>
</p>
Expand All @@ -96,7 +106,9 @@
<p>
You incorporate
<% analysis.nutrient_managements.each do |nut| %>
<span class="text -print-figure"><%= nut.amount %></span>
<span class="text -print-figure">
<%= printable_value(nut.amount) %>
</span>
<span class="text -print-units">kg/ha/year</span>
<span class="text -print-product">of <%= nut.nutrient_mgmt_name %></span>
<% end %>
Expand All @@ -105,15 +117,19 @@

<p>
<span class="text -print-product">Rice straw burned</span>
<span class="text -print-figure"><%= analysis.rice_straw_burned %></span>
<span class="text -print-figure">
<%= printable_value(analysis.rice_straw_burned) %>
</span>
</p>
<% end %>

<% unless analysis.transportation_fuels.select{|t| t.amount && t.amount > 0}.empty? %>
<% analysis.transportation_fuels.each do |fuel| %>
<% if fuel.amount.present? %>
<p>
<span class="text -print-figure"><%= fuel.amount %></span>
<span class="text -print-figure">
<%= printable_value fuel.amount %>
</span>
<span class="text -print-units"><%= fuel.fuel_unit_name %></span>
<span class="text -print-product">of <%= fuel.fuel_name %> for transportation</span>
</p>
Expand All @@ -126,7 +142,9 @@
<% analysis.irrigation_fuels.each do |fuel| %>
<% if fuel.amount.present? %>
<p>
<span class="text -print-figure"><%= fuel.amount %></span>
<span class="text -print-figure">
<%= printable_value fuel.amount %>
</span>
<span class="text -print-units"><%= fuel.fuel_unit_name %></span>
<span class="text -print-product">of <%= fuel.fuel_name %> for irrigation</span>
</p>
Expand All @@ -138,7 +156,9 @@
<% analysis.fuels.each do |fuel| %>
<% if fuel.amount.present? %>
<p>
<span class="text -print-figure"><%= fuel.amount %></span>
<span class="text -print-figure">
<%= printable_value fuel.amount %>
</span>
<span class="text -print-units"><%= fuel.fuel_unit_name %></span>
<span class="text -print-product">of <%= fuel.fuel_name %> for other purposes</span>
</p>
Expand Down

0 comments on commit 4e27535

Please sign in to comment.