Skip to content

Commit 9b1699b

Browse files
authored
Merge pull request #4215 from Growstuff/activities-detail
Surface more Activities detail
1 parent 06c9077 commit 9b1699b

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

app/helpers/application_helper.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ def build_alert_classes(alert_type = :info)
2121
classes
2222
end
2323

24+
# Similar to Rails' time_ago_in_words, but gives a more standard
25+
# output like "in 3 days" or "5 months ago".
26+
# Also handles the case where from_time is a Date and to_time is a Date
27+
# (in which case it just says "today" if they're the same date).
28+
#
29+
# NOTE: This is similar to distance_of_time_in_words but different enough
30+
# that I think it's worth having a separate helper for it.
31+
#
32+
# from_time - the starting time (Time or Date)
33+
# to_time - the ending time (Time or Date). Default: now (Time.zone.now)
34+
# include_seconds - whether to include seconds in the calculation
35+
#
36+
# Returns a string like "in 3 days" or "5 months ago"
37+
def standard_time_distance(from_time, to_time = 0, include_seconds = false)
38+
return 'today' if from_time.is_a?(Date) && (from_time == to_time)
39+
40+
return 'now' if from_time == to_time
41+
return distance_of_time_in_words(from_time, to_time, include_seconds:) + ' ago' if from_time > to_time
42+
43+
'in ' + distance_of_time_in_words(from_time, to_time, include_seconds:)
44+
end
45+
2446
def count_github_contibutors
2547
File.open(Rails.root.join('CONTRIBUTORS.md')).readlines.grep(/^-/).size
2648
end

app/models/concerns/search_activities.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ module SearchActivities
99
mappings: {
1010
properties: {
1111
active: { type: :boolean },
12-
created_at: { type: :integer }
12+
created_at: { type: :integer },
13+
updated_at: { type: :integer },
14+
due_date: { type: :date }
1315
}
1416
}
1517

@@ -23,8 +25,10 @@ def search_data
2325
category:,
2426
garden_id:,
2527
garden_name: garden&.name,
28+
garden_slug: garden&.garden_slug,
2629
planting_id:,
2730
planting_name: planting&.crop&.name,
31+
planting_slug: planting&.slug,
2832
description:,
2933

3034
# owner

app/views/activities/_card.html.haml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@
2020
- if can? :destroy, activity
2121
.dropdown-divider
2222
= delete_button(activity, classes: 'dropdown-item text-danger')
23-
= link_to activity_path(slug: activity.slug) do
24-
.card-body.text-center
23+
.card-body
24+
= link_to activity_path(slug: activity.slug) do
2525
%h4= activity.name
26-
.text-center= activity.description
27-
- if activity.garden
28-
.text-center= activity.garden
29-
- if activity.planting
30-
.text-center= activity.planting
26+
%small.due-date{title: activity.due_date}
27+
= standard_time_distance(activity.due_date.to_date, Time.zone.now.to_date)
28+
%div
29+
%small.text-justify{title: activity.description}= activity.description.truncate(150)
30+
%p
31+
%ul.list-unstyled
32+
- if activity.garden_name && activity.garden_slug
33+
%li
34+
%small= link_to activity.garden_name, garden_path(slug: activity.garden_slug)
35+
- if activity.planting_name && activity.planting_slug
36+
%li
37+
%small= link_to activity.planting_name, planting_path(slug: activity.planting_slug)
38+
3139
.card-footer
32-
.float-right
33-
%span.chip.member-chip
34-
= link_to member_path(slug: activity.owner_slug) do
35-
= activity.owner_login_name
40+
%small.chip.member-chip
41+
= link_to member_path(slug: activity.owner_slug) do
42+
= activity.owner_login_name

app/views/crops/_harvests.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#{harvest.owner} harvested #{display_quantity(harvest)}.
1313
.float-right= render 'members/location', member: harvest.owner
1414
.harvest-timeago
15-
%small #{distance_of_time_in_words(harvest.harvested_at, Time.zone.now)} ago.
15+
%small #{standard_time_distance(harvest.harvested_at, Time.zone.now.to_date)}
1616
%li.list-group-item= link_to "View all #{crop.name} harvests", crop_harvests_path(crop), class: 'card-link'
1717
- if crop.approved?
1818
- if current_member

app/views/harvests/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
%h3
4747
Harvested
4848
= editable :date, @harvest, :harvested_at, display_field: '.harvested_at'
49-
%strong.harvested_at #{distance_of_time_in_words @harvest.harvested_at, Time.zone.now.to_date} ago
49+
%strong.harvested_at #{standard_time_distance @harvest.harvested_at, Time.zone.now.to_date}
5050
%span.harvested_at= I18n.l @harvest.harvested_at
5151

5252
.card{class: @harvest.quantity.present? ? '' : 'text-muted'}

0 commit comments

Comments
 (0)