Class: Renalware::System::AdminMenuComponent

Inherits:
ApplicationComponent show all
Includes:
UsersHelper
Defined in:
app/components/renalware/system/admin_menu_component.rb

Overview

Experimental ActionView component

Instance Method Summary collapse

Methods included from UsersHelper

#current_user_is_admin?, #current_user_is_developer?, #current_user_is_super_admin?

Methods inherited from ApplicationComponent

#policy, #renalware

Instance Method Details

#admin_menu_item(*args) ⇒ Object



11
12
13
14
15
16
17
18
# File 'app/components/renalware/system/admin_menu_component.rb', line 11

def admin_menu_item(*args)
  return unless
    current_user_is_admin? ||
    current_user_is_super_admin? ||
    current_user_is_developer?

  menu_item(*args)
end

#current_controller_matches(regex) ⇒ Object



44
45
46
# File 'app/components/renalware/system/admin_menu_component.rb', line 44

def current_controller_matches(regex)
  regex.match(params[:controller]).present?
end

#developer_menu_item(*args) ⇒ Object



26
27
28
29
30
# File 'app/components/renalware/system/admin_menu_component.rb', line 26

def developer_menu_item(*args)
  return unless current_user_is_developer?

  menu_item(*args)
end

#formatted_nhs_number(patient) ⇒ Object



48
49
50
# File 'app/components/renalware/system/admin_menu_component.rb', line 48

def formatted_nhs_number(patient)
  ::Renalware::PatientPresenter.new(patient).nhs_number
end


32
33
34
35
36
37
38
39
40
41
42
# File 'app/components/renalware/system/admin_menu_component.rb', line 32

def menu_item(title, path, active_when_controller_matches, enabled = true)
  klasses = %w(link)
  klasses << "active" if current_controller_matches(active_when_controller_matches)
  tag.li class: klasses.join(" ") do
    if enabled
      link_to(title, path)
    else
      tag.span title
    end
  end
end

#super_admin_menu_item(*args) ⇒ Object



20
21
22
23
24
# File 'app/components/renalware/system/admin_menu_component.rb', line 20

def super_admin_menu_item(*args)
  return unless current_user_is_super_admin? || current_user_is_developer?

  menu_item(*args)
end