Module: CommonwealthVlrEngine::CatalogHelper
- Includes:
- Blacklight::CatalogHelperBehavior
- Included in:
- IiifManifestController, ImageViewerController, OcrSearchController
- Defined in:
- app/helpers/commonwealth_vlr_engine/catalog_helper.rb
Instance Method Summary collapse
-
#cc_terms_code(license) ⇒ Object
returns the CC license terms code for use in URLs, etc.
-
#cc_url(license) ⇒ Object
returns a link to a CC license.
-
#collection_gallery_url(document, size) ⇒ Object
return the image url for the collection gallery view document size = pixel length of square IIIF-created image.
- #collection_icon_path ⇒ Object
- #create_download_links(document, files_hash, link_class) ⇒ Object
- #create_thumb_img_element(document, img_class = []) ⇒ Object
- #extra_body_classes ⇒ Object
- #has_downloadable_files?(files_hash) ⇒ Boolean
- #has_image_files?(files_hash) ⇒ Boolean
-
#ia_download_title(file_extension) ⇒ Object
render the file type names for Internet Archive book item download links.
-
#index_collection_link(options = {}) ⇒ Object
render collection name as a link in catalog#index list view.
-
#index_date_value(options = {}) ⇒ Object
render the date in the catalog#index list view.
-
#index_institution_link(options = {}) ⇒ Object
render institution name as a link in catalog#index list view.
-
#index_relation_base_icon(document) ⇒ Object
render the collection/institution icon if necessary.
-
#index_slideshow_img_url(document) ⇒ Object
return the URL of an image to display in the catalog#index slideshow view.
-
#index_title_length ⇒ Object
determine the ‘truncate’ length based on catalog#index view type.
- #institution_icon_path ⇒ Object
-
#link_to_az_value(letter, field, search_path, link_class = nil) ⇒ Object
link to items starting with a specific letter.
- #normalize_date(date) ⇒ Object
-
#render_cc_license(license) ⇒ Object
insert an icon and link to CC licenses.
-
#render_full_title(document) ⇒ Object
output properly formatted full title, with subtitle, parallel title, etc.
-
#render_hiergo_subject(geojson_feature, separator, separator_class = nil) ⇒ Object
render metadata for <mods:hierarchicalGeographic> subjects from GeoJSON.
- #render_item_breadcrumb(document) ⇒ Object
-
#render_main_title(document) ⇒ Object
output properly formatted title with volume info, but no subtitle.
-
#render_mlt_search_link(document) ⇒ Object
render the ‘more like this’ search link if doc has subjects.
-
#render_mods_date(date_start, date_end = nil, date_qualifier = nil, date_type = nil) ⇒ Object
returns a properly-formatted date value as a string.
-
#render_mods_dates(document) ⇒ Object
returns an array of properly-formatted date values.
- #render_mods_xml_record(document_id) ⇒ Object
- #render_volume_title(document) ⇒ Object
-
#return_oai_inst_name(document) ⇒ Object
return the correct name of the institution to link to for OAI objects.
-
#setup_collection_links(document, link_class = nil) ⇒ Object
creates an array of collection links for display on catalog#index list view and catalog#show breadcrumb.
-
#setup_names_roles(document) ⇒ Object
create a list of names and roles to be displayed.
- #should_autofocus_on_search_box? ⇒ Boolean
-
#thumbnail_url(document) ⇒ Object
LOCAL OVERRIDE: don’t want to pull thumbnail url from Solr.
Instance Method Details
#cc_terms_code(license) ⇒ Object
returns the CC license terms code for use in URLs, etc.
6 7 8 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 6 def cc_terms_code(license) license.match(/\s[BYNCDSA-]{2,}/).to_s.strip.downcase end |
#cc_url(license) ⇒ Object
returns a link to a CC license
11 12 13 14 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 11 def cc_url(license) terms_code = cc_terms_code(license) "http://creativecommons.org/licenses/#{terms_code}/3.0" end |
#collection_gallery_url(document, size) ⇒ Object
return the image url for the collection gallery view document size = pixel length of square IIIF-created image
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 18 def collection_gallery_url document, size exemplary_image_pid = document[:exemplary_image_ssi] if exemplary_image_pid if exemplary_image_pid.match(/oai/) datastream_disseminator_url(exemplary_image_pid,'thumbnail300') else iiif_square_img_path(exemplary_image_pid, size) end else collection_icon_path end end |
#collection_icon_path ⇒ Object
31 32 33 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 31 def collection_icon_path 'commonwealth-vlr-engine/dc_collection-icon.png' end |
#create_download_links(document, files_hash, link_class) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 35 def create_download_links(document, files_hash, link_class) file_types = [files_hash[:documents], files_hash[:ereader], files_hash[:audio], files_hash[:generic]] download_links = [] file_types.each do |file_type| file_type.each do |file| object_profile_json = JSON.parse(file['object_profile_ssm'].first) file_name_ext = object_profile_json["objLabel"].split('.') download_link_title = document['identifier_ia_id_ssi'] ? ia_download_title(file_name_ext[1]) : file_name_ext[0] download_links << link_to(download_link_title, datastream_disseminator_url(file['id'],'productionMaster'), :target => '_blank', :class => link_class) + content_tag(:span, "(.#{file_name_ext[1]}, #{number_to_human_size(object_profile_json["datastreams"]["productionMaster"]["dsSize"])})", :class => 'download_info') end end download_links end |
#create_thumb_img_element(document, img_class = []) ⇒ Object
54 55 56 57 58 59 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 54 def create_thumb_img_element(document, img_class=[]) image_classes = img_class.class == Array ? img_class.join(' ') : '' image_tag(thumbnail_url(document), :alt => document[blacklight_config.index.title_field.to_sym], :class => image_classes) end |
#extra_body_classes ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 61 def extra_body_classes @extra_body_classes ||= ['blacklight-' + controller_name, 'blacklight-' + [controller_name, controller.action_name].join('-')] # if this is the home page if controller_name == 'pages' && action_name =='home' @extra_body_classes.push('blacklight-home') else @extra_body_classes end end |
#has_downloadable_files?(files_hash) ⇒ Boolean
71 72 73 74 75 76 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 71 def has_downloadable_files? files_hash files_hash[:documents].present? || files_hash[:audio].present? || files_hash[:generic].present? || files_hash[:ereader].present? end |
#has_image_files?(files_hash) ⇒ Boolean
78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 78 def has_image_files? files_hash image_file_pids = nil unless files_hash[:images].empty? image_file_pids = [] files_hash[:images].each do |image_file| image_file_pids << image_file['id'] end end image_file_pids end |
#ia_download_title(file_extension) ⇒ Object
render the file type names for Internet Archive book item download links
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 90 def ia_download_title(file_extension) case file_extension when 'mobi' 'Kindle' when 'zip' 'Daisy' when 'pdf' 'PDF' when 'epub' 'EPUB' else file_extension.upcase end end |
#index_collection_link(options = {}) ⇒ Object
render collection name as a link in catalog#index list view
106 107 108 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 106 def index_collection_link ={} setup_collection_links([:document]).join(' / ').html_safe end |
#index_date_value(options = {}) ⇒ Object
render the date in the catalog#index list view
112 113 114 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 112 def index_date_value ={} render_mods_dates([:document]).first end |
#index_institution_link(options = {}) ⇒ Object
render institution name as a link in catalog#index list view
117 118 119 120 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 117 def index_institution_link ={} link_to([:value].first, institution_path(:id => [:document][:institution_pid_ssi])) end |
#index_relation_base_icon(document) ⇒ Object
render the collection/institution icon if necessary
123 124 125 126 127 128 129 130 131 132 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 123 def index_relation_base_icon document if document[blacklight_config.view_config(document_index_view_type).display_type_field] display_type = document[blacklight_config.view_config(document_index_view_type).display_type_field].downcase if controller_name == 'catalog' && (display_type == 'collection' || display_type == 'institution') image_tag("commonwealth-vlr-engine/dc_#{display_type}-icon.png", alt: "#{display_type} icon", class: "index-title-icon #{display_type}-icon") else '' end end end |
#index_slideshow_img_url(document) ⇒ Object
return the URL of an image to display in the catalog#index slideshow view
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 135 def document if document[:exemplary_image_ssi] && !document[blacklight_config.flagged_field.to_sym] if document[blacklight_config.index.display_type_field.to_sym] == 'OAIObject' || document[:exemplary_image_ssi].match(/oai/) thumbnail_url(document) else iiif_image_url(document[:exemplary_image_ssi], {:size => ',500'}) end elsif document[:type_of_resource_ssim] render_object_icon_path(document[:type_of_resource_ssim].first) elsif document[blacklight_config.index.display_type_field.to_sym] == 'Collection' collection_icon_path elsif document[blacklight_config.index.display_type_field.to_sym] == 'Institution' institution_icon_path else render_object_icon_path(nil) end end |
#index_title_length ⇒ Object
determine the ‘truncate’ length based on catalog#index view type
154 155 156 157 158 159 160 161 162 163 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 154 def index_title_length case params[:view] when 'list' 170 when 'masonry' 89 else 130 end end |
#institution_icon_path ⇒ Object
165 166 167 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 165 def institution_icon_path 'commonwealth-vlr-engine/dc_institution-icon.png' end |
#link_to_az_value(letter, field, search_path, link_class = nil) ⇒ Object
link to items starting with a specific letter
170 171 172 173 174 175 176 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 170 def link_to_az_value(letter, field, search_path, link_class=nil) new_params = params.except(:controller, :action, :q, :page) new_params[:q] = "#{field}:#{letter}*" link_to(letter, self.send(search_path, new_params), class: link_class) end |
#normalize_date(date) ⇒ Object
178 179 180 181 182 183 184 185 186 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 178 def normalize_date(date) if date.length == 10 Date.parse(date).strftime('%B %-d, %Y') elsif date.length == 7 Date.parse(date + '-01').strftime('%B %Y') else date end end |
#render_cc_license(license) ⇒ Object
insert an icon and link to CC licenses
189 190 191 192 193 194 195 196 197 198 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 189 def render_cc_license(license) terms_code = cc_terms_code(license) link_to(image_tag("//i.creativecommons.org/l/#{terms_code}/3.0/80x15.png", :alt => 'CC ' + terms_code.upcase + ' icon', :class => 'cc_license_icon'), cc_url(license), :rel => 'license', :id => 'cc_license_link', :target => '_blank') end |
#render_full_title(document) ⇒ Object
output properly formatted full title, with subtitle, parallel title, etc.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 201 def render_full_title(document) title_output = '' title_output << document[blacklight_config.index.title_field.to_sym] if document[:subtitle_tsim] title_output << " : #{document[:subtitle_tsim].first}" end if document[:title_info_partnum_tsi] title_output << ". #{document[:title_info_partnum_tsi]}" end if document[:title_info_partname_tsi] title_output << ". #{document[:title_info_partname_tsi]}" end if document[:title_info_primary_trans_tsim] document[:title_info_primary_trans_tsim].each do |parallel_title| title_output << " = #{parallel_title}" end end title_output.squish end |
#render_hiergo_subject(geojson_feature, separator, separator_class = nil) ⇒ Object
render metadata for <mods:hierarchicalGeographic> subjects from GeoJSON
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 222 def render_hiergo_subject(geojson_feature, separator, separator_class=nil) output_array = [] hiergeo_hash = JSON.parse(geojson_feature).symbolize_keys[:properties] hiergeo_hash.each_key do |k| if k == 'country' && hiergeo_hash[k] == 'United States' # display 'United States' only if no other values output_array << link_to_facet(hiergeo_hash[k], 'subject_geographic_ssim') if hiergeo_hash.length == 1 elsif k == 'county' output_array << link_to_facet("#{hiergeo_hash[k]} (county)", 'subject_geographic_ssim') elsif k == 'island' || k == 'area' || k == 'province' || k == 'territory' || k == 'region' output_array << link_to_facet(hiergeo_hash[k], 'subject_geographic_ssim') + " (#{k.to_s})" elsif k == 'other' place_type = hiergeo_hash[k].scan(/\([a-z\s]*\)/).last place_name = hiergeo_hash[k].gsub(/#{place_type}/,'').gsub(/\s\(\)\z/,'') output_array << link_to_facet(place_name, 'subject_geographic_ssim') + " #{place_type.to_s}" else output_array << link_to_facet(hiergeo_hash[k], 'subject_geographic_ssim') end end output_array.join(content_tag(:span, separator, :class => separator_class)).html_safe end |
#render_item_breadcrumb(document) ⇒ Object
244 245 246 247 248 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 244 def (document) if document[:collection_pid_ssm] setup_collection_links(document).sort.join(' / ').html_safe end end |
#render_main_title(document) ⇒ Object
output properly formatted title with volume info, but no subtitle
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 251 def render_main_title(document) title_output = '' if document[blacklight_config.index.title_field.to_sym] title_output << document[blacklight_config.index.title_field.to_sym] if document[:title_info_partnum_tsi] title_output << ". #{document[:title_info_partnum_tsi]}" end if document[:title_info_partname_tsi] title_output << ". #{document[:title_info_partname_tsi]}" end else title_output << document.id end title_output.squish end |
#render_mlt_search_link(document) ⇒ Object
render the ‘more like this’ search link if doc has subjects
268 269 270 271 272 273 274 275 276 277 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 268 def render_mlt_search_link(document) if document[:subject_facet_ssim] || document[:subject_geo_city_ssim] content_tag :div, :id => 'more_mlt_link_wrapper' do link_to t('blacklight.more_like_this.more_mlt_link'), search_catalog_path(:mlt_id => document.id, :qt => 'mlt'), :id => 'more_mlt_link' end end end |
#render_mods_date(date_start, date_end = nil, date_qualifier = nil, date_type = nil) ⇒ Object
returns a properly-formatted date value as a string
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 292 def render_mods_date (date_start, date_end = nil, date_qualifier = nil, date_type = nil) prefix = '' suffix = '' date_start_suffix = '' if date_qualifier && date_qualifier != 'nil' prefix = date_qualifier == 'approximate' ? '[ca. ' : '[' suffix = date_qualifier == 'questionable' ? '?]' : ']' end prefix << 'c' if date_type == 'copyrightDate' if date_end && date_end != 'nil' date_start_suffix = '?' if date_qualifier == 'questionable' prefix + normalize_date(date_start) + date_start_suffix + t('blacklight.metadata_display.date_range_connector') + normalize_date(date_end) + suffix else prefix + normalize_date(date_start) + suffix end end |
#render_mods_dates(document) ⇒ Object
returns an array of properly-formatted date values
280 281 282 283 284 285 286 287 288 289 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 280 def render_mods_dates (document) date_values = [] document[:date_start_tsim].each_with_index do |start_date,index| date_type = document[:date_type_ssm] ? document[:date_type_ssm][index] : nil date_qualifier = document[:date_start_qualifier_ssm] ? document[:date_start_qualifier_ssm][index] : nil date_end = document[:date_end_tsim] ? document[:date_end_tsim][index] : nil date_values << render_mods_date(start_date, date_end, date_qualifier, date_type) end date_values end |
#render_mods_xml_record(document_id) ⇒ Object
309 310 311 312 313 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 309 def render_mods_xml_record(document_id) mods_xml_file_path = datastream_disseminator_url(document_id, 'descMetadata') mods_response = Typhoeus::Request.get(mods_xml_file_path) mods_xml_text = REXML::Document.new(mods_response.body) end |
#render_volume_title(document) ⇒ Object
315 316 317 318 319 320 321 322 323 324 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 315 def render_volume_title(document) vol_title_info = [document[:title_info_partnum_tsi], document[:title_info_partname_tsi]] if vol_title_info[0] vol_title_info[1] ? vol_title_info[0].capitalize + ': ' + vol_title_info[1] : vol_title_info[0].capitalize elsif vol_title_info[1] vol_title_info[1].capitalize else render_main_title(document) end end |
#return_oai_inst_name(document) ⇒ Object
return the correct name of the institution to link to for OAI objects
327 328 329 330 331 332 333 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 327 def return_oai_inst_name(document) if document[blacklight_config.institution_field.to_sym] document[blacklight_config.institution_field.to_sym].first else t('blacklight.oai_objects.default_inst_name') end end |
#setup_collection_links(document, link_class = nil) ⇒ Object
creates an array of collection links for display on catalog#index list view and catalog#show breadcrumb
337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 337 def setup_collection_links(document, link_class=nil) coll_hash = {} 0.upto document[:collection_pid_ssm].length-1 do |index| coll_hash[document[blacklight_config.collection_field.to_sym][index]] = document[:collection_pid_ssm][index] end coll_links = [] coll_hash.sort.each do |coll_array| coll_links << link_to(coll_array[0], collection_path(:id => coll_array[1]), :class => link_class.presence) end coll_links end |
#setup_names_roles(document) ⇒ Object
create a list of names and roles to be displayed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 352 def setup_names_roles(document) names = [] roles = [] multi_role_indices = [] name_fields = [document[:name_personal_tsim], document[:name_corporate_tsim], document[:name_generic_tsim]] role_fields = [document[:name_personal_role_tsim], document[:name_corporate_role_tsim], document[:name_generic_role_tsim]] name_fields.each_with_index do |name_field,name_field_index| if name_field 0.upto name_field.length-1 do |index| names << name_field[index] if role_fields[name_field_index] && role_fields[name_field_index][index] roles << role_fields[name_field_index][index].strip else roles << 'Creator' end end end end roles.each_with_index do |role,index| if /[\|]{2}/.match(role) multi_roles = role.split('||') multi_role_name = names[index] multi_role_indices << index multi_roles.each { |multi_role| roles << multi_role } 0.upto multi_roles.length-1 do names << multi_role_name end end end unless multi_role_indices.empty? multi_role_indices.reverse.each do |index| names.delete_at(index) roles.delete_at(index) end end return names,roles end |
#should_autofocus_on_search_box? ⇒ Boolean
390 391 392 393 394 395 396 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 390 def should_autofocus_on_search_box? (controller.is_a? Blacklight::Catalog and action_name == "index" and params[:q].to_s.empty? and params[:f].to_s.empty?) or (controller.is_a? PagesController and action_name == 'home') end |
#thumbnail_url(document) ⇒ Object
LOCAL OVERRIDE: don’t want to pull thumbnail url from Solr
399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 399 def thumbnail_url document if document[:exemplary_image_ssi] && !document[blacklight_config.flagged_field.to_sym] datastream_disseminator_url(document[:exemplary_image_ssi], 'thumbnail300') elsif document[:type_of_resource_ssim] render_object_icon_path(document[:type_of_resource_ssim].first) elsif document[blacklight_config.index.display_type_field.to_sym] == 'Collection' collection_icon_path elsif document[blacklight_config.index.display_type_field.to_sym] == 'Institution' institution_icon_path else render_object_icon_path(nil) end end |