Module: StrongMindNav
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/controllers/concerns/strong_mind_nav.rb
Constant Summary collapse
- NAVBAR_CACHE_KEY_SUFFIX =
'navbar'
Instance Method Summary collapse
- #build_nav_items ⇒ Object
- #common_nav_options ⇒ Object
- #fetch_common_nav ⇒ Object
- #menu_items ⇒ Object
- #nav_item_data(item) ⇒ Object
Instance Method Details
#build_nav_items ⇒ Object
48 49 50 51 52 |
# File 'app/controllers/concerns/strong_mind_nav.rb', line 48 def build_nav_items items = { nav_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_options ⇒ Object
41 42 43 44 45 46 |
# File 'app/controllers/concerns/strong_mind_nav.rb', line 41 def { authenticity_token: form_authenticity_token, show_role_switcher: false } end |
#fetch_common_nav ⇒ Object
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 = (nav_items) = Rails.cache.fetch(user_cache_key_encoded, expires_in: 1.day) do Strongmind::CommonNavFetcher.new(current_user).retrieve(nav_items, ) end = [:top_navbar_html] = [:bottom_navbar_html] @theme_css = [: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) = render_to_string(partial: 'layouts/loading_navbar').html_safe end end |
#menu_items ⇒ Object
35 36 37 38 39 |
# File 'app/controllers/concerns/strong_mind_nav.rb', line 35 def [ { name: 'Home', icon: 'fa-solid fa-house', url: root_path } ] end |
#nav_item_data(item) ⇒ Object
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 |