commonwealth-vlr-engine 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_120x120.png +0 -0
  4. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_152x152.png +0 -0
  5. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_60x60.png +0 -0
  6. data/app/assets/images/commonwealth-vlr-engine/vlr_mobile-icons_76x76.png +0 -0
  7. data/app/assets/javascripts/blacklight_google_analytics/blacklight_google_analytics.js.erb +11 -0
  8. data/app/assets/javascripts/commonwealth-vlr-engine.js +3 -0
  9. data/app/assets/javascripts/commonwealth-vlr-engine/download_utils.js +4 -0
  10. data/app/assets/stylesheets/commonwealth-vlr-engine/commonwealth-vlr-engine.css +1 -0
  11. data/app/assets/stylesheets/commonwealth-vlr-engine/downloads.scss +18 -0
  12. data/app/assets/stylesheets/commonwealth-vlr-engine/facets.scss +64 -0
  13. data/app/assets/stylesheets/commonwealth-vlr-engine/vlr_dependencies.css +3 -1
  14. data/app/controllers/bookmarks_controller.rb +7 -2
  15. data/app/controllers/collections_controller.rb +1 -109
  16. data/app/controllers/concerns/commonwealth_vlr_engine/collections_controller_behavior.rb +132 -0
  17. data/app/controllers/concerns/commonwealth_vlr_engine/downloads_controller_behavior.rb +184 -0
  18. data/app/controllers/concerns/commonwealth_vlr_engine/institutions_controller_behavior.rb +70 -0
  19. data/app/controllers/downloads_controller.rb +4 -0
  20. data/app/controllers/iiif_manifest_controller.rb +2 -7
  21. data/app/controllers/image_viewer_controller.rb +3 -13
  22. data/app/controllers/institutions_controller.rb +1 -65
  23. data/app/controllers/ocr_search_controller.rb +1 -1
  24. data/app/controllers/saved_searches_controller.rb +2 -0
  25. data/app/controllers/search_history_controller.rb +2 -0
  26. data/app/helpers/commonwealth_vlr_engine/application_helper.rb +20 -2
  27. data/app/helpers/commonwealth_vlr_engine/catalog_helper.rb +36 -53
  28. data/app/helpers/commonwealth_vlr_engine/downloads_helper_behavior.rb +192 -0
  29. data/app/helpers/commonwealth_vlr_engine/facets_helper.rb +3 -1
  30. data/app/helpers/commonwealth_vlr_engine/ocr_search_helper_behavior.rb +5 -0
  31. data/app/helpers/commonwealth_vlr_engine/search_history_constraints_helper.rb +25 -0
  32. data/app/helpers/downloads_helper.rb +3 -0
  33. data/app/views/catalog/_add_this.html.erb +3 -1
  34. data/app/views/catalog/_folder_item_control.html.erb +2 -1
  35. data/app/views/catalog/_index_mapview.html.erb +9 -0
  36. data/app/views/catalog/_more_like_this.html.erb +1 -1
  37. data/app/views/catalog/_show_cite_tools.html.erb +3 -0
  38. data/app/views/catalog/_show_default.html.erb +13 -12
  39. data/app/views/catalog/_show_partials/_show_book_viewer_link.html.erb +1 -1
  40. data/app/views/catalog/_show_partials/_show_default_metadata.html.erb +3 -3
  41. data/app/views/catalog/_show_partials/_show_downloads.html.erb +1 -1
  42. data/app/views/catalog/_show_partials/_show_volumes.html.erb +1 -1
  43. data/app/views/catalog/_show_sharing_tools.html.erb +3 -0
  44. data/app/views/collections/show.html.erb +1 -0
  45. data/app/views/downloads/_terms_of_use.html.erb +29 -0
  46. data/app/views/downloads/show.html.erb +29 -0
  47. data/app/views/image_viewer/_render_book_viewer.html.erb +1 -1
  48. data/app/views/institutions/show.html.erb +2 -10
  49. data/app/views/layouts/commonwealth-vlr-engine.html.erb +1 -4
  50. data/app/views/ocr_search/_index_ocr_list.html.erb +3 -3
  51. data/app/views/shared/_mobile_icon_tags.html.erb +4 -0
  52. data/app/views/shared/_search_form_header.html.erb +1 -1
  53. data/app/views/shared/_tools.html.erb +5 -5
  54. data/commonwealth-vlr-engine.gemspec +8 -6
  55. data/config/initializers/patch_blacklight_advanced_search.rb +6 -6
  56. data/config/initializers/patch_blacklight_range_limit.rb +18 -0
  57. data/config/jetty.yml +1 -1
  58. data/config/locales/commonwealth-vlr-engine.en.yml +12 -0
  59. data/config/routes.rb +6 -0
  60. data/lib/commonwealth-vlr-engine.rb +1 -0
  61. data/lib/commonwealth-vlr-engine/controller.rb +18 -3
  62. data/lib/commonwealth-vlr-engine/controller_override.rb +79 -21
  63. data/lib/commonwealth-vlr-engine/engine.rb +1 -0
  64. data/lib/commonwealth-vlr-engine/render_constraints_override.rb +15 -14
  65. data/lib/commonwealth-vlr-engine/search_builder/collections_search_builder.rb +1 -1
  66. data/lib/commonwealth-vlr-engine/search_builder/commonwealth_search_builder_behavior.rb +13 -1
  67. data/lib/commonwealth-vlr-engine/search_builder/flagged_search_builder.rb +1 -1
  68. data/lib/commonwealth-vlr-engine/search_builder/institutions_search_builder.rb +1 -1
  69. data/lib/commonwealth-vlr-engine/search_builder/mlt_search_builder.rb +2 -1
  70. data/lib/commonwealth-vlr-engine/streaming.rb +50 -0
  71. data/lib/commonwealth-vlr-engine/version.rb +1 -1
  72. data/lib/generators/commonwealth_vlr_engine/routes_generator.rb +8 -0
  73. data/lib/generators/commonwealth_vlr_engine/templates/commonwealth_search_builder.rb +4 -3
  74. data/lib/generators/commonwealth_vlr_engine/templates/config/vlr.yml +3 -0
  75. data/solr_conf/conf/solrconfig.xml +42 -5
  76. data/spec/controllers/collections_controller_spec.rb +20 -0
  77. data/spec/controllers/downloads_controller_spec.rb +65 -0
  78. data/spec/controllers/image_viewer_controller_spec.rb +0 -18
  79. data/spec/controllers/institutions_controller_spec.rb +7 -0
  80. data/spec/features/advanced_search_date_range_spec.rb +36 -0
  81. data/spec/features/collections/index_spec.rb +6 -0
  82. data/spec/features/collections/show_spec.rb +38 -0
  83. data/spec/features/more_like_this_search_spec.rb +18 -1
  84. data/spec/fixtures/sample_solr_documents.yml +107 -19
  85. data/spec/helpers/application_helper_spec.rb +9 -2
  86. data/spec/helpers/catalog_helper_spec.rb +26 -42
  87. data/spec/helpers/downloads_helper_spec.rb +173 -0
  88. data/spec/helpers/ocr_search_helper_spec.rb +15 -7
  89. data/spec/helpers/range_limit_helper_spec.rb +20 -0
  90. data/spec/helpers/search_history_constraints_helper_spec.rb +39 -0
  91. data/spec/lib/commonwealth-vlr-engine/controller_override_spec.rb +37 -0
  92. data/spec/lib/commonwealth-vlr-engine/render_constraints_override_spec.rb +0 -10
  93. data/spec/lib/commonwealth-vlr-engine/search_builder/commonwealth_search_builder_behavior_spec.rb +21 -3
  94. data/spec/lib/commonwealth-vlr-engine/search_builder/mlt_search_builder_spec.rb +1 -1
  95. metadata +99 -12
  96. data/app/helpers/commonwealth_vlr_engine/component_helper.rb +0 -22
  97. data/app/views/catalog/_show_tools.html.erb +0 -42
  98. data/spec/helpers/component_helper_spec.rb +0 -34
@@ -0,0 +1,70 @@
1
+ module CommonwealthVlrEngine
2
+ module InstitutionsControllerBehavior
3
+ extend ActiveSupport::Concern
4
+ ##
5
+ # Give Bookmarks access to the CatalogController configuration
6
+ include Blacklight::Configurable
7
+ include Blacklight::SearchHelper
8
+
9
+ included do
10
+ copy_blacklight_config_from(CatalogController)
11
+
12
+ before_filter :institutions_index_config, :only => [:index]
13
+ # remove collection facet and collapse others
14
+ before_filter :relation_base_blacklight_config, :only => [:show]
15
+
16
+ helper_method :search_action_url
17
+ end
18
+
19
+ def index
20
+ @nav_li_active = 'explore'
21
+ params[:per_page] = params[:per_page].presence || '50'
22
+ (@response, @document_list) = search_results(params)
23
+ params[:view] ||= 'list' # still need this or grid view is invoked
24
+ params[:sort] = 'title_info_primary_ssort asc'
25
+
26
+ respond_to do |format|
27
+ format.html
28
+ end
29
+ end
30
+
31
+ def show
32
+ @nav_li_active = 'explore'
33
+ @show_response, @document = fetch(params[:id])
34
+ @institution_title = @document[blacklight_config.index.title_field.to_sym]
35
+
36
+ # get the response for collection objects
37
+ @collex_response, @collex_documents = search_results({:f => {'active_fedora_model_suffix_ssi' => 'Collection','institution_pid_ssi' => params[:id]},:rows => 100, :sort => 'title_info_primary_ssort asc'})
38
+
39
+ # add params[:f] for proper facet links
40
+ params[:f] = {blacklight_config.institution_field => [@institution_title]}
41
+
42
+ # get the response for the facets representing items in collection
43
+ (@response, @document_list) = search_results({:f => params[:f]})
44
+
45
+ respond_to do |format|
46
+ format.html
47
+ end
48
+
49
+ end
50
+
51
+ def range_limit
52
+ redirect_to range_limit_catalog_path(params.except('controller', 'action')) and return
53
+ end
54
+
55
+ protected
56
+
57
+ # Blacklight uses #search_action_url to figure out the right URL for the global search box
58
+ def search_action_url options = {}
59
+ search_catalog_url(options.except(:controller, :action))
60
+ end
61
+
62
+ # remove grid view from blacklight_config, use correct SearchBuilder for index view
63
+ def institutions_index_config
64
+ blacklight_config.search_builder_class = CommonwealthInstitutionsSearchBuilder
65
+ blacklight_config.view.delete(:gallery)
66
+ blacklight_config.view.delete(:masonry)
67
+ blacklight_config.view.delete(:slideshow)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,4 @@
1
+ class DownloadsController < ApplicationController
2
+ include CommonwealthVlrEngine::DownloadsControllerBehavior
3
+
4
+ end
@@ -21,7 +21,7 @@ class IiifManifestController < CatalogController
21
21
  canvas_response, canvas_document = fetch(params[:canvas_object_id])
22
22
  if canvas_document[:is_file_of_ssim]
23
23
  response, document = fetch(params[:id])
24
- image_files = has_image_files?(get_files(params[:id]))
24
+ image_files = image_file_pids(get_image_files(params[:id]))
25
25
  if image_files
26
26
  image_index = Hash[image_files.map.with_index.to_a][params[:canvas_object_id]]
27
27
  iiif_canvas = canvas_from_id(params[:canvas_object_id],
@@ -38,7 +38,7 @@ class IiifManifestController < CatalogController
38
38
 
39
39
  def annotation
40
40
  response, document = fetch(params[:id])
41
- if has_image_files?(get_files(params[:id])).include?(params[:annotation_object_id])
41
+ if image_file_pids(get_image_files(params[:id])).include?(params[:annotation_object_id])
42
42
  annotation = image_annotation_from_image_id(params[:annotation_object_id], document)
43
43
  render :json => annotation.to_json
44
44
  else
@@ -66,9 +66,4 @@ class IiifManifestController < CatalogController
66
66
  headers['Access-Control-Allow-Origin'] = "*"
67
67
  end
68
68
 
69
- def not_found
70
- raise ActionController::RoutingError.new('Not Found')
71
- end
72
-
73
-
74
69
  end
@@ -5,9 +5,9 @@ class ImageViewerController < CatalogController
5
5
 
6
6
  def show
7
7
  @response, @document = fetch(params[:id])
8
- #@img_to_show = params[:view]
9
8
  @title = @document[blacklight_config.index.title_field.to_sym]
10
- @page_sequence = get_page_sequence(@document.id, params[:view])
9
+ # @object_files is already set by before_filter in CommonwealthVlrEngine::ControllerOverride
10
+ @page_sequence = create_img_sequence(image_file_pids(@object_files[:images]), params[:view])
11
11
  respond_to do |format|
12
12
  format.js
13
13
  format.html { redirect_to solr_document_path(@document.id,
@@ -17,18 +17,8 @@ class ImageViewerController < CatalogController
17
17
 
18
18
  def book_viewer
19
19
  @response, @document = fetch(params[:id])
20
- @image_files = has_image_files?(get_files(params[:id]))
20
+ @image_files = image_file_pids(get_image_files(params[:id]))
21
21
  render(:layout => 'book_viewer')
22
22
  end
23
23
 
24
- private
25
-
26
- def get_page_sequence(document_id, current_img_id)
27
- image_files = []
28
- get_image_files(document_id).each do |img_file|
29
- image_files << img_file['id']
30
- end
31
- create_img_sequence(image_files, current_img_id)
32
- end
33
-
34
24
  end
@@ -1,68 +1,4 @@
1
1
  class InstitutionsController < CatalogController
2
-
3
- ##
4
- # Give Bookmarks access to the CatalogController configuration
5
- include Blacklight::Configurable
6
- include Blacklight::SearchHelper
7
-
8
- copy_blacklight_config_from(CatalogController)
9
-
10
- before_filter :institutions_index_config, :only => [:index]
11
- # remove collection facet and collapse others
12
- before_filter :relation_base_blacklight_config, :only => [:show]
13
-
14
- # Blacklight uses #search_action_url to figure out the right URL for
15
- # the global search box
16
- def search_action_url options = {}
17
- search_catalog_url(options.except(:controller, :action))
18
- end
19
- helper_method :search_action_url
20
-
21
- def index
22
- @nav_li_active = 'explore'
23
- params[:per_page] = params[:per_page].presence || '50'
24
- (@response, @document_list) = search_results(params)
25
- params[:view] ||= 'list' # still need this or grid view is invoked
26
- params[:sort] = 'title_info_primary_ssort asc'
27
-
28
- respond_to do |format|
29
- format.html
30
- end
31
- end
32
-
33
- def show
34
- @nav_li_active = 'explore'
35
- @show_response, @document = fetch(params[:id])
36
- @institution_title = @document[blacklight_config.index.title_field.to_sym]
37
-
38
- # get the response for collection objects
39
- @collex_response, @collex_documents = search_results({:f => {'active_fedora_model_suffix_ssi' => 'Collection','institution_pid_ssi' => params[:id]},:rows => 100, :sort => 'title_info_primary_ssort asc'})
40
-
41
- # add params[:f] for proper facet links
42
- params[:f] = {blacklight_config.institution_field => [@institution_title]}
43
-
44
- # get the response for the facets representing items in collection
45
- (@response, @document_list) = search_results({:f => params[:f]})
46
-
47
- # get an image for the institution
48
- if @document[:exemplary_image_ssi]
49
- @institution_image_pid = @document[:exemplary_image_ssi]
50
- end
51
-
52
- respond_to do |format|
53
- format.html
54
- end
55
-
56
- end
57
-
58
- private
59
-
60
- # remove grid view from blacklight_config, use correct SearchBuilder for index view
61
- def institutions_index_config
62
- blacklight_config.search_builder_class = CommonwealthInstitutionsSearchBuilder
63
- blacklight_config.view.delete(:gallery)
64
- blacklight_config.view.delete(:masonry)
65
- blacklight_config.view.delete(:slideshow)
66
- end
2
+ include CommonwealthVlrEngine::InstitutionsControllerBehavior
67
3
 
68
4
  end
@@ -13,7 +13,7 @@ class OcrSearchController < CatalogController
13
13
  def index
14
14
  @doc_response, @document = fetch(params[:id])
15
15
  if params[:ocr_q]
16
- @image_pid_list = has_image_files?(get_files(params[:id]))
16
+ @image_pid_list = image_file_pids(get_image_files(params[:id]))
17
17
  ocr_search_params = {q: params[:ocr_q],
18
18
  f: {'is_file_of_ssim' => "info:fedora/#{params[:id]}"}}
19
19
  ocr_search_params[:page] = params[:page] if params[:page]
@@ -4,5 +4,7 @@ class SavedSearchesController < ApplicationController
4
4
 
5
5
  helper BlacklightAdvancedSearch::RenderConstraintsOverride
6
6
  helper BlacklightMaps::RenderConstraintsOverride
7
+ helper BlacklightRangeLimit::ViewHelperOverride
8
+ helper RangeLimitHelper
7
9
  helper CommonwealthVlrEngine::RenderConstraintsOverride
8
10
  end
@@ -4,5 +4,7 @@ class SearchHistoryController < ApplicationController
4
4
 
5
5
  helper BlacklightAdvancedSearch::RenderConstraintsOverride
6
6
  helper BlacklightMaps::RenderConstraintsOverride
7
+ helper BlacklightRangeLimit::ViewHelperOverride
8
+ helper RangeLimitHelper
7
9
  helper CommonwealthVlrEngine::RenderConstraintsOverride
8
10
  end
@@ -29,8 +29,8 @@ module CommonwealthVlrEngine
29
29
  end
30
30
  end
31
31
 
32
- def render_format_index(args)
33
- render_format(args[:document][args[:field]])
32
+ def render_format_index(options={})
33
+ options[:value].map { |v| render_format(v) }.join('; ')
34
34
  end
35
35
 
36
36
  # return the path to the icon for objects with no thumbnail
@@ -48,6 +48,19 @@ module CommonwealthVlrEngine
48
48
  "commonwealth-vlr-engine/dc_#{icon}-icon.png"
49
49
  end
50
50
 
51
+ # render date range constraints from Advanced Search form
52
+ # used by CommonwealthVlrEngine::RenderConstraintsOverride
53
+ # and CommonwealthVlrEngine::SearchHistoryConstraintsHelper
54
+ def date_range_constraints_to_s(params)
55
+ if params[:date_start].blank?
56
+ "before #{params[:date_end]}"
57
+ elsif params[:date_end].blank?
58
+ "after #{params[:date_start]}"
59
+ else
60
+ "#{params[:date_start]}-#{params[:date_end]}"
61
+ end
62
+ end
63
+
51
64
  #from psu scholarsphere
52
65
  # TODO: this isn't used anywhere in the app, get rid of it?
53
66
  def link_to_field(fieldname, fieldvalue, displayvalue = nil)
@@ -195,6 +208,11 @@ module CommonwealthVlrEngine
195
208
  }.to_json
196
209
  end
197
210
 
211
+ # adds apple-touch-icon tags to <head>
212
+ def render_mobile_icon_tags
213
+ render partial: 'shared/mobile_icon_tags'
214
+ end
215
+
198
216
  end
199
217
  end
200
218
 
@@ -32,25 +32,6 @@ module CommonwealthVlrEngine
32
32
  'commonwealth-vlr-engine/dc_collection-icon.png'
33
33
  end
34
34
 
35
- def create_download_links(document, files_hash, link_class)
36
- file_types = [files_hash[:audio], files_hash[:documents], files_hash[:ereader], files_hash[:generic]]
37
- download_links = []
38
- file_types.each do |file_type|
39
- file_type.each do |file|
40
- object_profile_json = JSON.parse(file['object_profile_ssm'].first)
41
- file_name_ext = object_profile_json["objLabel"].split('.')
42
- download_link_title = document['identifier_ia_id_ssi'] ? ia_download_title(file_name_ext[1]) : file_name_ext[0]
43
- download_links << link_to(download_link_title,
44
- datastream_disseminator_url(file['id'],'productionMaster'),
45
- :target => '_blank',
46
- :class => link_class) + content_tag(:span,
47
- "(#{file_name_ext[1].upcase}, #{number_to_human_size(object_profile_json["datastreams"]["productionMaster"]["dsSize"])})",
48
- :class => 'download_info')
49
- end
50
- end
51
- download_links
52
- end
53
-
54
35
  def create_thumb_img_element(document, img_class=[])
55
36
  image_classes = img_class.class == Array ? img_class.join(' ') : ''
56
37
  image_tag(thumbnail_url(document),
@@ -68,38 +49,16 @@ module CommonwealthVlrEngine
68
49
  end
69
50
  end
70
51
 
71
- def has_downloadable_files? files_hash
72
- files_hash[:documents].present? ||
73
- files_hash[:audio].present? ||
74
- files_hash[:generic].present? ||
75
- files_hash[:ereader].present?
76
- end
77
-
78
52
  def has_image_files? files_hash
79
- image_file_pids = nil
80
- unless files_hash[:images].empty?
81
- image_file_pids = []
82
- files_hash[:images].each do |image_file|
83
- image_file_pids << image_file['id']
84
- end
85
- end
86
- image_file_pids
53
+ files_hash[:images].present?
87
54
  end
88
55
 
89
- # render the file type names for Internet Archive book item download links
90
- def ia_download_title(file_extension)
91
- case file_extension
92
- when 'mobi'
93
- 'Kindle'
94
- when 'zip'
95
- 'Daisy'
96
- when 'pdf'
97
- 'PDF'
98
- when 'epub'
99
- 'EPUB'
100
- else
101
- file_extension.upcase
56
+ def image_file_pids images_hash
57
+ image_file_pids = []
58
+ images_hash.each do |image_file|
59
+ image_file_pids << image_file['id']
102
60
  end
61
+ image_file_pids
103
62
  end
104
63
 
105
64
  # render collection name as a link in catalog#index list view
@@ -266,12 +225,11 @@ module CommonwealthVlrEngine
266
225
 
267
226
  # render the 'more like this' search link if doc has subjects
268
227
  def render_mlt_search_link(document)
269
- if document[:subject_facet_ssim] || document[:subject_geo_city_ssim]
270
- content_tag :div, :id => 'more_mlt_link_wrapper' do
228
+ if document[:subject_facet_ssim] || document[:subject_geo_city_ssim] || document[:related_item_host_ssim]
229
+ content_tag :div, id: 'more_mlt_link_wrapper' do
271
230
  link_to t('blacklight.more_like_this.more_mlt_link'),
272
- search_catalog_path(:mlt_id => document.id,
273
- :qt => 'mlt'),
274
- :id => 'more_mlt_link'
231
+ search_catalog_path(mlt_id: document.id),
232
+ id: 'more_mlt_link'
275
233
  end
276
234
  end
277
235
  end
@@ -297,7 +255,7 @@ module CommonwealthVlrEngine
297
255
  prefix = date_qualifier == 'approximate' ? '[ca. ' : '['
298
256
  suffix = date_qualifier == 'questionable' ? '?]' : ']'
299
257
  end
300
- prefix << 'c' if date_type == 'copyrightDate'
258
+ prefix << '(c) ' if date_type == 'copyrightDate'
301
259
  if date_end && date_end != 'nil'
302
260
  date_start_suffix = '?' if date_qualifier == 'questionable'
303
261
  prefix + normalize_date(date_start) + date_start_suffix + t('blacklight.metadata_display.date_range_connector') + normalize_date(date_end) + suffix
@@ -306,6 +264,31 @@ module CommonwealthVlrEngine
306
264
  end
307
265
  end
308
266
 
267
+ # have to override to display non-typical constraints
268
+ # (e.g. coordinates, mlt, range limit, advanced search)
269
+ # need this until:
270
+ # https://github.com/projectblacklight/blacklight_advanced_search/issues/53
271
+ # https://github.com/projectblacklight/blacklight-maps/issues/84
272
+ # https://github.com/projectblacklight/blacklight_range_limit/issues/49
273
+ # are resolved
274
+ def render_search_to_page_title(params)
275
+ # this is ugly, but easiest way to deal with it; too many gems to try and solve it all here
276
+ html_constraints = render_search_to_s(params).gsub(/<span class="filterValues">/,' ')
277
+ html_constraints = html_constraints.gsub(/<\/span>[\s]*<span class="constraint">/,' / ')
278
+ sanitize(html_constraints, :tags=>[])
279
+
280
+ ## TODO: remove above and uncomment lines below after all issues have been resolved with
281
+ ## blacklight_advanced_search, blacklight_range_limit, and blacklight-maps
282
+ # constraints = [render_search_to_page_title_mlt(params), super(params)]
283
+ # constraints.reject { |item| item.blank? }.join(' / ')
284
+ end
285
+
286
+ # TODO: uncomment and write spec after issues identified with render_search_to_page_title resolved
287
+ #def render_search_to_page_title_mlt(params)
288
+ # return "".html_safe if params[:mlt_id].blank?
289
+ # "#{t('blacklight.search.filters.label', :label => t('blacklight.more_like_this.constraint_label'))} #{h(params[:mlt_id])}"
290
+ #end
291
+
309
292
  def render_mods_xml_record(document_id)
310
293
  mods_xml_file_path = datastream_disseminator_url(document_id, 'descMetadata')
311
294
  mods_response = Typhoeus::Request.get(mods_xml_file_path)
@@ -0,0 +1,192 @@
1
+ module CommonwealthVlrEngine
2
+ module DownloadsHelperBehavior
3
+
4
+ # create an array of download links
5
+ # images have to be handled by a separate function since there are multiple sizes
6
+ def create_download_links(document, files_hash)
7
+ download_links = []
8
+ non_img_file_types = [files_hash[:audio], files_hash[:documents], files_hash[:ereader], files_hash[:generic]]
9
+ if has_downloadable_images?(document, files_hash) && !files_hash[:images].empty?
10
+ download_links.concat(image_download_links(document, files_hash[:images]))
11
+ end
12
+ non_img_file_types.each do |file_type|
13
+ file_type.each do |file|
14
+ object_profile_json = JSON.parse(file['object_profile_ssm'].first)
15
+ download_links << file_download_link(file['id'],
16
+ download_link_title(document, object_profile_json),
17
+ object_profile_json,
18
+ 'productionMaster',
19
+ download_link_options)
20
+ end
21
+ end
22
+ download_links
23
+ end
24
+
25
+ def download_link_class
26
+ 'sidebar_downloads_link'
27
+ end
28
+
29
+ def download_link_options
30
+ {class: download_link_class, rel: 'nofollow', data: {:ajax_modal => 'trigger'}}
31
+ end
32
+
33
+ def download_link_title(document, object_profile, datastream_id=nil)
34
+ if !object_profile || (document[:has_model_ssim].include? "info:fedora/afmodel:Bplmodels_ImageFile")
35
+ link_title = t("blacklight.downloads.images.#{datastream_id}")
36
+ else
37
+ file_name_ext = object_profile["objLabel"].split('.')
38
+ if document[:identifier_ia_id_ssi] || (document[:active_fedora_model_ssi] == "Bplmodels::EreaderFile")
39
+ link_title = ia_download_title(file_name_ext[1])
40
+ else
41
+ link_title = file_name_ext[0]
42
+ end
43
+ end
44
+ link_title
45
+ end
46
+
47
+ def has_downloadable_files?(document, files_hash)
48
+ has_downloadable_images?(document, files_hash) ||
49
+ files_hash[:documents].present? ||
50
+ files_hash[:audio].present? ||
51
+ files_hash[:generic].present? ||
52
+ files_hash[:ereader].present?
53
+ end
54
+
55
+ def has_downloadable_images?(document, files_hash)
56
+ has_image_files?(files_hash) && license_allows_download?(document)
57
+ end
58
+
59
+ # render the file type names for Internet Archive book item download links
60
+ def ia_download_title(file_extension)
61
+ case file_extension
62
+ when 'mobi'
63
+ 'Kindle'
64
+ when 'zip'
65
+ 'Daisy'
66
+ else
67
+ file_extension.upcase
68
+ end
69
+ end
70
+
71
+ def image_datastreams(object_profile_json)
72
+ image_datastreams = []
73
+ stored_datastreams = %w(productionMaster access800 georectifiedMaster)
74
+ stored_datastreams.each do |datastream_id|
75
+ image_datastreams << datastream_id if object_profile_json["datastreams"][datastream_id]
76
+ end
77
+ image_datastreams.insert(1, 'accessFull')
78
+ end
79
+
80
+ def image_download_links(document, image_files_hash)
81
+ if document[:identifier_ia_id_ssi]
82
+ [file_download_link(document[:id],
83
+ t("blacklight.downloads.images.accessFull"),
84
+ nil,
85
+ 'JPEG2000',
86
+ download_link_options)]
87
+ else
88
+ object_profile_json = JSON.parse(image_files_hash.first['object_profile_ssm'].first)
89
+ image_links = []
90
+ image_datastreams(object_profile_json).each do |datastream_id|
91
+ if image_files_hash.length == 1
92
+ object_profile = object_profile_json
93
+ object_id = image_files_hash.first['id']
94
+ else
95
+ object_profile = setup_zip_object_profile(image_files_hash, datastream_id)
96
+ object_id = document[:id]
97
+ end
98
+ image_links << file_download_link(object_id,
99
+ t("blacklight.downloads.images.#{datastream_id}"),
100
+ object_profile,
101
+ datastream_id,
102
+ download_link_options)
103
+ end
104
+ image_links
105
+ end
106
+ end
107
+
108
+ # parse the license statement and return true if image downloads are allowed
109
+ def license_allows_download? document
110
+ document[:license_ssm].to_s =~ /(Creative Commons|No known restrictions)/
111
+ end
112
+
113
+ def file_download_link(object_pid, link_title, object_profile_json, datastream_id, link_options={})
114
+ link_to(link_title,
115
+ download_path(object_pid, datastream_id: datastream_id),
116
+ link_options) + content_tag(:span,
117
+ "(#{file_type_string(datastream_id, object_profile_json)}, #{file_size_string(datastream_id, object_profile_json)})",
118
+ class: 'download_info')
119
+ end
120
+
121
+ def file_type_string(datastream_id, object_profile_json)
122
+ if object_profile_json
123
+ if datastream_id == 'accessFull' || datastream_id == 'access800'
124
+ file_type_string = 'JPEG'
125
+ else
126
+ #file_type_string = object_profile_json["datastreams"][datastream_id]["dsMIME"].split('/')[1].upcase
127
+ file_type_string = object_profile_json["objLabel"].split('.')[1].upcase
128
+ end
129
+ file_type_string << ', multi-file ZIP' if object_profile_json["zip"]
130
+ else
131
+ file_type_string = case datastream_id
132
+ when 'productionMaster'
133
+ 'TIF'
134
+ when 'JPEG2000'
135
+ datastream_id
136
+ else
137
+ 'JPEG'
138
+ end
139
+ end
140
+ file_type_string
141
+ end
142
+
143
+ def file_size_string(datastream_id, object_profile_json)
144
+ if object_profile_json
145
+ if datastream_id == 'accessFull'
146
+ file_size_string = '~' +
147
+ number_to_human_size((object_profile_json["datastreams"]["productionMaster"]["dsSize"] * 0.083969078))
148
+ else
149
+ file_size_string = number_to_human_size(object_profile_json["datastreams"][datastream_id]["dsSize"])
150
+ file_size_string.insert(0,'~') if object_profile_json["zip"]
151
+ end
152
+ else
153
+ file_size_string = 'multi-file ZIP'
154
+ end
155
+ file_size_string
156
+ end
157
+
158
+ # create a composite object_profile_json object from multiple file objects
159
+ # used to display size of ZIP archive
160
+ def setup_zip_object_profile(image_files_hash, datastream_id)
161
+ datastream_id_to_use = datastream_id == 'accessFull' ? 'productionMaster' : datastream_id
162
+ object_profile = {zip: true,
163
+ objLabel: datastream_id == 'productionMaster' ? '.TIF' : '.JPEG',
164
+ datastreams: {datastream_id_to_use.to_sym => {}}}
165
+ zip_size = 0
166
+ image_files_hash.each do |image_file|
167
+ img_object_profile_json = JSON.parse(image_file['object_profile_ssm'].first)
168
+ zip_size += img_object_profile_json["datastreams"][datastream_id_to_use]["dsSize"]
169
+ end
170
+ # estimate compression, pretty rough
171
+ zip_size = case datastream_id
172
+ when 'productionMaster'
173
+ zip_size * 0.798
174
+ when 'accessFull'
175
+ zip_size * 0.839
176
+ else
177
+ zip_size * 0.927
178
+ end
179
+ object_profile[:datastreams][datastream_id_to_use.to_sym][:dsSize] = zip_size
180
+ object_profile.deep_stringify_keys
181
+ end
182
+
183
+ def url_for_download(document, datastream_id)
184
+ if document[:identifier_ia_id_ssi] && datastream_id == 'JPEG2000'
185
+ "https://archive.org/download/#{document[:identifier_ia_id_ssi]}/#{document[:identifier_ia_id_ssi]}_jp2.zip"
186
+ else
187
+ trigger_downloads_path(document.id, datastream_id: datastream_id)
188
+ end
189
+ end
190
+
191
+ end
192
+ end