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_thumb_img_element(document, img_class = []) ⇒ Object
- #extra_body_classes ⇒ Object
- #has_image_files?(files_hash) ⇒ Boolean
- #image_file_pids(images_hash) ⇒ Object
-
#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
TODO: uncomment and write spec after issues identified with render_search_to_page_title resolved def render_search_to_page_title_mlt(params) return “”.html_safe if params.blank? “#:label => t(‘blacklight.more_like_this.constraint_label’)) #)” end.
-
#render_search_to_page_title(params) ⇒ Object
have to override to display non-typical constraints (e.g. coordinates, mlt, range limit, advanced search) need this until: github.com/projectblacklight/blacklight_advanced_search/issues/53 github.com/projectblacklight/blacklight-maps/issues/84 github.com/projectblacklight/blacklight_range_limit/issues/49 are resolved.
- #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_thumb_img_element(document, img_class = []) ⇒ Object
35 36 37 38 39 40 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 35 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
42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 42 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_image_files?(files_hash) ⇒ Boolean
52 53 54 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 52 def has_image_files? files_hash files_hash[:images].present? end |
#image_file_pids(images_hash) ⇒ Object
56 57 58 59 60 61 62 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 56 def image_file_pids images_hash image_file_pids = [] images_hash.each do |image_file| image_file_pids << image_file['id'] end image_file_pids end |
#index_collection_link(options = {}) ⇒ Object
render collection name as a link in catalog#index list view
65 66 67 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 65 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
71 72 73 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 71 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
76 77 78 79 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 76 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
82 83 84 85 86 87 88 89 90 91 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 82 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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 94 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
113 114 115 116 117 118 119 120 121 122 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 113 def index_title_length case params[:view] when 'list' 170 when 'masonry' 89 else 130 end end |
#institution_icon_path ⇒ Object
124 125 126 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 124 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
129 130 131 132 133 134 135 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 129 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
137 138 139 140 141 142 143 144 145 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 137 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
148 149 150 151 152 153 154 155 156 157 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 148 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.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 160 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
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 181 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
203 204 205 206 207 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 203 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
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 210 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
227 228 229 230 231 232 233 234 235 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 227 def render_mlt_search_link(document) if document[:subject_facet_ssim] || document[:subject_geo_city_ssim] || document[:related_item_host_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), 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
250 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 250 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
238 239 240 241 242 243 244 245 246 247 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 238 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
TODO: uncomment and write spec after issues identified with render_search_to_page_title resolved def render_search_to_page_title_mlt(params)
return "".html_safe if params[:mlt_id].blank?
"#{t('blacklight.search.filters.label', :label => t('blacklight.more_like_this.constraint_label'))} #{h(params[:mlt_id])}"
end
292 293 294 295 296 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 292 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_search_to_page_title(params) ⇒ Object
have to override to display non-typical constraints (e.g. coordinates, mlt, range limit, advanced search) need this until: github.com/projectblacklight/blacklight_advanced_search/issues/53 github.com/projectblacklight/blacklight-maps/issues/84 github.com/projectblacklight/blacklight_range_limit/issues/49 are resolved
274 275 276 277 278 279 280 281 282 283 284 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 274 def render_search_to_page_title(params) # this is ugly, but easiest way to deal with it; too many gems to try and solve it all here html_constraints = render_search_to_s(params).gsub(/<span class="filterValues">/,' ') html_constraints = html_constraints.gsub(/<\/span>[\s]*<span class="constraint">/,' / ') sanitize(html_constraints, :tags=>[]) ## TODO: remove above and uncomment lines below after all issues have been resolved with ## blacklight_advanced_search, blacklight_range_limit, and blacklight-maps # constraints = [render_search_to_page_title_mlt(params), super(params)] # constraints.reject { |item| item.blank? }.join(' / ') end |
#render_volume_title(document) ⇒ Object
298 299 300 301 302 303 304 305 306 307 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 298 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
310 311 312 313 314 315 316 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 310 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
320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 320 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
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 335 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
373 374 375 376 377 378 379 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 373 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
382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'app/helpers/commonwealth_vlr_engine/catalog_helper.rb', line 382 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 |