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.



112
113
114
115
116
117
118
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 112

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

#display_user_name(recent_document) ⇒ Object



47
48
49
50
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 47

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

#has_collection_search_parameters?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 43

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


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

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.



26
27
28
29
30
31
32
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 26

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


34
35
36
37
38
39
40
41
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 34

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


56
57
58
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 56

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.



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

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


70
71
72
73
74
75
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 70

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


83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 83

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


104
105
106
107
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 104

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



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

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



52
53
54
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 52

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

#render_visibility_label(document) ⇒ Object



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

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


130
131
132
133
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 130

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.



122
123
124
125
126
127
128
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 122

def search_form_action
  if on_the_dashboard?
    search_action_for_dashboard
  else  
    catalog_index_path
  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


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/sufia/sufia_helper_behavior.rb', line 7

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