Class: Hyrax::MenuPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb

Overview

view-model for the admin menu

Direct Known Subclasses

Hyku::MenuPresenter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_context) ⇒ MenuPresenter

Returns a new instance of MenuPresenter.



4
5
6
# File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 4

def initialize(view_context)
  @view_context = view_context
end

Instance Attribute Details

#view_context ⇒ Object (readonly)

Returns the value of attribute view_context.



8
9
10
# File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 8

def view_context
  @view_context
end

Instance Method Details

#cdm_migrator_section? ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 19

def cdm_migrator_section?
  %w[cdm csv].include?(controller_name)
end

#collapsable_section(text, id:, icon_class:, open:, &block) ⇒ Object

Draw a collaspable menu section. The passed block should contain

  • items.

  • 
    
    50
    51
    52
    53
    54
    55
    56
    # File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 50
    
    def collapsable_section(text, id:, icon_class:, open:, &block)
      CollapsableSectionPresenter.new(view_context: view_context,
                                      text: text,
                                      id: id,
                                      icon_class: icon_class,
                                      open: open).render(&block)
    end

    Parameters:

    • options (Hash, String) —

      a hash or string representing the path. Hash is prefered as it allows us to workaround https://github.com/rails/rails/issues/28253

    • also_active_for (Hash, String) (defaults to: nil) —

      a hash or string with alternative paths that should be 'active'

    
    
    26
    27
    28
    29
    30
    31
    32
    33
    34
    # File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 26
    
    def nav_link(options, also_active_for: nil, **link_html_options)
      active_urls = [options, also_active_for].compact
      list_options = active_urls.any? { |url| current_page?(url) } ? { class: 'active' } : {}
      (:li, list_options) do
        link_to(options, link_html_options) do
          yield
        end
      end
    end

    #settings_section? ⇒ Boolean

    Returns true if the current controller happens to be one of the controllers that deals with settings. This is used to keep the parent section on the sidebar open.

    Returns:

    • (Boolean)
    
    
    15
    16
    17
    # File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 15
    
    def settings_section?
      %w[appearances content_blocks features pages collection_types].include?(controller_name)
    end

    #show_configuration? ⇒ Boolean

    Returns will the configuration section be displayed to the user.

    Returns:

    • (Boolean) —

      will the configuration section be displayed to the user

    
    
    59
    60
    61
    62
    63
    64
    # File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 59
    
    def show_configuration?
      can?(:update, :appearance) ||
        can?(:manage, :collection_types) ||
        can?(:manage, Sipity::WorkflowResponsibility) ||
        can?(:manage, Hyrax::Feature)
    end

    #user_activity_section? ⇒ Boolean

    with user activity This is used to keep the parent section on the sidebar open.

    Returns:

    • (Boolean) —

      true if the current controller happens to be one of the controllers that deals

    
    
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    # File 'lib/generators/cdm_migrator/install/templates/presenters/hyrax/menu_presenter.rb', line 38
    
    def user_activity_section?
      # we're using a case here because we need to differentiate UsersControllers
      # in different namespaces (Hyrax & Admin)
      case controller
      when Hyrax::UsersController, Hyrax::NotificationsController, Hyrax::TransfersController, Hyrax::DepositorsController
        true
      else
        false
      end
    end