Module: SufiaHelper

Included in:
EventJob
Defined in:
app/helpers/sufia_helper.rb

Instance Method Summary collapse

Instance Method Details

#display_user_name(recent_document) ⇒ Object



37
38
39
40
# File 'app/helpers/sufia_helper.rb', line 37

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


64
65
66
67
68
69
70
# File 'app/helpers/sufia_helper.rb', line 64

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

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



105
106
107
108
109
110
111
# File 'app/helpers/sufia_helper.rb', line 105

def link_back_to_catalog(opts={:label=>t('blacklight.back_to_search')})
  query_params = session[:search] ? session[:search].dup : {}
  query_params.delete :counter
  query_params.delete :total
  link_url = sufia.url_for(query_params)
  link_to opts[:label], link_url
end

link_back_to_dashboard(:label=>‘Back to Search’) Create a link back to the dashboard screen, keeping the user’s facet, query and paging choices intact by using session.



20
21
22
23
24
25
26
# File 'app/helpers/sufia_helper.rb', line 20

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


28
29
30
31
32
33
34
35
# File 'app/helpers/sufia_helper.rb', line 28

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


46
47
48
# File 'app/helpers/sufia_helper.rb', line 46

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


50
51
52
53
54
# File 'app/helpers/sufia_helper.rb', line 50

def link_to_facet_list(list, field_string, emptyText="No value entered", separator=", ")
  facet_field = Solrizer.solr_name(field_string, :facetable)
  return list.map{ |item| link_to_facet(item, facet_field) }.join(separator) unless list.blank?
  return emptyText
end


57
58
59
60
61
62
# File 'app/helpers/sufia_helper.rb', line 57

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


72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/sufia_helper.rb', line 72

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

#linkify_chat_id(chat_id) ⇒ Object



85
86
87
88
89
90
91
# File 'app/helpers/sufia_helper.rb', line 85

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



42
43
44
# File 'app/helpers/sufia_helper.rb', line 42

def number_of_deposits(user)
  ActiveFedora::SolrService.query("#{Solrizer.solr_name('depositor', :stored_searchable, :type => :string)}:#{user.user_key}").count
end

#render_facet_value(facet_solr_field, item, options = {}) ⇒ Object

Override to remove the label class (easier integration with bootstrap) and handles arrays



95
96
97
98
99
100
101
# File 'app/helpers/sufia_helper.rb', line 95

def render_facet_value(facet_solr_field, item, options ={})    
  if item.is_a? Array
    render_array_facet_value(facet_solr_field, item, options)
  end
  path =sufia.url_for(add_facet_params_and_redirect(facet_solr_field, item.value).merge(:only_path=>true))
  (link_to_unless(options[:suppress_link], item.value, path, :class=>"facet_select") + " " + render_facet_count(item.hits)).html_safe
end