Class: Hyrax::WorkShowPresenter

Inherits:
Object
  • Object
show all
Includes:
ModelProxy, PresentsAttributes
Defined in:
app/presenters/hyrax/work_show_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, #to_partial_path

Constructor Details

#initialize(solr_document, current_ability, request = nil) ⇒ WorkShowPresenter

Returns a new instance of WorkShowPresenter.

Parameters:

  • solr_document (SolrDocument)
  • current_ability (Ability)
  • request (ActionDispatch::Request) (defaults to: nil)

    the http request context. Used so the GraphExporter knows what URLs to draw.



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_abilityObject

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

#requestObject

Returns the value of attribute request.



5
6
7
# File 'app/presenters/hyrax/work_show_presenter.rb', line 5

def request
  @request
end

#solr_documentObject

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_modifiedObject



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_uploadedObject



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

Returns:

  • (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

Returns:

  • (Boolean)


133
134
135
# File 'app/presenters/hyrax/work_show_presenter.rb', line 133

def display_unfeature_link?
  work_featurable? && featured?
end

#download_urlString

Returns a download URL, if work has representative media, or a blank string.

Returns:

  • (String)

    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

Returns:

  • (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_jsonldObject



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_ntObject



91
92
93
# File 'app/presenters/hyrax/work_show_presenter.rb', line 91

def export_as_nt
  graph.dump(:ntriples)
end

#export_as_ttlObject



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.

Returns:

  • (Array)

    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)
  # 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 { |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_workObject



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


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_presentersArray<CollectionPresenter>

Get presenters for the collections this work is a member of via the member_of_collections association.

Returns:



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_titleObject



29
30
31
# File 'app/presenters/hyrax/work_show_presenter.rb', line 29

def page_title
  title.first
end

#presenter_typesObject



111
112
113
# File 'app/presenters/hyrax/work_show_presenter.rb', line 111

def presenter_types
  Hyrax.config.registered_curation_concern_types.map(&:underscore) + ["collection"]
end

#representative_presenterObject

Returns FileSetPresenter presenter for the representative FileSets.

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_pathObject



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

#tweeterObject



107
108
109
# File 'app/presenters/hyrax/work_show_presenter.rb', line 107

def tweeter
  TwitterPresenter.twitter_handle_for(user_key: depositor)
end

#work_featurable?Boolean

Returns:

  • (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

#workflowObject



43
44
45
# File 'app/presenters/hyrax/work_show_presenter.rb', line 43

def workflow
  @workflow ||= WorkflowPresenter.new(solr_document, current_ability)
end