Sha256: f660879d05596372cfb4d7579e30d623186820b907937317a3c7855cadfc4c26

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Renalware
  module System
    # Experimental ActionView component
    class AdminMenuComponent < ApplicationComponent
      include Renalware::UsersHelper
      attr_reader :current_user

      def initialize(current_user:)
        @current_user = current_user
      end

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

        menu_item(*args)
      end

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

        menu_item(*args)
      end

      def developer_menu_item(*args)
        return unless current_user_is_developer?

        menu_item(*args)
      end

      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

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
renalware-core-2.0.159 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.158 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.157 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.156 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.155 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.153 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.152 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.151 app/components/renalware/system/admin_menu_component.rb