debian-mirror-gitlab/app/helpers/broadcast_messages_helper.rb
2020-03-09 13:42:32 +05:30

54 lines
1.3 KiB
Ruby

# frozen_string_literal: true
module BroadcastMessagesHelper
def current_broadcast_banner_messages
BroadcastMessage.current_banner_messages(request.path)
end
def current_broadcast_notification_message
not_hidden_messages = BroadcastMessage.current_notification_messages(request.path).select do |message|
cookies["hide_broadcast_notification_message_#{message.id}"].blank?
end
not_hidden_messages.last
end
def broadcast_message(message, opts = {})
return unless message.present?
render "shared/broadcast_message", { message: message, opts: opts }
end
def broadcast_message_style(broadcast_message)
return '' if broadcast_message.notification?
style = []
if broadcast_message.color.present?
style << "background-color: #{broadcast_message.color}"
end
if broadcast_message.font.present?
style << "color: #{broadcast_message.font}"
end
style.join('; ')
end
def broadcast_message_status(broadcast_message)
if broadcast_message.active?
'Active'
elsif broadcast_message.ended?
'Expired'
else
'Pending'
end
end
def render_broadcast_message(broadcast_message)
Banzai.render_field(broadcast_message, :message).html_safe
end
def broadcast_type_options
BroadcastMessage.broadcast_types.keys.map { |w| [w.humanize, w] }
end
end