From 043230394eae9abec32ddba03039d1e2f6f8d15f Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Wed, 23 Apr 2025 13:08:00 +0200 Subject: [PATCH] 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. --- app/helpers/notifications_helper.rb | 36 ++++++++++++++++++----------- app/models/concerns/mentions.rb | 1 - app/models/event.rb | 19 +++------------ 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 613776bac..cc63fb5d5 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -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 diff --git a/app/models/concerns/mentions.rb b/app/models/concerns/mentions.rb index 883ebc40a..41a818794 100644 --- a/app/models/concerns/mentions.rb +++ b/app/models/concerns/mentions.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 5eb095039..f95dc0785 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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