Class: Hyrax::CollectionPresenter
- Inherits:
-
Object
- Object
- Hyrax::CollectionPresenter
- Includes:
- ActionView::Helpers::NumberHelper, ActionView::Helpers::TagHelper, ModelProxy, PresentsAttributes
- Defined in:
- app/presenters/hyrax/collection_presenter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #collection_type ⇒ Object
-
#current_ability ⇒ Object
Returns the value of attribute current_ability.
-
#parent_collections ⇒ Object
This is expected to be a Blacklight::Solr::Response with all of the parent collections.
-
#request ⇒ Object
Returns the value of attribute request.
-
#solr_document ⇒ Object
Returns the value of attribute solr_document.
-
#subcollection_count ⇒ Object
Returns the value of attribute subcollection_count.
Class Method Summary collapse
-
.terms ⇒ Object
Terms is the list of fields displayed by app/views/collections/_show_descriptions.html.erb.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#allow_batch? ⇒ Boolean
Determine if the user can perform batch operations on this collection.
- #available_parent_collections(scope:) ⇒ Object
-
#banner_file ⇒ #to_s?
A download path for the banner file.
- #collection_type_badge ⇒ Object
- #create_many_work_types? ⇒ Boolean
-
#create_work_presenter ⇒ Object
A presenter for selecting a work type to create this is needed here because the selector is in the header on every page.
- #draw_select_work_modal? ⇒ Boolean
- #first_work_type ⇒ Object
-
#initialize(solr_document, current_ability, request = nil) ⇒ CollectionPresenter
constructor
A new instance of CollectionPresenter.
- #logo_record ⇒ Object
-
#managed_access ⇒ Object
For the Managed Collections tab, determine the label to use for the level of access the user has for this admin set.
-
#parent_collection_count ⇒ Object
The number of parent collections shown on the current page.
- #show_path ⇒ Object
-
#size ⇒ String
deprecated
Deprecated.
to be removed in 4.0.0; this feature was replaced with a hard-coded null implementation
- #terms_with_values ⇒ Object
- #total_items ⇒ Object
-
#total_parent_collections ⇒ Object
The total number of parents that this collection belongs to, visible or not.
- #total_viewable_collections ⇒ Object
- #total_viewable_items ⇒ Object
- #total_viewable_works ⇒ Object
- #user_can_create_new_nest_collection? ⇒ Boolean
- #user_can_nest_collection? ⇒ Boolean
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, #valid_child_concerns
Constructor Details
#initialize(solr_document, current_ability, request = nil) ⇒ CollectionPresenter
Returns a new instance of CollectionPresenter.
19 20 21 22 23 24 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 19 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_type ⇒ Object
32 33 34 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 32 def collection_type @collection_type ||= Hyrax::CollectionType.find_by_gid!(collection_type_gid) end |
#current_ability ⇒ Object
Returns the value of attribute current_ability.
8 9 10 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 8 def current_ability @current_ability end |
#parent_collections ⇒ Object
This is expected to be a Blacklight::Solr::Response with all of the parent collections
10 11 12 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 10 def parent_collections @parent_collections end |
#request ⇒ Object
Returns the value of attribute request.
8 9 10 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 8 def request @request end |
#solr_document ⇒ Object
Returns the value of attribute solr_document.
8 9 10 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 8 def solr_document @solr_document end |
#subcollection_count ⇒ Object
Returns the value of attribute subcollection_count.
9 10 11 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 9 def subcollection_count @subcollection_count end |
Class Method Details
.terms ⇒ Object
Terms is the list of fields displayed by app/views/collections/_show_descriptions.html.erb
44 45 46 47 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 44 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
56 57 58 59 60 61 62 63 64 65 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 56 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
187 188 189 190 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 187 def allow_batch? return true if current_ability.can?(:edit, solr_document) false end |
#available_parent_collections(scope:) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 157 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 |
#banner_file ⇒ #to_s?
Returns a download path for the banner file.
124 125 126 127 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 124 def = CollectionBrandingInfo.find_by(collection_id: id, role: "banner") "/" + .local_path.split("/")[-4..-1].join("/") if end |
#collection_type_badge ⇒ Object
95 96 97 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 95 def collection_type_badge tag.span(collection_type.title, class: "label", style: "background-color: " + collection_type.badge_color + ";") end |
#create_many_work_types? ⇒ Boolean
145 146 147 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 145 def create_many_work_types? create_work_presenter.many? end |
#create_work_presenter ⇒ Object
A presenter for selecting a work type to create this is needed here because the selector is in the header on every page
141 142 143 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 141 def create_work_presenter @create_work_presenter ||= create_work_presenter_class.new(current_ability.current_user) end |
#draw_select_work_modal? ⇒ Boolean
149 150 151 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 149 def draw_select_work_modal? create_many_work_types? end |
#first_work_type ⇒ Object
153 154 155 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 153 def first_work_type create_work_presenter.first_model end |
#logo_record ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 129 def logo_record CollectionBrandingInfo.where(collection_id: id, role: "logo") .select(:local_path, :alt_text, :target_url).map do |logo| { alttext: logo.alt_text, file: File.split(logo.local_path).last, file_location: "/#{logo.local_path.split('/')[-4..-1].join('/')}", linkurl: logo.target_url } end end |
#managed_access ⇒ Object
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.
174 175 176 177 178 179 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 174 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_count ⇒ Object
The number of parent collections shown on the current page. This will differ from total_parent_collections due to pagination.
106 107 108 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 106 def parent_collection_count parent_collections.nil? ? 0 : parent_collections.documents.size end |
#show_path ⇒ Object
118 119 120 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 118 def show_path Hyrax::Engine.routes.url_helpers.dashboard_collection_path(id, locale: I18n.locale) end |
#size ⇒ String
to be removed in 4.0.0; this feature was replaced with a hard-coded null implementation
Returns ‘unknown’.
70 71 72 73 74 75 76 77 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 70 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_values ⇒ Object
49 50 51 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 49 def terms_with_values self.class.terms.select { |t| self[t].present? } end |
#total_items ⇒ Object
79 80 81 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 79 def total_items Hyrax::SolrService.new.count("member_of_collection_ids_ssim:#{id}") end |
#total_parent_collections ⇒ Object
The total number of parents that this collection belongs to, visible or not.
100 101 102 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 100 def total_parent_collections parent_collections.nil? ? 0 : parent_collections.response['numFound'] end |
#total_viewable_collections ⇒ Object
91 92 93 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 91 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_items ⇒ Object
83 84 85 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 83 def total_viewable_items ActiveFedora::Base.where("member_of_collection_ids_ssim:#{id}").accessible_by(current_ability).count end |
#total_viewable_works ⇒ Object
87 88 89 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 87 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
114 115 116 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 114 def user_can_create_new_nest_collection? current_ability.can?(:create_collection_of_type, collection_type) end |
#user_can_nest_collection? ⇒ Boolean
110 111 112 |
# File 'app/presenters/hyrax/collection_presenter.rb', line 110 def user_can_nest_collection? current_ability.can?(:deposit, solr_document) end |