Module: StrongMindNav

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/strong_mind_nav.rb

Constant Summary collapse

'navbar'

Instance Method Summary collapse

Instance Method Details

#build_nav_itemsObject



48
49
50
51
52
# File 'app/controllers/concerns/strong_mind_nav.rb', line 48

def build_nav_items
  items = { nav_items: menu_items.map { |item| nav_item_data(item) } }
  items[:nav_items].first[:is_active] = true unless items[:nav_items].any? { |item| item[:is_active] }
  items
end

#common_nav_optionsObject



41
42
43
44
45
46
# File 'app/controllers/concerns/strong_mind_nav.rb', line 41

def common_nav_options
  {
    authenticity_token: form_authenticity_token,
    show_role_switcher: false
  }
end

#fetch_common_navObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/concerns/strong_mind_nav.rb', line 9

def fetch_common_nav
  begin
    nav_items = build_nav_items

    user_cache_key_encoded = generate_user_navbar_cache_key(nav_items)
    navbar = Rails.cache.fetch(user_cache_key_encoded, expires_in: 1.day) do
      Strongmind::CommonNavFetcher.new(current_user).retrieve(nav_items, common_nav_options)
    end

    @top_navbar_html = navbar[:top_navbar_html]
    @bottom_navbar_html = navbar[:bottom_navbar_html]
    @theme_css = navbar[:theme_css]
  rescue Strongmind::Exceptions::TokenNotFoundError, Strongmind::Exceptions::UserNotFoundError, Strongmind::Exceptions::RefreshTokenExpiredError => e
    Sentry.capture_exception(e) if e.is_a? Strongmind::Exceptions::UserNotFoundError
    Rails.logger.error(e)
    flash[:alert] = e.inspect if Rails.env.development? || Rails.env.test?
    @stop_redirect = true if Rails.env.development? || Rails.env.test?
    current_user.invalidate_all_sessions! if current_user
    render 'logins/index' and return
  rescue Exception => e
    Sentry.capture_exception(e)
    Rails.logger.error(e)
    @top_navbar_html = render_to_string(partial: 'layouts/loading_navbar').html_safe
  end
end


35
36
37
38
39
# File 'app/controllers/concerns/strong_mind_nav.rb', line 35

def menu_items
  [
    { name: 'Home', icon: 'fa-solid fa-house', url: root_path }
  ]
end


54
55
56
57
58
59
60
61
62
# File 'app/controllers/concerns/strong_mind_nav.rb', line 54

def nav_item_data(item)
  url = item[:url]
  {
    name: item[:name],
    icon: item[:icon],
    url: url,
    is_active: current_page?(url)
  }
end