Sha256: 10a84b3d320d8fb0d2783c7a4a7cc9d642b5e32d3008d5575ebae673181adcbd

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

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

      rattr_initialize [:current_user!]

      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

10 entries across 10 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.1.0 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.167 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.166 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.165 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.164 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.163 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.162 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.161 app/components/renalware/system/admin_menu_component.rb
renalware-core-2.0.160 app/components/renalware/system/admin_menu_component.rb