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 %> +
<%= f.submit "Sign up", class: 'btn btn-primary' %>
diff --git a/app/views/trips/_countries.html.erb b/app/views/trips/_countries.html.erb index 9dc0adc2..f4518f33 100644 --- a/app/views/trips/_countries.html.erb +++ b/app/views/trips/_countries.html.erb @@ -1,14 +1,29 @@ -<% if trip.countries.any? %> -

- <%= "#{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 %> +
+
+
+
Distance
+
<%= @trip.distance %> <%= current_user.safe_settings.distance_unit %>
+
+
+
+
+
Duration
+
<%= trip_duration(@trip) %>
+
+
+
+
+
Countries
+
+ <% if @trip.countries.any? %> + <%= @trip.countries.join(', ') %> + <% elsif @trip.visited_countries.present? %> + <%= @trip.visited_countries.join(', ') %> + <% else %> + Countries are being calculated... + + <% end %> +
+
+
+
diff --git a/app/views/trips/_distance.html.erb b/app/views/trips/_distance.html.erb index 89f0ef92..e6e4d13d 100644 --- a/app/views/trips/_distance.html.erb +++ b/app/views/trips/_distance.html.erb @@ -1,5 +1,5 @@ <% if trip.distance.present? %> - <%= trip.distance %> <%= current_user.safe_settings.distance_unit %> + <%= trip.distance %> <%= distance_unit %> <% else %> Calculating... diff --git a/app/views/trips/_path.html.erb b/app/views/trips/_path.html.erb index 25d59a41..4321d5f2 100644 --- a/app/views/trips/_path.html.erb +++ b/app/views/trips/_path.html.erb @@ -1,7 +1,7 @@ <% if trip.path.present? %>
-
+
<% else %> diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb index f057ac24..1d068953 100644 --- a/app/views/trips/show.html.erb +++ b/app/views/trips/show.html.erb @@ -2,40 +2,30 @@ <%= turbo_stream_from "trip_#{@trip.id}" %> -
-
-

<%= @trip.name %>

-

- <%= human_date(@trip.started_at) %> - <%= human_date(@trip.ended_at) %> -

- <% if @trip.countries.any? || @trip.visited_countries.present? %> -
- <%= render "trips/countries", trip: @trip %> -
- <% else %> -
-

- Countries are being calculated... - -

-
- <% end %> -
- -
-
-
+
+
+
+
<%= render "trips/path", trip: @trip, current_user: current_user %>
+
+

<%= @trip.name %>

+

+ <%= human_date(@trip.started_at) %> - <%= human_date(@trip.ended_at) %> +

+ + <%= render "trips/countries", trip: @trip, current_user: current_user %> +
+
<%= @trip.notes.body %>
<% if @photo_previews.any? %> - <% @photo_previews.each_slice(4) do |slice| %> -
+ <% @photo_previews.each_slice(3) do |slice| %> +
<% slice.each do |photo| %>