Tidy up event helper code

Also, revert to using a helper method to determine the event action, since this is purely a view concern. Keep method at the event model to identify initial assignments.
This commit is contained in:
Jorge Manrubia
2025-04-23 13:08:00 +02:00
parent 2e3ffcfb9d
commit 043230394e
3 changed files with 25 additions and 31 deletions
+22 -14
View File
@@ -1,25 +1,20 @@
module NotificationsHelper
def event_notification_title(event)
if event.commented?
"RE: " + event.card.title
elsif event.assigned?
"Assigned to you: " + event.card.title
else
event.card.title
case event_notification_action(event)
when "commented" then "RE: " + event.card.title
when "assigned" then "Assigned to you: " + event.card.title
else event.card.title
end
end
def event_notification_body(event)
name = event.creator.name
if event.closed?
"Closed by #{name}"
elsif event.published?
"Added by #{name}"
elsif event.commented?
"#{strip_tags(event.comment.body_html).blank? ? "#{name} replied" : "#{event.creator.name}:" } #{strip_tags(event.comment.body_html).truncate(200)}"
else
name
case event_notification_action(event)
when "closed" then "Closed by #{name}"
when "published" then "Added by #{name}"
when "commented" then comment_notification_body(event)
else name
end
end
@@ -59,4 +54,17 @@ module NotificationsHelper
tag.div id: "next_page", data: { controller: "fetch-on-visible", fetch_on_visible_url_value: notifications_path(page: @page.next_param) }
end
end
private
def event_notification_action(event)
if event.initial_assignment?
"assigned"
else
event.action
end
end
def comment_notification_body(event)
"#{strip_tags(event.comment.body_html).blank? ? "#{name} replied" : "#{event.creator.name}:" } #{strip_tags(event.comment.body_html).truncate(200)}"
end
end
-1
View File
@@ -35,7 +35,6 @@ module Mentions
end
def mentionable_content_changed?
puts "Was #{previously_new_record?}"
previously_new_record? || @mentionable_content_before_save != mentionable_content
end
+3 -16
View File
@@ -12,24 +12,11 @@ class Event < ApplicationRecord
after_create -> { card.touch(:last_active_at) }
def assigned?
action == "assigned" || initial_assignment?
end
def action
super.inquiry
super&.inquiry
end
def method_missing(method_name, *args, &block)
if method_name.to_s.end_with?("?")
action == method_name.to_s.chomp("?")
else
super
end
def initial_assignment?
action == "published" && card.assigned_to?(creator)
end
private
def initial_assignment?
action == "published" && card.assigned_to?(creator)
end
end