Class: Hyrax::WorkShowPresenter
- Inherits:
-
Object
- Object
- Hyrax::WorkShowPresenter
- Includes:
- MissingMethodBehavior, ModelProxy, PresentsAttributes
- Defined in:
- app/presenters/hyrax/work_show_presenter.rb
Instance Attribute Summary collapse
-
#current_ability ⇒ Object
Returns the value of attribute current_ability.
-
#member_presenter_factory ⇒ Object
writeonly
Sets the attribute member_presenter_factory.
-
#request ⇒ Object
Returns the value of attribute request.
-
#solr_document ⇒ Object
Returns the value of attribute solr_document.
Instance Method Summary collapse
- #date_modified ⇒ Object
- #date_uploaded ⇒ Object
-
#define_dynamic_methods ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength.
- #display_feature_link? ⇒ Boolean
- #display_unfeature_link? ⇒ Boolean
-
#download_url ⇒ String
A download URL, if work has representative media, or a blank string.
-
#editor? ⇒ Boolean
deprecated
Deprecated.
use
::Ability.can?(:edit, presenter). Hyrax views calling presenter #editor methods will continue to call them until Hyrax 4.0.0. The deprecation time horizon for the presenter methods themselves is 5.0.0. - #export_as_jsonld ⇒ Object
- #export_as_nt ⇒ Object
- #export_as_ttl ⇒ Object
-
#grouped_presenters(filtered_by: nil, except: nil) ⇒ Array
Presenters grouped by model name, used to show the parents of this object.
-
#iiif_viewer ⇒ Symbol
The name of the IIIF viewer partial to render.
-
#iiif_viewer? ⇒ Boolean
(also: #universal_viewer?)
Render a IIIF viewer.
-
#initialize(solr_document, current_ability, request = nil) ⇒ WorkShowPresenter
constructor
A new instance of WorkShowPresenter.
- #inspect_work ⇒ Object
- #link_name ⇒ Object
-
#list_of_item_ids_to_display ⇒ Array
List to display with Kaminari pagination.
-
#manifest_metadata ⇒ Array
IIIF metadata for inclusion in the manifest Called by the
iiif_manifestgem to add metadata. - #manifest_url ⇒ Object
- #member_count ⇒ Integer
-
#member_of_collection_presenters ⇒ Array<CollectionPresenter>
Get presenters for the collections this work is a member of via the member_of_collections association.
- #model ⇒ Object
- #page_title ⇒ Object
- #presenter_types ⇒ Object
-
#representative_presenter ⇒ Object
FileSetPresenter presenter for the representative FileSets.
- #schema_version ⇒ Object
-
#sequence_rendering ⇒ Array
IIIF rendering linking property for inclusion in the manifest Called by the
iiif_manifestgem to add a 'rendering' (eg. a link a download for the resource). -
#show_deposit_for?(collections:) ⇒ Boolean
Given a set of collections, which the caller asserts the current ability can deposit to, decide whether to display actions to add this work to a collection.
- #stats_path ⇒ Object
-
#total_pages ⇒ Integer
Total number of pages of viewable items.
- #tweeter ⇒ Object
- #valid_child_concerns ⇒ Array<Class>
- #valkyrie_presenter? ⇒ Boolean
- #work_featurable? ⇒ Boolean
- #workflow ⇒ Object
Methods included from PresentsAttributes
#attribute_to_html, #display_microdata?, #microdata_type_to_html, #permission_badge, #permission_badge_class
Methods included from ModelProxy
Constructor Details
#initialize(solr_document, current_ability, request = nil) ⇒ WorkShowPresenter
Returns a new instance of WorkShowPresenter.
24 25 26 27 28 29 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 24 def initialize(solr_document, current_ability, request = nil) @solr_document = Hyrax::SolrDocument::OrderedMembers.decorate(solr_document) @current_ability = current_ability @request = request define_dynamic_methods if @solr_document.flexible? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hyrax::MissingMethodBehavior
Instance Attribute Details
#current_ability ⇒ Object
Returns the value of attribute current_ability.
12 13 14 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 12 def current_ability @current_ability end |
#member_presenter_factory=(value) ⇒ Object
Sets the attribute member_presenter_factory
11 12 13 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 11 def member_presenter_factory=(value) @member_presenter_factory = value end |
#request ⇒ Object
Returns the value of attribute request.
12 13 14 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 12 def request @request end |
#solr_document ⇒ Object
Returns the value of attribute solr_document.
12 13 14 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 12 def solr_document @solr_document end |
Instance Method Details
#date_modified ⇒ Object
138 139 140 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 138 def date_modified solr_document.date_modified.try(:to_formatted_s, :standard) end |
#date_uploaded ⇒ Object
142 143 144 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 142 def date_uploaded solr_document.date_uploaded.try(:to_formatted_s, :standard) end |
#define_dynamic_methods ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 31 def define_dynamic_methods # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength Hyrax::FlexibleSchema.default_properties.each do |prop| method_name = prop.to_s property_details = Hyrax::FlexibleSchema.current_version["properties"][method_name] next unless property_details index_keys = property_details["indexing"] next unless index_keys multi_value = property_details['multiple'] || (property_details['data_type'] == 'array') next if self.class.method_defined?(method_name) && solr_document.respond_to?(method_name) # Define the method on the SolrDocument class Hyrax::SolrDocument::OrderedMembers.send(:define_method, method_name) do |*_args| index_keys.each do |index_key| value = self[index_key] return (multi_value ? Array.wrap(value) : value) if value.present? end multi_value ? [] : "" end # Define the method on the Presenter class self.class.send(:define_method, method_name) do |*args| @solr_document.send(method_name, *args) end end end |
#display_feature_link? ⇒ Boolean
193 194 195 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 193 def display_feature_link? work_featurable? && FeaturedWork.can_create_another? && !featured? end |
#display_unfeature_link? ⇒ Boolean
197 198 199 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 197 def display_unfeature_link? work_featurable? && featured? end |
#download_url ⇒ String
Returns a download URL, if work has representative media, or a blank string.
80 81 82 83 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 80 def download_url return '' if representative_presenter.nil? Hyrax::Engine.routes.url_helpers.download_url(representative_presenter, host: request.host) end |
#editor? ⇒ Boolean
use ::Ability.can?(:edit, presenter). Hyrax views calling
presenter #editor methods will continue to call them until Hyrax
4.0.0. The deprecation time horizon for the presenter methods themselves
is 5.0.0.
167 168 169 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 167 def editor? current_ability.can?(:edit, self) end |
#export_as_jsonld ⇒ Object
154 155 156 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 154 def export_as_jsonld graph.dump(:jsonld, standard_prefixes: true) end |
#export_as_nt ⇒ Object
150 151 152 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 150 def export_as_nt graph.dump(:ntriples) end |
#export_as_ttl ⇒ Object
158 159 160 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 158 def export_as_ttl graph.dump(:ttl) end |
#grouped_presenters(filtered_by: nil, except: nil) ⇒ Array
Returns presenters grouped by model name, used to show the parents of this object.
180 181 182 183 184 185 186 187 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 180 def grouped_presenters(filtered_by: nil, except: nil) # TODO: we probably need to retain collection_presenters (as parent_presenters) # and join this with member_of_collection_presenters grouped = member_of_collection_presenters.group_by(&:model_name).transform_keys(&:human) grouped.select! { |obj| obj.casecmp(filtered_by).zero? } unless filtered_by.nil? grouped.reject! { |obj| except.map(&:downcase).include? obj.downcase } unless except.nil? grouped end |
#iiif_viewer ⇒ Symbol
Returns the name of the IIIF viewer partial to render.
108 109 110 111 112 113 114 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 108 def iiif_viewer if representative_presenter.present? && av_viewable? Hyrax.config.iiif_av_viewer else :universal_viewer end end |
#iiif_viewer? ⇒ Boolean Also known as: universal_viewer?
Returns render a IIIF viewer.
86 87 88 89 90 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 86 def iiif_viewer? representative_id.present? && representative_presenter.present? && (av_viewable? || image_viewable? || pdf_viewable?) end |
#inspect_work ⇒ Object
75 76 77 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 75 def inspect_work @inspect_workflow ||= InspectWorkPresenter.new(solr_document, current_ability) end |
#link_name ⇒ Object
146 147 148 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 146 def link_name current_ability.can?(:read, id) ? to_s : 'Private' end |
#list_of_item_ids_to_display ⇒ Array
Returns list to display with Kaminari pagination.
212 213 214 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 212 def list_of_item_ids_to_display paginated_item_list(page_array: ) end |
#manifest_metadata ⇒ Array
IIIF metadata for inclusion in the manifest
Called by the iiif_manifest gem to add metadata
239 240 241 242 243 244 245 246 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 239 def Hyrax.config..each_with_object([]) do |field, | << { 'label' => I18n.t("simple_form.labels.defaults.#{field}"), 'value' => Array.wrap(send(field).map { |f| Loofah.fragment(f.to_s).scrub!(:whitewash).to_s }) } end end |
#manifest_url ⇒ Object
221 222 223 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 221 def manifest_url manifest_helper.polymorphic_url([:manifest, self]) end |
#member_count ⇒ Integer
250 251 252 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 250 def member_count @member_count ||= member_presenters.count end |
#member_of_collection_presenters ⇒ Array<CollectionPresenter>
Get presenters for the collections this work is a member of via the member_of_collections association.
132 133 134 135 136 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 132 def member_of_collection_presenters PresenterFactory.build_for(ids: , presenter_class: collection_presenter_class, presenter_args: presenter_factory_arguments) end |
#model ⇒ Object
205 206 207 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 205 def model solr_document.to_model end |
#page_title ⇒ Object
67 68 69 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 67 def page_title "#{human_readable_type} | #{title.first} | ID: #{id} | #{I18n.t('hyrax.product_name')}" end |
#presenter_types ⇒ Object
175 176 177 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 175 def presenter_types Hyrax.config.registered_curation_concern_types.map(&:underscore) + ["collection"] end |
#representative_presenter ⇒ Object
Returns FileSetPresenter presenter for the representative FileSets.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 117 def representative_presenter return nil if representative_id.blank? @representative_presenter ||= begin result = member_presenters([representative_id]).first return nil if result.try(:id) == id result.try(:representative_presenter) || result rescue Hyrax::ObjectNotFoundError Hyrax.logger.warn "Unable to find representative_id #{representative_id} for work #{id}" return nil end end |
#schema_version ⇒ Object
63 64 65 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 63 def schema_version solr_document[:schema_version_ssi] end |
#sequence_rendering ⇒ Array
IIIF rendering linking property for inclusion in the manifest
Called by the iiif_manifest gem to add a 'rendering' (eg. a link a download for the resource)
229 230 231 232 233 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 229 def sequence_rendering solr_document.rendering_ids.each_with_object([]) do |file_set_id, renderings| renderings << manifest_helper.build_rendering(file_set_id) end.flatten end |
#show_deposit_for?(collections:) ⇒ Boolean
Given a set of collections, which the caller asserts the current ability can deposit to, decide whether to display actions to add this work to a collection.
By default, this returns true if any collections are passed in OR the
current ability can create a collection.
267 268 269 270 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 267 def show_deposit_for?(collections:) collections.present? || current_ability.can?(:create_any, Hyrax.config.collection_class) end |
#stats_path ⇒ Object
201 202 203 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 201 def stats_path Hyrax::Engine.routes.url_helpers.stats_work_path(self, locale: I18n.locale) end |
#total_pages ⇒ Integer
Returns total number of pages of viewable items.
217 218 219 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 217 def total_pages (total_items.to_f / rows_from_params.to_f).ceil end |
#tweeter ⇒ Object
171 172 173 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 171 def tweeter TwitterPresenter.twitter_handle_for(user_key: depositor) end |
#valid_child_concerns ⇒ Array<Class>
274 275 276 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 274 def valid_child_concerns Hyrax::ChildTypes.for(parent: solr_document.hydra_model).to_a end |
#valkyrie_presenter? ⇒ Boolean
279 280 281 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 279 def valkyrie_presenter? solr_document.hydra_model < Valkyrie::Resource end |
#work_featurable? ⇒ Boolean
189 190 191 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 189 def work_featurable? user_can_feature_works? && solr_document.public? end |
#workflow ⇒ Object
71 72 73 |
# File 'app/presenters/hyrax/work_show_presenter.rb', line 71 def workflow @workflow ||= WorkflowPresenter.new(solr_document, current_ability) end |