debian-mirror-gitlab/app/helpers/broadcast_messages_helper.rb

65 lines
1.7 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
module BroadcastMessagesHelper
2020-03-13 15:44:24 +05:30
def current_broadcast_banner_messages
2020-04-08 14:13:33 +05:30
BroadcastMessage.current_banner_messages(request.path).select do |message|
cookies["hide_broadcast_message_#{message.id}"].blank?
end
2020-01-01 13:55:28 +05:30
end
2020-03-13 15:44:24 +05:30
def current_broadcast_notification_message
not_hidden_messages = BroadcastMessage.current_notification_messages(request.path).select do |message|
2020-04-08 14:13:33 +05:30
cookies["hide_broadcast_message_#{message.id}"].blank?
2020-03-13 15:44:24 +05:30
end
not_hidden_messages.last
end
def broadcast_message(message, opts = {})
return unless message.present?
2020-03-13 15:44:24 +05:30
render "shared/broadcast_message", { message: message, opts: opts }
end
def broadcast_message_style(broadcast_message)
2020-03-13 15:44:24 +05:30
return '' if broadcast_message.notification?
2018-12-05 23:21:45 +05:30
style = []
2015-09-11 14:41:01 +05:30
if broadcast_message.color.present?
style << "background-color: #{broadcast_message.color}"
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
if broadcast_message.font.present?
style << "color: #{broadcast_message.font}"
2015-09-11 14:41:01 +05:30
end
2018-12-05 23:21:45 +05:30
style.join('; ')
end
def broadcast_message_status(broadcast_message)
if broadcast_message.active?
'Active'
elsif broadcast_message.ended?
'Expired'
else
'Pending'
end
2014-09-02 18:07:02 +05:30
end
2016-04-02 18:10:28 +05:30
2016-11-03 12:29:30 +05:30
def render_broadcast_message(broadcast_message)
2020-04-22 19:07:51 +05:30
if broadcast_message.notification?
Banzai.render_field_and_post_process(broadcast_message, :message, {
2020-04-08 14:13:33 +05:30
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-04-02 18:10:28 +05:30
end
2020-03-13 15:44:24 +05:30
def broadcast_type_options
BroadcastMessage.broadcast_types.keys.map { |w| [w.humanize, w] }
end
2014-09-02 18:07:02 +05:30
end