BigW Consortium Gitlab

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

    content_tag :div, class: 'broadcast-message', style: broadcast_message_style(message) do
6
      icon('bullhorn') << ' ' << render_broadcast_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
  def render_broadcast_message(broadcast_message)
    Banzai.render_field(broadcast_message, :message).html_safe
37
  end
38
end