Class: Hyrax::AdminSetSelectionPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/hyrax/admin_set_selection_presenter.rb

Overview

Note:

this supersedes the older Hyrax::AdminSetOptionsPresenter, which actied more like a “service” sending database queries to Solr and ActiveRecord. this version seeks only to present the input data and relies on its caller to pass in the right data.

Presents select options for admin sets.

Each entry in the #select_options return value provides a label for display, an id to serve as the value, and a data hash which is used as HTML5 data entries. The data entries can be used as hooks for Javascript to control input validation taking into account the Admin Set and `PermissionTemplate` rules (`visibility_component.es6` does this, for example).

Since:

  • 3.1.0

Defined Under Namespace

Classes: OptionsEntry

Instance Method Summary collapse

Constructor Details

#initialize(admin_sets:) ⇒ AdminSetSelectionPresenter

Returns a new instance of AdminSetSelectionPresenter.

Parameters:

  • (Array<#id>)

Since:

  • 3.1.0


23
24
25
# File 'app/presenters/hyrax/admin_set_selection_presenter.rb', line 23

def initialize(admin_sets:)
  @admin_sets = admin_sets
end

Instance Method Details

#select_optionsArray<Array<String, String, Hash>>

Returns an array suitable for a form input `collection:` parameter. it should contain a label, an id, and a hash of HTML5 data attributes.

Returns:

  • (Array<Array<String, String, Hash>>)

    an array suitable for a form input `collection:` parameter. it should contain a label, an id, and a hash of HTML5 data attributes.

Since:

  • 3.1.0


31
32
33
34
35
36
37
38
39
40
# File 'app/presenters/hyrax/admin_set_selection_presenter.rb', line 31

def select_options
  @admin_sets.map do |admin_set|
    case admin_set
    when OptionsEntry
      admin_set.result
    else
      OptionsEntry.new(admin_set: admin_set).result
    end
  end
end