Sha256: 8f037ce5ba8c0e51a5f6fa943d6173b9e156ae2e63ab1c5dba71e22afb061b2d

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module MenuBarHelper
  def menu_bar_links
    [
      link_to_profile,
      link_to_classroom,
      link_to_bibliotheca,
      solve_discussions_link,
      user_discussions_link
    ]
  end

  def menu_bar_list_items
    menu_bar_links.compact.map { |link| li_tag(link) }.join.html_safe
  end

  def li_tag(link)
    content_tag :li, link
  end

  def link_to_profile
    menu_item('user', :profile, user_path)
  end

  def link_to_classroom
    link_to_application 'graduation-cap', :classroom_ui, :teacher_here?
  end

  def link_to_bibliotheca
    link_to_application :book, :bibliotheca_ui, :writer?
  end

  def link_to_application(icon, app_name, minimal_permissions)
    return unless current_user&.send(minimal_permissions)
    url = url_for_application(app_name)
    menu_item icon, app_name, url
  end

  def logout_link
    li_tag menu_item('sign-out-alt', :sign_out, logout_path(origin: url_for))
  end

  def menu_item(icon, name, url)
    link_to fixed_fa_icon(icon, text: t(name)), url, role: 'menuitem', tabindex: '-1'
  end

  def any_menu_bar_links?
    menu_bar_links.any?
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mumuki-laboratory-8.5.0 app/helpers/menu_bar_helper.rb
mumuki-laboratory-8.4.0 app/helpers/menu_bar_helper.rb
mumuki-laboratory-8.3.0 app/helpers/menu_bar_helper.rb