Sha256: 836769a0c8d7eea02a9891448bc9c1150e9166e405d7a66c89804e1bea20f856

Contents?: true

Size: 1.43 KB

Versions: 25

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true
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

25 entries across 25 versions & 1 rubygems

Version Path
hyrax-3.0.1 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.rc4 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.rc3 app/presenters/hyrax/select_collection_type_list_presenter.rb
hyrax-3.0.0.pre.rc2 app/presenters/hyrax/select_collection_type_list_presenter.rb