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.
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 = solr_document
@current_ability = current_ability
@request = request
end
|
Instance Attribute Details
#current_ability ⇒ Object
Returns the value of attribute current_ability.
5
6
7
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 5
def current_ability
@current_ability
end
|
#request ⇒ Object
Returns the value of attribute request.
5
6
7
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 5
def request
@request
end
|
#solr_document ⇒ Object
Returns the value of attribute solr_document.
5
6
7
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 5
def solr_document
@solr_document
end
|
Instance Method Details
#date_modified ⇒ Object
79
80
81
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 79
def date_modified
solr_document.date_modified.try(:to_formatted_s, :standard)
end
|
#date_uploaded ⇒ Object
83
84
85
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 83
def date_uploaded
solr_document.date_uploaded.try(:to_formatted_s, :standard)
end
|
#display_feature_link? ⇒ Boolean
129
130
131
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 129
def display_feature_link?
work_featurable? && FeaturedWork.can_create_another? && !featured?
end
|
#display_unfeature_link? ⇒ Boolean
133
134
135
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 133
def display_unfeature_link?
work_featurable? && featured?
end
|
#download_url ⇒ String
Returns a download URL, if work has representative media, or a blank string.
52
53
54
55
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 52
def download_url
return '' if representative_presenter.nil?
Hyrax::Engine.routes.url_helpers.download_url(representative_presenter, host: request.host)
end
|
#editor? ⇒ Boolean
103
104
105
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 103
def editor?
current_ability.can?(:edit, solr_document)
end
|
#export_as_jsonld ⇒ Object
95
96
97
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 95
def export_as_jsonld
graph.dump(:jsonld, standard_prefixes: true)
end
|
#export_as_nt ⇒ Object
91
92
93
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 91
def export_as_nt
graph.dump(:ntriples)
end
|
#export_as_ttl ⇒ Object
99
100
101
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 99
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.
116
117
118
119
120
121
122
123
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 116
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
47
48
49
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 47
def inspect_work
@inspect_workflow ||= InspectWorkPresenter.new(solr_document, current_ability)
end
|
#link_name ⇒ Object
87
88
89
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 87
def link_name
current_ability.can?(:read, id) ? to_s : 'File'
end
|
#member_of_collection_presenters ⇒ Array<CollectionPresenter>
Get presenters for the collections this work is a member of via the member_of_collections association.
73
74
75
76
77
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 73
def member_of_collection_presenters
PresenterFactory.build_for(ids: member_of_collection_ids,
presenter_class: collection_presenter_class,
presenter_args: presenter_factory_arguments)
end
|
#page_title ⇒ Object
29
30
31
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 29
def page_title
title.first
end
|
#presenter_types ⇒ Object
#representative_presenter ⇒ Object
Returns FileSetPresenter presenter for the representative FileSets.
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 58
def representative_presenter
return nil if representative_id.blank?
@representative_presenter ||=
begin
result = member_presenters([representative_id]).first
if result.respond_to?(:representative_presenter)
result.representative_presenter
else
result
end
end
end
|
#stats_path ⇒ Object
137
138
139
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 137
def stats_path
Hyrax::Engine.routes.url_helpers.stats_work_path(self)
end
|
#work_featurable? ⇒ Boolean
125
126
127
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 125
def work_featurable?
user_can_feature_works? && solr_document.public?
end
|
#workflow ⇒ Object
43
44
45
|
# File 'app/presenters/hyrax/work_show_presenter.rb', line 43
def workflow
@workflow ||= WorkflowPresenter.new(solr_document, current_ability)
end
|