2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-12-09 00:34:51 -05:00
|
|
|
module BroadcastMessagesHelper
|
2020-01-09 19:07:56 -05:00
|
|
|
def current_broadcast_banner_messages
|
2022-02-17 10:18:08 -05:00
|
|
|
BroadcastMessage.current_banner_messages(request.path).select do |message|
|
2020-03-04 19:07:49 -05:00
|
|
|
cookies["hide_broadcast_message_#{message.id}"].blank?
|
|
|
|
end
|
2019-12-02 10:06:36 -05:00
|
|
|
end
|
|
|
|
|
2020-01-09 19:07:56 -05:00
|
|
|
def current_broadcast_notification_message
|
2022-02-17 10:18:08 -05:00
|
|
|
not_hidden_messages = BroadcastMessage.current_notification_messages(request.path).select do |message|
|
2020-03-04 19:07:49 -05:00
|
|
|
cookies["hide_broadcast_message_#{message.id}"].blank?
|
2020-01-28 13:08:35 -05:00
|
|
|
end
|
|
|
|
not_hidden_messages.last
|
2020-01-09 19:07:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def broadcast_message(message, opts = {})
|
2015-12-31 16:42:56 -05:00
|
|
|
return unless message.present?
|
|
|
|
|
2020-01-28 13:08:35 -05:00
|
|
|
render "shared/broadcast_message", { message: message, opts: opts }
|
2015-12-31 16:42:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def broadcast_message_style(broadcast_message)
|
2020-01-09 19:07:56 -05:00
|
|
|
return '' if broadcast_message.notification?
|
|
|
|
|
2018-08-18 07:19:57 -04:00
|
|
|
style = []
|
2015-05-21 17:49:06 -04:00
|
|
|
|
|
|
|
if broadcast_message.color.present?
|
2015-12-31 16:42:56 -05:00
|
|
|
style << "background-color: #{broadcast_message.color}"
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|
2015-05-21 17:49:06 -04:00
|
|
|
|
|
|
|
if broadcast_message.font.present?
|
2015-12-31 16:42:56 -05:00
|
|
|
style << "color: #{broadcast_message.font}"
|
2015-05-21 17:49:06 -04:00
|
|
|
end
|
|
|
|
|
2018-08-18 07:19:57 -04:00
|
|
|
style.join('; ')
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|
2016-01-13 11:46:32 -05:00
|
|
|
|
|
|
|
def broadcast_message_status(broadcast_message)
|
|
|
|
if broadcast_message.active?
|
|
|
|
'Active'
|
|
|
|
elsif broadcast_message.ended?
|
|
|
|
'Expired'
|
|
|
|
else
|
|
|
|
'Pending'
|
|
|
|
end
|
|
|
|
end
|
2016-02-03 23:01:04 -05:00
|
|
|
|
2016-10-06 18:01:42 -04:00
|
|
|
def render_broadcast_message(broadcast_message)
|
2020-03-25 17:08:06 -04:00
|
|
|
if broadcast_message.notification?
|
2020-03-24 11:08:44 -04:00
|
|
|
Banzai.render_field_and_post_process(broadcast_message, :message, {
|
2020-03-17 20:09:16 -04:00
|
|
|
current_user: current_user,
|
|
|
|
skip_project_check: true,
|
|
|
|
broadcast_message_placeholders: true
|
|
|
|
}).html_safe
|
|
|
|
else
|
|
|
|
Banzai.render_field(broadcast_message, :message).html_safe
|
|
|
|
end
|
2016-02-03 23:01:04 -05:00
|
|
|
end
|
2020-01-09 19:07:56 -05:00
|
|
|
|
|
|
|
def broadcast_type_options
|
|
|
|
BroadcastMessage.broadcast_types.keys.map { |w| [w.humanize, w] }
|
|
|
|
end
|
2013-12-09 00:34:51 -05:00
|
|
|
end
|