Sha256: e8ccc521ca8916a357de5891980540f7dc37a22972e641254e3b827d18c4c422

Contents?: true

Size: 1.4 KB

Versions: 36

Compression:

Stored size: 1.4 KB

Contents

module Hyrax
  # Presents the list of collection type options that a user may choose from when deciding to create a new work
  class SelectCollectionTypeListPresenter
    # @param current_user [User]
    def initialize(current_user)
      @current_user = current_user
    end

    class_attribute :row_presenter
    self.row_presenter = SelectCollectionTypePresenter

    # @return [Boolean] are there many different types to choose?
    def many?
      authorized_collection_types.size > 1
    end

    # @return [Boolean] are there any authorized types?
    def any?
      return true if authorized_collection_types.present?
      false
    end

    # Return an array of authorized collection types.
    def authorized_collection_types
      @authorized_collection_types ||= Hyrax::CollectionTypes::PermissionsService.can_create_collection_types(user: @current_user)
    end

    # Return or yield the first type in the list. This is used when the list
    # only has a single element.
    # @yieldparam [CollectionType] a Hyrax::CollectionType
    # @return [CollectionType] a Hyrax::CollectionType
    def first_collection_type
      yield(authorized_collection_types.first) if block_given?
      authorized_collection_types.first
    end

    # @yieldparam [SelectCollectionTypePresenter] a presenter for the collection
    def each
      authorized_collection_types.each { |type| yield row_presenter.new(type) }
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.9.5 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.9.4 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.9.3 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.9.2 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.9.1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.9.0 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.8.0 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.7.2 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.7.1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.7.0 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.6.0 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.rc1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.beta3 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.5.1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.5.0 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.beta2 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.4.1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.beta1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-2.4.0 app/presenters/hyrax/select_collection_type_list_presenter.rb