Module: BroadcastMessagesHelper

Includes:
Gitlab::Utils::StrongMemoize
Included in:
Admin::BroadcastMessagesController
Defined in:
app/helpers/broadcast_messages_helper.rb

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Instance Method Details

#broadcast_message(message, opts = {}) ⇒ Object


25
26
27
28
29
# File 'app/helpers/broadcast_messages_helper.rb', line 25

def broadcast_message(message, opts = {})
  return unless message.present?

  render "shared/broadcast_message", { message: message, **opts }
end

#broadcast_message_status(broadcast_message) ⇒ Object


31
32
33
34
35
36
37
38
39
# File 'app/helpers/broadcast_messages_helper.rb', line 31

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

#broadcast_theme_optionsObject


57
58
59
# File 'app/helpers/broadcast_messages_helper.rb', line 57

def broadcast_theme_options
  BroadcastMessage.themes.keys
end

#broadcast_type_optionsObject


53
54
55
# File 'app/helpers/broadcast_messages_helper.rb', line 53

def broadcast_type_options
  BroadcastMessage.broadcast_types.keys.map { |w| [w.humanize, w] }
end

#current_broadcast_banner_messagesObject


6
7
8
9
10
11
12
13
# File 'app/helpers/broadcast_messages_helper.rb', line 6

def current_broadcast_banner_messages
  BroadcastMessage.current_banner_messages(
    current_path: request.path,
    user_access_level: current_user_access_level_for_project_or_group
  ).select do |message|
    cookies["hide_broadcast_message_#{message.id}"].blank?
  end
end

#current_broadcast_notification_messageObject


15
16
17
18
19
20
21
22
23
# File 'app/helpers/broadcast_messages_helper.rb', line 15

def current_broadcast_notification_message
  not_hidden_messages = BroadcastMessage.current_notification_messages(
    current_path: request.path,
    user_access_level: current_user_access_level_for_project_or_group
  ).select do |message|
    cookies["hide_broadcast_message_#{message.id}"].blank?
  end
  not_hidden_messages.last
end

#render_broadcast_message(broadcast_message) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/broadcast_messages_helper.rb', line 41

def render_broadcast_message(broadcast_message)
  if broadcast_message.notification?
    Banzai.render_field_and_post_process(broadcast_message, :message, {
      current_user: current_user,
      skip_project_check: true,
      broadcast_message_placeholders: true
    }).html_safe
  else
    Banzai.render_field(broadcast_message, :message).html_safe
  end
end

#target_access_level_optionsObject


61
62
63
64
65
# File 'app/helpers/broadcast_messages_helper.rb', line 61

def target_access_level_options
  BroadcastMessage::ALLOWED_TARGET_ACCESS_LEVELS.map do |access_level|
    [Gitlab::Access.human_access(access_level), access_level]
  end
end

#target_access_levels_display(access_levels) ⇒ Object


67
68
69
70
71
# File 'app/helpers/broadcast_messages_helper.rb', line 67

def target_access_levels_display(access_levels)
  access_levels.map do |access_level|
    Gitlab::Access.human_access(access_level)
  end.join(', ')
end