Class: Hyrax::WorkShowPresenter
Instance Attribute Summary collapse
Instance Method Summary
collapse
#attribute_to_html, #display_microdata?, #microdata_type_to_html, #permission_badge, #permission_badge_class
Methods included from ModelProxy
#persisted?, #to_model
Constructor Details
#initialize(solr_document, current_ability, request = nil) ⇒ WorkShowPresenter
Returns a new instance of WorkShowPresenter.
23
24
25
26
27
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 23
def initialize(solr_document, current_ability, request = nil)
@solr_document = Hyrax::SolrDocument::OrderedMembers.decorate(solr_document)
@current_ability = current_ability
@request = request
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
249
250
251
252
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 249
def method_missing(method_name, *args, &block)
return solr_document.public_send(method_name, *args, &block) if solr_document.respond_to?(method_name)
super
end
|
Instance Attribute Details
#current_ability ⇒ Object
Returns the value of attribute current_ability.
11
12
13
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 11
def current_ability
@current_ability
end
|
#member_presenter_factory=(value) ⇒ Object
Sets the attribute member_presenter_factory
10
11
12
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 10
def member_presenter_factory=(value)
@member_presenter_factory = value
end
|
#request ⇒ Object
Returns the value of attribute request.
11
12
13
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 11
def request
@request
end
|
#solr_document ⇒ Object
Returns the value of attribute solr_document.
11
12
13
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 11
def solr_document
@solr_document
end
|
Instance Method Details
#date_modified ⇒ Object
102
103
104
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 102
def date_modified
solr_document.date_modified.try(:to_formatted_s, :standard)
end
|
#date_uploaded ⇒ Object
106
107
108
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 106
def date_uploaded
solr_document.date_uploaded.try(:to_formatted_s, :standard)
end
|
#display_feature_link? ⇒ Boolean
157
158
159
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 157
def display_feature_link?
work_featurable? && FeaturedWork.can_create_another? && !featured?
end
|
#display_unfeature_link? ⇒ Boolean
161
162
163
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 161
def display_unfeature_link?
work_featurable? && featured?
end
|
#download_url ⇒ String
Returns a download URL, if work has representative media, or a blank string.
46
47
48
49
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 46
def download_url
return '' if representative_presenter.nil?
Hyrax::Engine.routes.url_helpers.download_url(representative_presenter, host: request.host)
end
|
#editor? ⇒ Boolean
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.
131
132
133
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 131
def editor?
current_ability.can?(:edit, self)
end
|
#export_as_jsonld ⇒ Object
118
119
120
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 118
def export_as_jsonld
graph.dump(:jsonld, standard_prefixes: true)
end
|
#export_as_nt ⇒ Object
114
115
116
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 114
def export_as_nt
graph.dump(:ntriples)
end
|
#export_as_ttl ⇒ Object
122
123
124
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 122
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.
144
145
146
147
148
149
150
151
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 144
def grouped_presenters(filtered_by: nil, except: nil)
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.
76
77
78
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 76
def iiif_viewer
:universal_viewer
end
|
#iiif_viewer? ⇒ Boolean
Also known as:
universal_viewer?
Returns render a IIIF viewer.
52
53
54
55
56
57
58
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 52
def iiif_viewer?
Hyrax.config.iiif_image_server? &&
representative_id.present? &&
representative_presenter.present? &&
representative_presenter.image? &&
members_include_viewable_image?
end
|
#inspect_work ⇒ Object
41
42
43
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 41
def inspect_work
@inspect_workflow ||= InspectWorkPresenter.new(solr_document, current_ability)
end
|
#link_name ⇒ Object
110
111
112
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 110
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.
176
177
178
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 176
def list_of_item_ids_to_display
paginated_item_list(page_array: authorized_item_ids)
end
|
IIIF metadata for inclusion in the manifest
Called by the `iiif_manifest` gem to add metadata
203
204
205
206
207
208
209
210
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 203
def manifest_metadata
Hyrax.config.iiif_metadata_fields.each_with_object([]) do |field, metadata|
metadata << {
'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
185
186
187
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 185
def manifest_url
manifest_helper.polymorphic_url([:manifest, self])
end
|
#member_count ⇒ Integer
214
215
216
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 214
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.
96
97
98
99
100
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 96
def member_of_collection_presenters
PresenterFactory.build_for(ids: member_of_authorized_parent_collections,
presenter_class: collection_presenter_class,
presenter_args: presenter_factory_arguments)
end
|
#model ⇒ Object
169
170
171
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 169
def model
solr_document.to_model
end
|
#page_title ⇒ Object
33
34
35
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 33
def page_title
"#{human_readable_type} | #{title.first} | ID: #{id} | #{I18n.t('hyrax.product_name')}"
end
|
#presenter_types ⇒ Object
#representative_presenter ⇒ Object
Returns FileSetPresenter presenter for the representative FileSets.
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 81
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
|
#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)
193
194
195
196
197
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 193
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.
231
232
233
234
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 231
def show_deposit_for?(collections:)
collections.present? ||
current_ability.can?(:create_any, Hyrax.config.collection_class)
end
|
#stats_path ⇒ Object
165
166
167
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 165
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.
181
182
183
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 181
def total_pages
(total_items.to_f / rows_from_params.to_f).ceil
end
|
#valid_child_concerns ⇒ Array<Class>
238
239
240
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 238
def valid_child_concerns
Hyrax::ChildTypes.for(parent: solr_document.hydra_model).to_a
end
|
#valkyrie_presenter? ⇒ Boolean
243
244
245
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 243
def valkyrie_presenter?
solr_document.hydra_model < Valkyrie::Resource
end
|
#work_featurable? ⇒ Boolean
153
154
155
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 153
def work_featurable?
user_can_feature_works? && solr_document.public?
end
|
#workflow ⇒ Object
37
38
39
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 37
def workflow
@workflow ||= WorkflowPresenter.new(solr_document, current_ability)
end
|