From 13dafde677c91e0c532238e50a4992a1513bd549 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Thu, 30 Jul 2026 12:52:34 +0100 Subject: [PATCH] Render GPX import notifications, from the trace record as possible --- app/models/gpx_import_notification_details.rb | 61 +++++++++++++++++++ app/models/user_notifications.rb | 52 +--------------- app/views/notifications/_gpx_details.html.erb | 18 +++--- .../_gpx_import_failure.html.erb | 6 +- .../_gpx_import_success.html.erb | 12 ++-- 5 files changed, 81 insertions(+), 68 deletions(-) create mode 100644 app/models/gpx_import_notification_details.rb diff --git a/app/models/gpx_import_notification_details.rb b/app/models/gpx_import_notification_details.rb new file mode 100644 index 000000000..55cb15ca2 --- /dev/null +++ b/app/models/gpx_import_notification_details.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +class GpxImportNotificationDetails + class Details + def initialize(notification) + @notification = notification + end + + delegate :record, :to => :@notification + end + + class Success < Details + delegate :description, :tagstring, :to => :record + + def filename + record.name + end + + def num_tags + record.tags.length + end + + def possible_points + @notification.params[:possible_points] + end + + def trace_points + record.size + end + end + + class Failure < Details + def filename + @notification.params[:trace_name] + end + + def description + @notification.params[:trace_description] + end + + def num_tags + tags.count + end + + def tags + @notification.params[:trace_tags] + end + + def tagstring + tags.join(", ") + end + + def possible_points + nil + end + + def trace_points + nil + end + end +end diff --git a/app/models/user_notifications.rb b/app/models/user_notifications.rb index dad2a522a..6cb5df56b 100644 --- a/app/models/user_notifications.rb +++ b/app/models/user_notifications.rb @@ -31,59 +31,11 @@ class UserNotifications end class GpxImportFailureNotification < Notification - def timestamp - @notification.created_at - end - - def trace_filename - @notification.params[:trace_name] - end - - def trace_description - @notification.params[:trace_description] - end - - def trace_tags - @notification.params[:trace_tags] - end - - def trace_possible_points - nil - end - - def trace_points - nil - end - - def error - @notification.params[:error] - end + delegate :params, :created_at, :to => :@notification end class GpxImportSuccessNotification < Notification - delegate :timestamp, :to => :record - - def trace_filename - record.name - end - - def trace_description - record.description - end - - def trace_tags - record.tags.map(&:tag) - end - - def trace_possible_points - @notification.params[:possible_points] - end - - def trace_points - record.size - end - - delegate :user, :to => :record + delegate :params, :to => :@notification end class NewFollowerNotification < Notification diff --git a/app/views/notifications/_gpx_details.html.erb b/app/views/notifications/_gpx_details.html.erb index a4da7eda0..b02d4b75c 100644 --- a/app/views/notifications/_gpx_details.html.erb +++ b/app/views/notifications/_gpx_details.html.erb @@ -1,24 +1,24 @@ -<%# locals: (notification:) %> +<%# locals: (details:) %>
<%= t(".filename") %>
-
<%= notification.trace_filename %>
+
<%= details.filename %>
<%= t(".description") %>
-
<%= notification.trace_description %>
+
<%= details.description %>
- <% if notification.trace_tags.length.positive? %> + <% if details.num_tags.positive? %>
<%= t(".tags") %>
-
<%= notification.trace_tags.join(", ") %>
+
<%= details.tagstring %>
<% end %> - <% if notification.trace_possible_points %> + <% if details.possible_points %>
<%= t(".total_points") %>
-
<%= notification.trace_possible_points %>
+
<%= details.possible_points %>
<% end %> - <% if notification.trace_points %> + <% if details.trace_points %>
<%= t(".imported_points") %>
-
<%= notification.trace_points %>
+
<%= details.trace_points %>
<% end %>
diff --git a/app/views/notifications/_gpx_import_failure.html.erb b/app/views/notifications/_gpx_import_failure.html.erb index b3e1d23d9..6cf053f18 100644 --- a/app/views/notifications/_gpx_import_failure.html.erb +++ b/app/views/notifications/_gpx_import_failure.html.erb @@ -5,7 +5,7 @@

<%= t(".headline") %>

-

<%= friendly_date_ago(notification.timestamp) %>

+

<%= friendly_date_ago(notification.created_at) %>

@@ -13,11 +13,11 @@
- <%= render "notifications/gpx_details", :notification => notification %> + <%= render "notifications/gpx_details", :details => GpxImportNotificationDetails::Failure.new(notification) %>
<%= t(".error_message") %>
-
<%= notification.error %>
+
<%= notification.params[:error] %>
diff --git a/app/views/notifications/_gpx_import_success.html.erb b/app/views/notifications/_gpx_import_success.html.erb index 4593d4ffd..05c1e6269 100644 --- a/app/views/notifications/_gpx_import_success.html.erb +++ b/app/views/notifications/_gpx_import_success.html.erb @@ -3,17 +3,17 @@

- <%= link_to t(".headline"), show_trace_path(notification.user, notification.record) %> + <%= link_to t(".headline"), show_trace_path(record.user, record) %>

-

<%= friendly_date_ago(notification.timestamp) %>

+

<%= friendly_date_ago(record.timestamp) %>

<% if Settings.status != "gpx_offline" %> - <% if notification.record.inserted %> - <%= link_to trace_icon(notification.record), - show_trace_path(notification.record.user, notification.record), + <% if record.inserted %> + <%= link_to trace_icon(record), + show_trace_path(record.user, record), :class => "d-inline-block" %> <% else %> <%= t ".pending" %> @@ -21,7 +21,7 @@ <% end %>
- <%= render "notifications/gpx_details", :notification => notification %> + <%= render "notifications/gpx_details", :details => GpxImportNotificationDetails::Success.new(notification) %>

-- 2.47.3