BigW Consortium Gitlab

broadcast_messages_helper.rb 962 Bytes
Newer Older
1
module BroadcastMessagesHelper
2 3 4 5
  def broadcast_message(message = BroadcastMessage.current)
    return unless message.present?

    content_tag :div, class: 'broadcast-message', style: broadcast_message_style(message) do
6
      icon('bullhorn') << ' ' << render_broadcast_message(message.message)
7 8 9 10 11
    end
  end

  def broadcast_message_style(broadcast_message)
    style = ''
12 13

    if broadcast_message.color.present?
14 15
      style << "background-color: #{broadcast_message.color}"
      style << '; ' if broadcast_message.font.present?
16
    end
17 18

    if broadcast_message.font.present?
19
      style << "color: #{broadcast_message.font}"
20 21
    end

22
    style
23
  end
24 25 26 27 28 29 30 31 32 33

  def broadcast_message_status(broadcast_message)
    if broadcast_message.active?
      'Active'
    elsif broadcast_message.ended?
      'Expired'
    else
      'Pending'
    end
  end
34 35 36 37

  def render_broadcast_message(message)
    Banzai.render(message, pipeline: :broadcast_message).html_safe
  end
38
end