Module: HydraHelper

Included in:
ApplicationHelper
Defined in:
vendor/plugins/hydra_repository/app/models/hydra_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) async_load_tag(url, tag)



13
14
15
16
17
18
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 13

def async_load_tag( url, tag )
  javascript_tag do 
    "window._token='#{form_authenticity_token}'" 
    "async_load('#{url}', '\##{tag}');"
  end
end

- (Object) document_fedora_show_html_title



78
79
80
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 78

def document_fedora_show_html_title
  @document.datastreams["descMetadata"].title_values.first
end


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 37

def edit_and_browse_links
  result = ""
  if params[:action] == "edit"
    result << "<a href=\"#{catalog_path(@document[:id], :viewing_context=>"browse")}\" class=\"browse toggle\">Browse</a>"
    result << "<span class=\"edit toggle active\">Edit</span>"
  else
    result << "<span class=\"browse toggle active\">Browse</span>"
    result << "<a href=\"#{edit_catalog_path(@document[:id])}\" class=\"edit toggle\">Edit</a>"
  end
  # result << link_to "Browse", "#", :class=>"browse"
  # result << link_to "Edit", edit_document_path(@document[:id]), :class=>"edit"
  return result
end

- (Object) facet_value_hits(solr_result, solr_fname, facet_value, default_response = "1")

Returns the hits for facet_value within facet solr_fname within the solr_result.



83
84
85
86
87
88
89
90
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 83

def facet_value_hits(solr_result, solr_fname, facet_value, default_response="1")
  item = solr_result.facets.detect {|f| f.name == solr_fname}.items.detect {|i| i.value == facet_value}
  if item
    return item.hits
  else
    return default_response
  end
end

- (Object) get_html_data_with_label(doc, label, field_string, opts = {})



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 92

def get_html_data_with_label(doc, label, field_string, opts={})
  if opts[:default] && !doc[field_string]
    doc[field_string] = opts[:default]
  end

  if doc[field_string]
    field = doc[field_string]
    text = "<dt>#{label}</dt><dd>"
    if field.is_a?(Array)
        field.each do |l|
          text += "#{CGI::unescapeHTML(l)}"
          if l != h(field.last)
            text += "<br/>"
          end
        end
    else
      text += CGI::unescapeHTML(field)
    end
    #Does the field have a vernacular equivalent? 
    if doc["vern_#{field_string}"]
      vern_field = doc["vern_#{field_string}"]
      text += "<br/>"
      if vern_field.is_a?(Array)
        vern_field.each do |l|
          text += "#{CGI::unescapeHTML(l)}"
          if l != h(vern_field.last)
            text += "<br/>"
          end
        end
      else
        text += CGI::unescapeHTML(vern_field)
      end
    end
    text += "</dd>"
    text
   end
end

- (Object) get_textile_data_with_label(doc, label, field_string, opts = {})



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 130

def get_textile_data_with_label(doc, label, field_string, opts={})
  if opts[:default] && !doc[field_string]
    doc[field_string] = opts[:default]
  end

  if doc[field_string]
    field = doc[field_string]
    text = "<dt>#{label}</dt><dd>"
    if field.is_a?(Array)
        field.each do |l|
          text += "#{RedCloth.new(l).to_html}"
          if l != h(field.last)
            text += "<br/>"
          end
        end
    else
      text += RedCloth.new(field).to_html
    end
    text += "</dd>"
    text
   end
end

- (Object) grouped_result_count(response, facet_name = nil, facet_value = nil)



51
52
53
54
55
56
57
58
59
60
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 51

def grouped_result_count(response, facet_name=nil, facet_value=nil)
  if facet_name && facet_value
    facet = response.facets.detect {|f| f.name == facet_name}
    facet_item = facet.items.detect {|i| i.value == facet_value} if facet
    count = facet_item ? facet_item.hits : 0
  else
    count = response.docs.total
  end
  pluralize(count, 'document')
end

- (Object) grouping_facet



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 62

def grouping_facet
  fields = Hash[sort_fields]
  case h(params[:sort])
  when fields['date -']
    'year_facet'
  when fields['date +']
    'year_facet'
  when fields['document type']
    'medium_t'
  when fields['location']
    'series_facet'
  else
    nil
  end
end

- (Object) javascript_includes

collection of javascript includes to be rendered in the



9
10
11
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 9

def javascript_includes
  @javascript_includes ||= []
end


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 20

def link_to_multifacet( name, args={} )
  facet_params = {}
  options = {}
  args.each_pair do |k,v|
    if k == :options
      options = v
    else
      facet_params[:f] ||= {}
      facet_params[:f][k] ||= []
      v = v.instance_of?(Array) ? v.first : v
      facet_params[:f][k].push(v)
    end
  end

  link_to(name, catalog_index_path(facet_params), options)
end

collection of stylesheet links to be rendered in the



4
5
6
# File 'vendor/plugins/hydra_repository/app/models/hydra_helper.rb', line 4

def stylesheet_links
  @stylesheet_links ||= []
end