+ Hi, this is Evgenii from Dawarich! Pretty wild journey last yeah, huh? Let's take a look back at all the places you explored in <%= @digest.year %>. +
+diff --git a/app/models/stat.rb b/app/models/stat.rb index 1bcb2cbf..4b0e6394 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -68,12 +68,14 @@ class Stat < ApplicationRecord def enable_sharing!(expiration: '1h') # Default to 24h if an invalid expiration is provided - expiration = '24h' unless %w[1h 12h 24h].include?(expiration) + expiration = '24h' unless %w[1h 12h 24h 1w 1m].include?(expiration) expires_at = case expiration when '1h' then 1.hour.from_now when '12h' then 12.hours.from_now when '24h' then 24.hours.from_now + when '1w' then 1.week.from_now + when '1m' then 1.month.from_now end update!( diff --git a/app/models/users/digest.rb b/app/models/users/digest.rb index 0c65a753..843aa115 100644 --- a/app/models/users/digest.rb +++ b/app/models/users/digest.rb @@ -46,12 +46,14 @@ class Users::Digest < ApplicationRecord end def enable_sharing!(expiration: '24h') - expiration = '24h' unless %w[1h 12h 24h].include?(expiration) + expiration = '24h' unless %w[1h 12h 24h 1w 1m].include?(expiration) expires_at = case expiration when '1h' then 1.hour.from_now when '12h' then 12.hours.from_now when '24h' then 24.hours.from_now + when '1w' then 1.week.from_now + when '1m' then 1.month.from_now end update!( @@ -127,7 +129,7 @@ class Users::Digest < ApplicationRecord end def total_distance_all_time - all_time_stats['total_distance'] || 0 + (all_time_stats['total_distance'] || 0).to_i end def distance_km diff --git a/app/services/users/digests/calculate_year.rb b/app/services/users/digests/calculate_year.rb index f278c6a6..faea7d50 100644 --- a/app/services/users/digests/calculate_year.rb +++ b/app/services/users/digests/calculate_year.rb @@ -76,12 +76,12 @@ module Users result = {} monthly_stats.each do |stat| - result[stat.month.to_s] = stat.distance + result[stat.month.to_s] = stat.distance.to_s end # Fill in missing months with 0 (1..12).each do |month| - result[month.to_s] ||= 0 + result[month.to_s] ||= '0' end result @@ -131,7 +131,7 @@ module Users { 'total_countries' => user.countries_visited.count, 'total_cities' => user.cities_visited.count, - 'total_distance' => user.stats.sum(:distance) + 'total_distance' => user.stats.sum(:distance).to_s } end end diff --git a/app/views/shared/_sharing_modal.html.erb b/app/views/shared/_sharing_modal.html.erb index 926719cb..f994558b 100644 --- a/app/views/shared/_sharing_modal.html.erb +++ b/app/views/shared/_sharing_modal.html.erb @@ -43,7 +43,9 @@ <%= options_for_select([ ['1 hour', '1h'], ['12 hours', '12h'], - ['24 hours', '24h'] + ['24 hours', '24h'], + ['1 week', '1w'], + ['1 month', '1m'] ], @stat&.sharing_settings&.dig('expiration') || '1h') %> diff --git a/app/views/users/digests/index.html.erb b/app/views/users/digests/index.html.erb index 142f4eab..7b695d23 100644 --- a/app/views/users/digests/index.html.erb +++ b/app/views/users/digests/index.html.erb @@ -27,8 +27,9 @@ <% if @digests.empty? %>
Year-end digests are automatically generated on January 1st each year. <% if @available_years.any? && current_user.active? %> diff --git a/app/views/users/digests/public_year.html.erb b/app/views/users/digests/public_year.html.erb index 2031aef2..a2cfaec7 100644 --- a/app/views/users/digests/public_year.html.erb +++ b/app/views/users/digests/public_year.html.erb @@ -80,7 +80,7 @@
Your journey, by the numbers
+ Hi, this is Evgenii from Dawarich! Pretty wild journey last yeah, huh? Let's take a look back at all the places you explored in <%= @digest.year %>. +
++ You can open your digest for sharing on its page on Dawarich: <%= users_digest_url(year: @digest.year) %> +
+