Module: Sufia::SufiaHelperBehavior

Included in:
SufiaHelper
Defined in:
app/helpers/sufia/sufia_helper_behavior.rb

Instance Method Summary collapse

Instance Method Details

#current_search_parametersObject

Only display the current search parameters if the user is not in the dashboard. If they are in the dashboard, then the search defaults to the user’s files and not all of Sufia.



134
135
136
137
138
139
140
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 134

def current_search_parameters
  if on_the_dashboard?
    return nil
  else
    return params[:q]
  end
end

#display_user_name(recent_document) ⇒ Object



69
70
71
72
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 69

def display_user_name(recent_document)
  return "no display name" unless recent_document.depositor
  ::User.find_by_user_key(recent_document.depositor).name rescue recent_document.depositor
end

#error_messages_for(object) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 3

def error_messages_for(object)
  if object.try(:errors) and object.errors.full_messages.any?
    (:div, class: 'alert alert-block alert-error validation-errors') do
      (:h4, I18n.t('sufia.errors.header', model: object.class.model_name.human.downcase), class: 'alert-heading') +
        (:ul) do
        object.errors.full_messages.map do |message|
          (:li, message)
        end.join('').html_safe
      end
    end
  else
    '' # return empty string
  end
end

#has_collection_search_parameters?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 65

def has_collection_search_parameters?
  !params[:cq].blank?
end


99
100
101
102
103
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 99

def iconify_auto_link(text, showLink = true)
  auto_link(text) do |value|
    "<i class='glyphicon glyphicon-new-window'></i>&nbsp;#{value if showLink}<br />"
  end
end

Create a link back to the dashboard screen, keeping the user’s facet, query and paging choices intact by using session.



48
49
50
51
52
53
54
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 48

def link_back_to_dashboard(opts = { label: 'Back to Search' })
  query_params = session[:search] ? session[:search].dup : {}
  query_params.delete :counter
  query_params.delete :total
  link_url = dashboard_index_path + "?" + query_params.to_query
  link_to opts[:label], link_url
end


56
57
58
59
60
61
62
63
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 56

def link_to_dashboard_query(query)
  p = params.dup
  p.delete :page
  p.delete :action
  p[:q] = query
  link_url = dashboard_index_path(p)
  link_to(query, link_url)
end


78
79
80
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 78

def link_to_facet(field, field_string)
  link_to(field, add_facet_params(field_string, field).merge!(controller: "catalog", action: "index"))
end

Parameters:

  • values (Array)

    The values to display

  • solr_field (String)

    The name of the solr field to link to without its suffix (:facetable)

  • empty_message (String) (defaults to: "No value entered")

    (‘No value entered’) The message to display if no values are passed in.

  • separator (String) (defaults to: ", ")

    (‘, ’) The value to join with.



86
87
88
89
90
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 86

def link_to_facet_list(values, solr_field, empty_message="No value entered", separator=", ")
  return empty_message if values.blank?
  facet_field = Solrizer.solr_name(solr_field, :facetable)
  safe_join(values.map{ |item| link_to_facet(item, facet_field) }, separator)
end


92
93
94
95
96
97
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 92

def link_to_field(fieldname, fieldvalue, displayvalue = nil)
  p = { search_field: 'advanced', fieldname => '"'+fieldvalue+'"' }
  link_url = catalog_index_path(p)
  display = displayvalue.blank? ? fieldvalue : displayvalue
  link_to(display, link_url)
end


105
106
107
108
109
110
111
112
113
114
115
116
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 105

def link_to_profile()
  user = ::User.find_by_user_key()
  return  if user.nil?

  text = if user.respond_to? :name
    user.name
  else
    
  end

  link_to text, Sufia::Engine.routes.url_helpers.profile_path(user)
end


126
127
128
129
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 126

def link_to_telephone(user = nil)
  @user ||= user
  link_to @user.telephone, "wtai://wp/mc;#{@user.telephone}" if @user.telephone
end

#linkify_chat_id(chat_id) ⇒ Object



118
119
120
121
122
123
124
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 118

def linkify_chat_id(chat_id)
  if chat_id.end_with? '@chat.psu.edu'
    "<a href=\"xmpp:#{chat_id}\">#{chat_id}</a>"
  else
    chat_id
  end
end

#number_of_deposits(user) ⇒ Object



74
75
76
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 74

def number_of_deposits(user)
  ActiveFedora::Base.where(Solrizer.solr_name('depositor', :stored_searchable) => user.user_key).count
end

#render_visibility_label(document) ⇒ Object



157
158
159
160
161
162
163
164
165
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 157

def render_visibility_label document
  if document.registered?
     :span, t('sufia.institution_name'), class: "label label-info", title: t('sufia.institution_name')
  elsif document.public?
     :span, t('sufia.visibility.open'), class: "label label-success", title: t('sufia.visibility.open')
  else
     :span, t('sufia.visibility.private'), class: "label label-danger", title: t('sufia.visibility.private')
  end
end


152
153
154
155
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 152

def render_visibility_link document
  link_to render_visibility_label(document), sufia.edit_generic_file_path(document.noid, {anchor: "permissions_display"}),
    id: "permission_"+document.noid, class: "visibility-link"
end

#search_form_actionObject

Depending on which page we’re landed on, we’ll need to set the appropriate action url for our search form.



144
145
146
147
148
149
150
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 144

def search_form_action
  if on_the_dashboard?
    search_action_for_dashboard
  else
    catalog_index_path
  end
end

#show_transfer_request_title(req) ⇒ Object



18
19
20
21
22
23
24
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 18

def show_transfer_request_title(req)
  if req.deleted_file?
    req.title
  else
    link_to(req.title, sufia.generic_file_path(req['pid'].split(':').last))
  end
end

#sufia_thumbnail_tag(document, options) ⇒ Object

You can configure blacklight to use this as the thumbnail example:

config.index.thumbnail_method = :sufia_thumbnail_tag


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 29

def sufia_thumbnail_tag(document, options)
  # collection
  if (document.collection?)
    (:span, "", class: "glyphicon glyphicon-th collection-icon-search")

  # file
  else
    path = if document.image? || document.pdf? || document.video? || document.office_document?
      sufia.download_path document.noid, datastream_id: 'thumbnail'
    elsif document.audio?
      "audio.png"
    else
      "default.png"
    end
    image_tag path, options
  end
end