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



22
23
24
25
26
# File 'app/presenters/hyrax/work_show_presenter.rb', line 22

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

#display_feature_link?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'app/presenters/hyrax/work_show_presenter.rb', line 119

def display_feature_link?
  work_featurable? && FeaturedWork.can_create_another? && !featured?
end

#display_unfeature_link?Boolean

Returns:

  • (Boolean)


123
124
125
# File 'app/presenters/hyrax/work_show_presenter.rb', line 123

def display_unfeature_link?
  work_featurable? && featured?
end

#editor?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'app/presenters/hyrax/work_show_presenter.rb', line 88

def editor?
  current_ability.can?(:edit, solr_document)
end

#export_as_jsonldObject



80
81
82
# File 'app/presenters/hyrax/work_show_presenter.rb', line 80

def export_as_jsonld
  graph.dump(:jsonld, standard_prefixes: true)
end

#export_as_ntObject



76
77
78
# File 'app/presenters/hyrax/work_show_presenter.rb', line 76

def export_as_nt
  graph.dump(:ntriples)
end

#export_as_ttlObject



84
85
86
# File 'app/presenters/hyrax/work_show_presenter.rb', line 84

def export_as_ttl
  graph.dump(:ttl)
end

#grouped_presenters(filtered_by: nil, except: nil) ⇒ Object

Returns presenters grouped by model name, used to show the parents of this object.

Returns:

  • presenters grouped by model name, used to show the parents of this object



106
107
108
109
110
111
112
113
# File 'app/presenters/hyrax/work_show_presenter.rb', line 106

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



46
47
48
# File 'app/presenters/hyrax/work_show_presenter.rb', line 46

def inspect_work
  @inspect_workflow ||= InspectWorkPresenter.new(solr_document, current_ability)
end


72
73
74
# File 'app/presenters/hyrax/work_show_presenter.rb', line 72

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:



66
67
68
69
70
# File 'app/presenters/hyrax/work_show_presenter.rb', line 66

def member_of_collection_presenters
  PresenterFactory.build_presenters(member_of_collection_ids,
                                    collection_presenter_class,
                                    *presenter_factory_arguments)
end

#page_titleObject



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

def page_title
  title.first
end

#presenter_typesObject



101
102
103
# File 'app/presenters/hyrax/work_show_presenter.rb', line 101

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



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/presenters/hyrax/work_show_presenter.rb', line 51

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



127
128
129
# File 'app/presenters/hyrax/work_show_presenter.rb', line 127

def stats_path
  Hyrax::Engine.routes.url_helpers.stats_work_path(self)
end

#tweeterObject



92
93
94
95
96
97
98
99
# File 'app/presenters/hyrax/work_show_presenter.rb', line 92

def tweeter
  user = ::User.find_by_user_key(depositor)
  if user.try(:twitter_handle).present?
    "@#{user.twitter_handle}"
  else
    I18n.translate('hyrax.product_twitter_handle')
  end
end

#work_featurable?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'app/presenters/hyrax/work_show_presenter.rb', line 115

def work_featurable?
  user_can_feature_works? && solr_document.public?
end

#workflowObject



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

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