Module: CommonwealthVlrEngine::ApplicationHelper

Included in:
DownloadsControllerBehavior
Defined in:
app/helpers/commonwealth_vlr_engine/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#datastream_disseminator_url(pid, datastream_id) ⇒ Object

returns the direct URL to a datastream in Fedora



95
96
97
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 95

def datastream_disseminator_url pid, datastream_id
  "#{FEDORA_URL['url']}/objects/#{pid}/datastreams/#{datastream_id}/content"
end

#date_range_constraints_to_s(params) ⇒ Object

render date range constraints from Advanced Search form used by CommonwealthVlrEngine::RenderConstraintsOverride and CommonwealthVlrEngine::SearchHistoryConstraintsHelper



54
55
56
57
58
59
60
61
62
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 54

def date_range_constraints_to_s(params)
  if params[:date_start].blank?
    "before #{params[:date_end]}"
  elsif params[:date_end].blank?
    "after #{params[:date_start]}"
  else
    "#{params[:date_start]}-#{params[:date_end]}"
  end
end

#get_image_metadata(image_pid) ⇒ Object

returns a hash with width/height from IIIF info.json response



130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 130

def (image_pid)
  iiif_response = Typhoeus::Request.get(IIIF_SERVER['url'] + image_pid + '/info.json')
  if iiif_response.response_code == 200 && !iiif_response.response_body.empty?
    iiif_info = JSON.parse(iiif_response.body)
     = {height: iiif_info["height"].to_i, width: iiif_info["width"].to_i}
  else
     = {height: 0, width: 0}
  end
  
end

#iiif_image_tag(image_pid, options) ⇒ Object

create an image tag from an IIIF image server



100
101
102
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 100

def iiif_image_tag(image_pid,options)
  image_tag iiif_image_url(image_pid, options), :alt => options[:alt].presence, :class => options[:class].presence
end

#iiif_image_url(image_pid, options) ⇒ Object

return the IIIF image url



105
106
107
108
109
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 105

def iiif_image_url(image_pid, options)
  size = options[:size] ? options[:size] : 'full'
  region = options[:region] ? options[:region] : 'full'
  "#{IIIF_SERVER['url']}#{image_pid}/#{region}/#{size}/0/default.jpg"
end

#iiif_square_img_path(image_pid, size) ⇒ Object

return a square image of the supplied size (in pixels)



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 112

def iiif_square_img_path(image_pid, size)
  img_info = (image_pid)
  width = img_info[:width]
  height = img_info[:height]
  if width > height
    offset = (width - height) / 2
    iiif_image_url(image_pid,
                   {:region => "#{offset},0,#{height},#{height}", :size => "#{size},#{size}"})
  elsif height > width
    offset = (height - width) / 2
    iiif_image_url(image_pid,
                   {:region => "0,#{offset},#{width},#{width}", :size => "#{size},#{size}"})
  else
    iiif_image_url(image_pid, {:size => "#{size},#{size}"})
  end
end

#insert_google_analyticsObject



149
150
151
152
153
154
155
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 149

def insert_google_analytics
  if Rails.env.to_s == 'production'
    content_for(:head) do
      render :partial=>'/layouts/google_analytics'
    end
  end
end

#insert_opengraph_markupObject



141
142
143
144
145
146
147
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 141

def insert_opengraph_markup
  if controller_name == 'catalog' && action_name == 'show'
    content_for(:head) do
      render :partial=>'/catalog/opengraph', :locals => {:document => @document}
    end
  end
end


90
91
92
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 90

def link_to_county_facet(field_value, field)
  link_to(field_value + ' County', search_catalog_path(:f => {field => [field_value + ' (county)']}))
end


73
74
75
76
77
78
79
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 73

def link_to_facet(field_value, field, displayvalue = nil)
  if field == 'genre_basic_ssim'
    link_to(render_format(field_value), search_catalog_path(:f => {field => [field_value]}))
  else
    link_to(displayvalue.presence || field_value, search_catalog_path(:f => {field => [field_value]}))
  end
end

link to a combination of facets (series + subseries, for ex)



82
83
84
85
86
87
88
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 82

def link_to_facets(field_values, fields, displayvalue = nil)
  facets = {}
  fields.each_with_index do |field, index|
    facets[field] = [field_values[index]]
  end
  link_to(displayvalue.presence || field_values[0], search_catalog_path(:f => facets))
end

from psu scholarsphere TODO: this isn’t used anywhere in the app, get rid of it?



66
67
68
69
70
71
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 66

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

#osd_nav_images(path_to_directory) ⇒ Object

returns a hash with the location of the OpenSeadragon custom images



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 158

def osd_nav_images(path_to_directory)
  {
      zoomIn: {
          REST:   path_to_image("#{path_to_directory}/zoomin_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/zoomin_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/zoomin_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/zoomin_pressed.png")
      },
      zoomOut: {
          REST:   path_to_image("#{path_to_directory}/zoomout_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/zoomout_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/zoomout_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/zoomout_pressed.png")
      },
      home: {
          REST:   path_to_image("#{path_to_directory}/home_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/home_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/home_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/home_pressed.png")
      },
      fullpage: {
          REST:   path_to_image("#{path_to_directory}/fullpage_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/fullpage_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/fullpage_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/fullpage_pressed.png")
      },
      rotateleft: {
          REST:   path_to_image("#{path_to_directory}/rotateleft_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/rotateleft_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/rotateleft_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/rotateleft_pressed.png")
      },
      rotateright: {
          REST:   path_to_image("#{path_to_directory}/rotateright_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/rotateright_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/rotateright_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/rotateright_pressed.png")
      },
      previous: {
          REST:   path_to_image("#{path_to_directory}/previous_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/previous_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/previous_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/previous_pressed.png")
      },
      next: {
          REST:   path_to_image("#{path_to_directory}/next_rest.png"),
          GROUP:  path_to_image("#{path_to_directory}/next_grouphover.png"),
          HOVER:  path_to_image("#{path_to_directory}/next_hover.png"),
          DOWN:   path_to_image("#{path_to_directory}/next_pressed.png")
      }
  }.to_json
end

#render_format(value) ⇒ Object

show the display-friendly value for the Format facet



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 5

def render_format(value)
  case value
    when 'Albums'
      'Albums/Scrapbooks'
    when 'Drawings'
      'Drawings/Illustrations'
    when 'Maps'
      'Maps/Atlases'
    when 'Motion pictures'
      'Film/Video'
    when 'Music'
      'Music (recordings)'
    when 'Objects'
      'Objects/Artifacts'
    when 'Musical notation'
      'Sheet music'
    when 'Sound recordings'
      'Audio recordings (nonmusical)'
    when 'Cards'
      'Postcards/Cards'
    when 'Correspondence'
      'Letters/Correspondence'
    else
      value
  end
end

#render_format_index(options = {}) ⇒ Object



32
33
34
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 32

def render_format_index(options={})
  options[:value].map { |v| render_format(v) }.join('; ')
end

#render_mobile_icon_tagsObject

adds apple-touch-icon tags to <head>



212
213
214
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 212

def render_mobile_icon_tags
  render partial: 'shared/mobile_icon_tags'
end

#render_object_icon_path(format) ⇒ Object

return the path to the icon for objects with no thumbnail



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/commonwealth_vlr_engine/application_helper.rb', line 37

def render_object_icon_path(format)
  case format
    when 'still image'
      icon = 'image'
    when 'sound recording', 'sound recording-nonmusical', 'sound recording-musical'
      icon = 'audio'
    when 'moving image'
      icon = 'moving-image'
    else
      icon = 'text'
  end
  "commonwealth-vlr-engine/dc_#{icon}-icon.png"
end