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 Attribute Summary collapse

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

Constructor Details

#initialize(current_user:) ⇒ AdminMenuComponent

Returns a new instance of AdminMenuComponent.



10
11
12
# File 'app/components/renalware/system/admin_menu_component.rb', line 10

def initialize(current_user:)
  @current_user = current_user
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user.



8
9
10
# File 'app/components/renalware/system/admin_menu_component.rb', line 8

def current_user
  @current_user
end

Instance Method Details

#admin_menu_item(*args) ⇒ Object



14
15
16
17
18
19
20
21
# File 'app/components/renalware/system/admin_menu_component.rb', line 14

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



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

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

#developer_menu_item(*args) ⇒ Object



29
30
31
32
33
# File 'app/components/renalware/system/admin_menu_component.rb', line 29

def developer_menu_item(*args)
  return unless current_user_is_developer?

  menu_item(*args)
end

#formatted_nhs_number(patient) ⇒ Object



51
52
53
# File 'app/components/renalware/system/admin_menu_component.rb', line 51

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


35
36
37
38
39
40
41
42
43
44
45
# File 'app/components/renalware/system/admin_menu_component.rb', line 35

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

#super_admin_menu_item(*args) ⇒ Object



23
24
25
26
27
# File 'app/components/renalware/system/admin_menu_component.rb', line 23

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

  menu_item(*args)
end