Files
fizzy/app/helpers/notifications_helper.rb
T
Jorge Manrubia eea9afb639 Fix: dismiss grouped notifications by card from the notifications tray
This also splits the templates into two: index and tray, since the URL now changes.
2025-11-14 12:58:24 +01:00

92 lines
3.1 KiB
Ruby

module NotificationsHelper
def event_notification_title(event)
case event_notification_action(event)
when "comment_created" then "RE: #{card_notification_title(event.eventable.card)}"
else card_notification_title(event.eventable)
end
end
def event_notification_body(event)
name = event.creator.name
case event_notification_action(event)
when "card_closed" then "Moved to Done by #{name}"
when "card_reopened" then "Reopened by #{name}"
when "card_published" then "Added by #{name}"
when "comment_created" then comment_notification_body(event)
when "card_assigned" then "Assigned to #{event.assignees.none? ? "self" : event.assignees.pluck(:name).to_sentence}"
else name
end
end
def notification_tag(notification, &)
tag.div id: dom_id(notification), class: "tray__item tray__item--notification", data: {
navigable_list_target: "item",
notifications_tray_target: "notification",
card_id: notification.card.id,
timestamp: notification.created_at.to_i
} do
link_to(notification,
class: [ "card card--notification", { "card--closed": notification.card.closed? }, { "unread": !notification.read? } ],
data: { turbo_frame: "_top", badge_target: "unread", action: "badge#update dialog#close" },
style: { "--card-color:": notification.card.color },
&)
end
end
def notification_toggle_read_button(notification, url:)
if notification.read?
button_to url,
method: :delete,
class: "card__notification-unread-indicator btn btn--circle borderless",
title: "Mark as unread",
data: { action: "form#submit:stop badge#update:stop", form_target: "submit" },
form: { data: { controller: "form" } } do
concat(icon_tag("unseen"))
end
else
button_to url,
class: "card__notification-unread-indicator btn btn--circle borderless",
title: "Mark as read",
data: { action: "form#submit:stop badge#update:stop", form_target: "submit" },
form: { data: { controller: "form" } } do
concat(icon_tag("remove"))
concat(tag.span("1", class: "badge-count", data: { group_count: "" }))
end
end
end
def notifications_next_page_link(page)
unless @page.last?
tag.div id: "next_page", data: { controller: "fetch-on-visible", fetch_on_visible_url_value: notifications_path(page: @page.next_param) }
end
end
def bundle_email_frequency_options_for(settings)
options_for_select([
[ "Never", "never" ],
[ "Every few hours", "every_few_hours" ],
[ "Every day", "daily" ],
[ "Every week", "weekly" ]
], settings.bundle_email_frequency)
end
private
def event_notification_action(event)
if event.action.card_published? && event.eventable.assigned_to?(event.creator)
"card_assigned"
else
event.action
end
end
def comment_notification_body(event)
comment = event.eventable
comment.body.to_plain_text.truncate(200)
end
def card_notification_title(card)
card.title.presence || "Card #{card.id}"
end
end