mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
Merge branch 'dev' of https://github.com/Growstuff/growstuff into links-wrong
This commit is contained in:
@@ -109,37 +109,49 @@ class Harvest < ApplicationRecord
|
||||
def to_s
|
||||
# 50 individual apples, weighing 3lb
|
||||
# 2 buckets of apricots, weighing 10kg
|
||||
"#{quantity_to_human} #{unit_to_human} #{crop_name_to_human} #{weight_to_human}".strip
|
||||
@to_s ||= "#{quantity_to_human} #{unit_to_human} #{crop_name_to_human} #{weight_to_human}".strip
|
||||
end
|
||||
|
||||
def quantity_to_human
|
||||
return number_to_human(quantity.to_s, strip_insignificant_zeros: true) if quantity
|
||||
|
||||
""
|
||||
@quantity_to_human ||= if quantity
|
||||
number_to_human(quantity.to_s, strip_insignificant_zeros: true)
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def unit_to_human
|
||||
return "" unless quantity && unit
|
||||
return 'individual' if unit == 'individual'
|
||||
return "#{unit} of" if quantity == 1
|
||||
|
||||
"#{unit.pluralize} of"
|
||||
@unit_to_human ||= begin
|
||||
if !quantity || !unit
|
||||
""
|
||||
elsif unit == 'individual'
|
||||
'individual'
|
||||
elsif quantity == 1
|
||||
"#{unit} of"
|
||||
else
|
||||
"#{unit.pluralize} of"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def weight_to_human
|
||||
return "" unless weight_quantity
|
||||
|
||||
"weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)} #{weight_unit}"
|
||||
@weight_to_human ||= if weight_quantity
|
||||
"weighing #{number_to_human(weight_quantity, strip_insignificant_zeros: true)} #{weight_unit}"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def crop_name_to_human
|
||||
if unit != 'individual' # buckets of apricot*s*
|
||||
crop.name.pluralize
|
||||
elsif quantity == 1
|
||||
crop.name
|
||||
else
|
||||
crop.name.pluralize
|
||||
end.to_s
|
||||
@crop_name_to_human ||= begin
|
||||
if unit != 'individual' # buckets of apricot*s*
|
||||
crop.name.pluralize
|
||||
elsif quantity == 1
|
||||
crop.name
|
||||
else
|
||||
crop.name.pluralize
|
||||
end.to_s
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -5,14 +5,15 @@
|
||||
%p Nobody has harvested this crop yet.
|
||||
- unless crop.harvests.empty?
|
||||
%ul.list-group.list-group-flush
|
||||
- Harvest.where(crop: crop).includes(:owner).order(harvested_at: :desc).limit(3).each do |harvest|
|
||||
%li.list-group-item
|
||||
= link_to harvest_path(harvest), class: 'card-link' do
|
||||
= harvest_icon
|
||||
#{harvest.owner} harvested #{display_quantity(harvest)}.
|
||||
.float-right= render 'members/location', member: harvest.owner
|
||||
.harvest-timeago
|
||||
%small #{standard_time_distance(harvest.harvested_at, Time.zone.now.to_date)}
|
||||
- Rails.cache.fetch([crop, "recent_harvests", Time.zone.today]) do
|
||||
- Harvest.where(crop: crop).includes(:owner).order(harvested_at: :desc).limit(3).each do |harvest|
|
||||
%li.list-group-item
|
||||
= link_to harvest_path(harvest), class: 'card-link' do
|
||||
= harvest_icon
|
||||
#{harvest.owner} harvested #{display_quantity(harvest)}.
|
||||
.float-right= render 'members/location', member: harvest.owner
|
||||
.harvest-timeago
|
||||
%small #{standard_time_distance(harvest.harvested_at, Time.zone.now.to_date)}
|
||||
%li.list-group-item= link_to "View all #{crop.name} harvests", crop_harvests_path(crop), class: 'card-link'
|
||||
- if crop.approved?
|
||||
- if current_member
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
%p
|
||||
%small
|
||||
= harvest.harvested_at
|
||||
- cache harvest do
|
||||
%p
|
||||
%small
|
||||
= harvest.harvested_at
|
||||
|
||||
Reference in New Issue
Block a user