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, #to_partial_path
Constructor Details
#initialize(solr_document, current_ability, request = nil) ⇒ WorkShowPresenter
Returns a new instance of WorkShowPresenter.
24
25
26
27
28
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 24
def initialize(solr_document, current_ability, request = nil)
@solr_document = solr_document
@current_ability = current_ability
@request = request
end
|
Instance Attribute Details
#current_ability ⇒ Object
Returns the value of attribute current_ability.
6
7
8
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 6
def current_ability
@current_ability
end
|
#request ⇒ Object
Returns the value of attribute request.
6
7
8
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 6
def request
@request
end
|
#solr_document ⇒ Object
Returns the value of attribute solr_document.
6
7
8
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 6
def solr_document
@solr_document
end
|
Instance Method Details
#date_modified ⇒ Object
90
91
92
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 90
def date_modified
solr_document.date_modified.try(:to_formatted_s, :standard)
end
|
#date_uploaded ⇒ Object
94
95
96
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 94
def date_uploaded
solr_document.date_uploaded.try(:to_formatted_s, :standard)
end
|
#display_feature_link? ⇒ Boolean
140
141
142
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 140
def display_feature_link?
work_featurable? && FeaturedWork.can_create_another? && !featured?
end
|
#display_unfeature_link? ⇒ Boolean
144
145
146
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 144
def display_unfeature_link?
work_featurable? && featured?
end
|
#download_url ⇒ String
Returns a download URL, if work has representative media, or a blank string.
53
54
55
56
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 53
def download_url
return '' if representative_presenter.nil?
Hyrax::Engine.routes.url_helpers.download_url(representative_presenter, host: request.host)
end
|
#editor? ⇒ Boolean
114
115
116
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 114
def editor?
current_ability.can?(:edit, solr_document)
end
|
#export_as_jsonld ⇒ Object
106
107
108
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 106
def export_as_jsonld
graph.dump(:jsonld, standard_prefixes: true)
end
|
#export_as_nt ⇒ Object
102
103
104
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 102
def export_as_nt
graph.dump(:ntriples)
end
|
#export_as_ttl ⇒ Object
110
111
112
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 110
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.
127
128
129
130
131
132
133
134
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 127
def grouped_presenters(filtered_by: nil, except: nil)
grouped = member_of_collection_presenters.group_by(&:model_name).transform_keys { |key| key.to_s.underscore }
grouped.select! { |obj| obj.downcase == filtered_by } unless filtered_by.nil?
grouped.except!(*except) unless except.nil?
grouped
end
|
#inspect_work ⇒ Object
48
49
50
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 48
def inspect_work
@inspect_workflow ||= InspectWorkPresenter.new(solr_document, current_ability)
end
|
#link_name ⇒ Object
98
99
100
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 98
def link_name
current_ability.can?(:read, id) ? to_s : 'File'
end
|
#list_of_item_ids_to_display ⇒ Array
Returns list to display with Kaminari pagination.
159
160
161
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 159
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
196
197
198
199
200
201
202
203
204
205
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 196
def manifest_metadata
metadata = []
Hyrax.config.iiif_metadata_fields.each do |field|
metadata << {
'label' => I18n.t("simple_form.labels.defaults.#{field}"),
'value' => Array.wrap(send(field))
}
end
metadata
end
|
#manifest_url ⇒ Object
174
175
176
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 174
def manifest_url
manifest_helper.polymorphic_url([:manifest, self])
end
|
#member_of_collection_presenters ⇒ Array<CollectionPresenter>
Get presenters for the collections this work is a member of via the member_of_collections association.
84
85
86
87
88
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 84
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
|
#member_presenters_for(an_array_of_ids) ⇒ Array<presenter_class>
Returns presenters for the array of ids (not filtered by class).
165
166
167
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 165
def member_presenters_for(an_array_of_ids)
member_presenters(an_array_of_ids)
end
|
#model ⇒ Object
152
153
154
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 152
def model
solr_document.to_model
end
|
#page_title ⇒ Object
30
31
32
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 30
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.
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 68
def representative_presenter
return nil if representative_id.blank?
@representative_presenter ||=
begin
result = member_presenters_for([representative_id]).first
return nil if result.try(:id) == id
if result.respond_to?(:representative_presenter)
result.representative_presenter
else
result
end
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)
182
183
184
185
186
187
188
189
190
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 182
def sequence_rendering
renderings = []
if solr_document.rendering_ids.present?
solr_document.rendering_ids.each do |file_set_id|
renderings << manifest_helper.build_rendering(file_set_id)
end
end
renderings.flatten
end
|
#stats_path ⇒ Object
148
149
150
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 148
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.
170
171
172
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 170
def total_pages
(total_items.to_f / rows_from_params.to_f).ceil
end
|
#universal_viewer? ⇒ Boolean
Returns render the UniversalViewer.
59
60
61
62
63
64
65
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 59
def universal_viewer?
representative_id.present? &&
representative_presenter.present? &&
representative_presenter.image? &&
Hyrax.config.iiif_image_server? &&
members_include_viewable_image?
end
|
#work_featurable? ⇒ Boolean
136
137
138
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 136
def work_featurable?
user_can_feature_works? && solr_document.public?
end
|
#workflow ⇒ Object
44
45
46
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 44
def workflow
@workflow ||= WorkflowPresenter.new(solr_document, current_ability)
end
|