Class: Hyrax::MenuPresenter
- Inherits:
-
Object
- Object
- Hyrax::MenuPresenter
- Defined in:
- app/presenters/hyrax/menu_presenter.rb
Overview
view-model for the admin menu
Class Attributes collapse
Instance Attribute Summary collapse
-
#view_context ⇒ Object
readonly
Returns the value of attribute view_context.
Instance Method Summary collapse
- #analytics_reporting_section? ⇒ Boolean
-
#collapsable_section(text, id:, icon_class:, open:, title: nil, &block) ⇒ Object
Draw a collaspable menu section.
-
#initialize(view_context) ⇒ MenuPresenter
constructor
A new instance of MenuPresenter.
- #nav_link(options, also_active_for: nil, **link_html_options) ⇒ Object
-
#settings_section? ⇒ Boolean
Returns true if the current controller happens to be one of the controllers that deals with settings.
-
#show_configuration? ⇒ Boolean
Will the configuration section be displayed to the user.
-
#user_activity_section? ⇒ Boolean
with user activity This is used to keep the parent section on the sidebar open.
Constructor Details
#initialize(view_context) ⇒ MenuPresenter
Returns a new instance of MenuPresenter.
5 6 7 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 5 def initialize(view_context) @view_context = view_context end |
Instance Attribute Details
#section_controller_names ⇒ Array<String>
20 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 20 class_attribute :section_controller_names, default: %w[appearances content_blocks features pages collection_types] |
#view_context ⇒ Object (readonly)
Returns the value of attribute view_context.
9 10 11 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 9 def view_context @view_context end |
Instance Method Details
#analytics_reporting_section? ⇒ Boolean
56 57 58 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 56 def analytics_reporting_section? %w[work_reports collection_reports].include?(controller_name) end |
#collapsable_section(text, id:, icon_class:, open:, title: nil, &block) ⇒ Object
Draw a collaspable menu section. The passed block should contain <li> items.
62 63 64 65 66 67 68 69 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 62 def collapsable_section(text, id:, icon_class:, open:, title: nil, &block) CollapsableSectionPresenter.new(view_context: view_context, text: text, id: id, icon_class: icon_class, title: title, open: open).render(&block) end |
#nav_link(options, also_active_for: nil, **link_html_options) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 33 def nav_link(, also_active_for: nil, **) active_urls = [, also_active_for].compact = active_urls.any? { |url| current_page?(url) } ? { class: 'active nav-item' } : { class: 'nav-item' } tag.li() do link_to(, ) 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.
26 27 28 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 26 def settings_section? section_controller_names.include?(controller_name) end |
#show_configuration? ⇒ Boolean
Returns will the configuration section be displayed to the user.
72 73 74 75 76 77 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 72 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.
45 46 47 48 49 50 51 52 53 54 |
# File 'app/presenters/hyrax/menu_presenter.rb', line 45 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 |