diff --git a/app.json b/app.json index e4bc1019..2f2f9e51 100644 --- a/app.json +++ b/app.json @@ -5,14 +5,6 @@ { "url": "https://github.com/heroku/heroku-buildpack-nodejs.git" }, { "url": "https://github.com/heroku/heroku-buildpack-ruby.git" } ], - "formation": { - "web": { - "quantity": 1 - }, - "worker": { - "quantity": 1 - } - }, "scripts": { "dokku": { "predeploy": "bundle exec rails db:migrate" diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb index fa0b77ae..89f7771a 100644 --- a/app/helpers/trips_helper.rb +++ b/app/helpers/trips_helper.rb @@ -23,4 +23,38 @@ module TripsHelper photoprism_search_url(settings['photoprism_url'], start_date, end_date) end end + + def trip_duration(trip) + start_time = trip.started_at.to_time + end_time = trip.ended_at.to_time + + # Calculate the difference + years = end_time.year - start_time.year + months = end_time.month - start_time.month + days = end_time.day - start_time.day + hours = end_time.hour - start_time.hour + + # Adjust for negative values + if hours < 0 + hours += 24 + days -= 1 + end + if days < 0 + prev_month = end_time.prev_month + days += (end_time - prev_month).to_i / 1.day + months -= 1 + end + if months < 0 + months += 12 + years -= 1 + end + + parts = [] + parts << "#{years} year#{'s' if years != 1}" if years > 0 + parts << "#{months} month#{'s' if months != 1}" if months > 0 + parts << "#{days} day#{'s' if days != 1}" if days > 0 + parts << "#{hours} hour#{'s' if hours != 1}" if hours > 0 + parts = ["0 hours"] if parts.empty? + parts.join(', ') + end end diff --git a/app/jobs/trips/calculate_distance_job.rb b/app/jobs/trips/calculate_distance_job.rb index b2e7b0d9..8a28e06f 100644 --- a/app/jobs/trips/calculate_distance_job.rb +++ b/app/jobs/trips/calculate_distance_job.rb @@ -3,23 +3,23 @@ class Trips::CalculateDistanceJob < ApplicationJob queue_as :default - def perform(trip_id) + def perform(trip_id, distance_unit) trip = Trip.find(trip_id) trip.calculate_distance trip.save! - broadcast_update(trip) + broadcast_update(trip, distance_unit) end private - def broadcast_update(trip) + def broadcast_update(trip, distance_unit) Turbo::StreamsChannel.broadcast_update_to( "trip_#{trip.id}", target: "trip_distance", partial: "trips/distance", - locals: { trip: trip } + locals: { trip: trip, distance_unit: distance_unit } ) end end diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 9b41d145..1b0e0d85 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -33,6 +33,10 @@ <%= f.password_field :password_confirmation, autocomplete: "new-password", class: 'input input-bordered' %> + <% if !DawarichSettings.self_hosted? %> +
+ <% end %> +- <%= "#{trip.countries.join(', ')} (#{trip.distance} #{current_user.safe_settings.distance_unit})" %> -
-<% elsif trip.visited_countries.present? %> -- <%= "#{trip.visited_countries.join(', ')} (#{trip.distance} #{current_user.safe_settings.distance_unit})" %> -
-<% else %> -- Countries are being calculated... - -
-<% end %> +- <%= human_date(@trip.started_at) %> - <%= human_date(@trip.ended_at) %> -
- <% if @trip.countries.any? || @trip.visited_countries.present? %> -- Countries are being calculated... - -
-+ <%= human_date(@trip.started_at) %> - <%= human_date(@trip.ended_at) %> +
+ + <%= render "trips/countries", trip: @trip, current_user: current_user %> +