Class: Hyrax::CollectionPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::NumberHelper, ActionView::Helpers::TagHelper, ModelProxy, PresentsAttributes
Defined in:
app/presenters/hyrax/collection_presenter.rb

Direct Known Subclasses

AdminSetPresenter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PresentsAttributes

#attribute_to_html, #display_microdata?, #microdata_type_to_html, #permission_badge, #permission_badge_class

Methods included from ModelProxy

#persisted?, #to_model, #to_partial_path

Constructor Details

#initialize(solr_document, current_ability, request = nil) ⇒ CollectionPresenter

Returns a new instance of CollectionPresenter.

Parameters:

  • solr_document (SolrDocument)
  • current_ability (Ability)
  • request (ActionDispatch::Request) (defaults to: nil)

    the http request context



18
19
20
21
22
23
# File 'app/presenters/hyrax/collection_presenter.rb', line 18

def initialize(solr_document, current_ability, request = nil)
  @solr_document = solr_document
  @current_ability = current_ability
  @request = request
  @subcollection_count = 0
end

Instance Attribute Details

#collection_typeObject



31
32
33
# File 'app/presenters/hyrax/collection_presenter.rb', line 31

def collection_type
  @collection_type ||= Hyrax::CollectionType.find_by_gid!(collection_type_gid)
end

#current_abilityObject

Returns the value of attribute current_ability.



7
8
9
# File 'app/presenters/hyrax/collection_presenter.rb', line 7

def current_ability
  @current_ability
end

#parent_collectionsObject

This is expected to be a Blacklight::Solr::Response with all of the parent collections



9
10
11
# File 'app/presenters/hyrax/collection_presenter.rb', line 9

def parent_collections
  @parent_collections
end

#requestObject

Returns the value of attribute request.



7
8
9
# File 'app/presenters/hyrax/collection_presenter.rb', line 7

def request
  @request
end

#solr_documentObject

Returns the value of attribute solr_document.



7
8
9
# File 'app/presenters/hyrax/collection_presenter.rb', line 7

def solr_document
  @solr_document
end

#subcollection_countObject

Returns the value of attribute subcollection_count.



8
9
10
# File 'app/presenters/hyrax/collection_presenter.rb', line 8

def subcollection_count
  @subcollection_count
end

Class Method Details

.termsObject

Terms is the list of fields displayed by app/views/collections/_show_descriptions.html.erb



43
44
45
46
# File 'app/presenters/hyrax/collection_presenter.rb', line 43

def self.terms
  [:total_items, :size, :resource_type, :creator, :contributor, :keyword, :license, :publisher, :date_created, :subject,
   :language, :identifier, :based_near, :related_url]
end

Instance Method Details

#[](key) ⇒ Object

Parameters:

  • key (Symbol)

Returns:

  • (Object)


55
56
57
58
59
60
61
62
63
64
# File 'app/presenters/hyrax/collection_presenter.rb', line 55

def [](key)
  case key
  when :size
    size
  when :total_items
    total_items
  else
    solr_document.send key
  end
end

#allow_batch?Boolean

Determine if the user can perform batch operations on this collection. Currently, the only batch operation allowed is deleting, so this is equivalent to checking if the user can delete the collection determined by criteria…

  • user must be able to edit the collection to be able to delete it

  • the collection does not have to be empty

Returns:

  • (Boolean)

    Boolean true if the user can perform batch actions; otherwise, false



190
191
192
193
# File 'app/presenters/hyrax/collection_presenter.rb', line 190

def allow_batch?
  return true if current_ability.can?(:edit, solr_document)
  false
end

#available_parent_collections(scope:) ⇒ Object



160
161
162
163
164
165
166
167
168
# File 'app/presenters/hyrax/collection_presenter.rb', line 160

def available_parent_collections(scope:)
  return @available_parents if @available_parents.present?
  collection = Collection.find(id)
  colls = Hyrax::Collections::NestedCollectionQueryService.available_parent_collections(child: collection, scope: scope, limit_to_id: nil)
  @available_parents = colls.map do |col|
    { "id" => col.id, "title_first" => col.title.first }
  end
  @available_parents.to_json
end


121
122
123
124
125
# File 'app/presenters/hyrax/collection_presenter.rb', line 121

def banner_file
  # Find Banner filename
  ci = CollectionBrandingInfo.where(collection_id: id, role: "banner")
  "/" + ci[0].local_path.split("/")[-4..-1].join("/") unless ci.empty?
end

#collection_type_badgeObject



94
95
96
# File 'app/presenters/hyrax/collection_presenter.rb', line 94

def collection_type_badge
  (:span, collection_type.title, class: "label", style: "background-color: " + collection_type.badge_color + ";")
end

#create_many_work_types?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'app/presenters/hyrax/collection_presenter.rb', line 148

def create_many_work_types?
  create_work_presenter.many?
end

#create_work_presenterObject

A presenter for selecting a work type to create this is needed here because the selector is in the header on every page



144
145
146
# File 'app/presenters/hyrax/collection_presenter.rb', line 144

def create_work_presenter
  @create_work_presenter ||= create_work_presenter_class.new(current_ability.current_user)
end

#draw_select_work_modal?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'app/presenters/hyrax/collection_presenter.rb', line 152

def draw_select_work_modal?
  create_many_work_types?
end

#first_work_typeObject



156
157
158
# File 'app/presenters/hyrax/collection_presenter.rb', line 156

def first_work_type
  create_work_presenter.first_model
end

#logo_recordObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/presenters/hyrax/collection_presenter.rb', line 127

def logo_record
  logo_info = []
  # Find Logo filename, alttext, linktext
  cis = CollectionBrandingInfo.where(collection_id: id, role: "logo")
  return if cis.empty?
  cis.each do |coll_info|
    logo_file = File.split(coll_info.local_path).last
    file_location = "/" + coll_info.local_path.split("/")[-4..-1].join("/") unless logo_file.empty?
    alttext = coll_info.alt_text
    linkurl = coll_info.target_url
    logo_info << { file: logo_file, file_location: file_location, alttext: alttext, linkurl: linkurl }
  end
  logo_info
end

#managed_accessObject

For the Managed Collections tab, determine the label to use for the level of access the user has for this admin set. Checks from most permissive to most restrictive.

Returns:

  • String the access label (e.g. Manage, Deposit, View)



177
178
179
180
181
182
# File 'app/presenters/hyrax/collection_presenter.rb', line 177

def managed_access
  return I18n.t('hyrax.dashboard.my.collection_list.managed_access.manage') if current_ability.can?(:edit, solr_document)
  return I18n.t('hyrax.dashboard.my.collection_list.managed_access.deposit') if current_ability.can?(:deposit, solr_document)
  return I18n.t('hyrax.dashboard.my.collection_list.managed_access.view') if current_ability.can?(:read, solr_document)
  ''
end

#parent_collection_countObject

The number of parent collections shown on the current page. This will differ from total_parent_collections due to pagination.



105
106
107
# File 'app/presenters/hyrax/collection_presenter.rb', line 105

def parent_collection_count
  parent_collections.nil? ? 0 : parent_collections.documents.size
end

#show_pathObject



117
118
119
# File 'app/presenters/hyrax/collection_presenter.rb', line 117

def show_path
  Hyrax::Engine.routes.url_helpers.dashboard_collection_path(id, locale: I18n.locale)
end

#sizeString

Deprecated.

to be removed in 4.0.0; this feature was replaced with a hard-coded null implementation

Returns ‘unknown’.

Returns:

  • (String)

    ‘unknown’



69
70
71
72
73
74
75
76
# File 'app/presenters/hyrax/collection_presenter.rb', line 69

def size
  Deprecation.warn('#size has been deprecated for removal in Hyrax 4.0.0; ' \
                   'The implementation of the indexed Collection size ' \
                   'feature is extremely inefficient, so it has been removed. ' \
                   'This method now returns a hard-coded `"unknown"` for ' \
                   'compatibility.')
  'unknown'
end

#terms_with_valuesObject



48
49
50
# File 'app/presenters/hyrax/collection_presenter.rb', line 48

def terms_with_values
  self.class.terms.select { |t| self[t].present? }
end

#total_itemsObject



78
79
80
# File 'app/presenters/hyrax/collection_presenter.rb', line 78

def total_items
  ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}").count
end

#total_parent_collectionsObject

The total number of parents that this collection belongs to, visible or not.



99
100
101
# File 'app/presenters/hyrax/collection_presenter.rb', line 99

def total_parent_collections
  parent_collections.nil? ? 0 : parent_collections.response['numFound']
end

#total_viewable_collectionsObject



90
91
92
# File 'app/presenters/hyrax/collection_presenter.rb', line 90

def total_viewable_collections
  ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id} AND generic_type_sim:Collection").accessible_by(current_ability).count
end

#total_viewable_itemsObject



82
83
84
# File 'app/presenters/hyrax/collection_presenter.rb', line 82

def total_viewable_items
  ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}").accessible_by(current_ability).count
end

#total_viewable_worksObject



86
87
88
# File 'app/presenters/hyrax/collection_presenter.rb', line 86

def total_viewable_works
  ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id} AND generic_type_sim:Work").accessible_by(current_ability).count
end

#user_can_create_new_nest_collection?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'app/presenters/hyrax/collection_presenter.rb', line 113

def user_can_create_new_nest_collection?
  current_ability.can?(:create_collection_of_type, collection_type)
end

#user_can_nest_collection?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'app/presenters/hyrax/collection_presenter.rb', line 109

def user_can_nest_collection?
  current_ability.can?(:deposit, solr_document)
end