geoblacklight_sidecar_images 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rubocop.yml +80 -0
- data/.travis.yml +29 -0
- data/Gemfile +47 -0
- data/LICENSE +201 -0
- data/README.md +45 -0
- data/Rakefile +37 -0
- data/app/assets/config/geoblacklight_sidecar_images_manifest.js +2 -0
- data/app/assets/images/geoblacklight_sidecar_images/.keep +0 -0
- data/app/assets/javascripts/geoblacklight_sidecar_images/application.js +13 -0
- data/app/assets/stylesheets/geoblacklight_sidecar_images/application.css +15 -0
- data/app/controllers/geoblacklight_sidecar_images/application_controller.rb +5 -0
- data/app/helpers/geoblacklight_sidecar_images/application_helper.rb +4 -0
- data/app/jobs/geoblacklight_sidecar_images/application_job.rb +4 -0
- data/app/mailers/geoblacklight_sidecar_images/application_mailer.rb +6 -0
- data/app/models/geoblacklight_sidecar_images/application_record.rb +5 -0
- data/app/views/layouts/geoblacklight_sidecar_images/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20180118203155_create_solr_document_sidecars.rb +12 -0
- data/geoblacklight_sidecar_images.gemspec +37 -0
- data/lib/generators/geoblacklight_sidecar_images/assets_generator.rb +31 -0
- data/lib/generators/geoblacklight_sidecar_images/example_docs_generator.rb +18 -0
- data/lib/generators/geoblacklight_sidecar_images/install_generator.rb +58 -0
- data/lib/generators/geoblacklight_sidecar_images/jobs_generator.rb +27 -0
- data/lib/generators/geoblacklight_sidecar_images/models_generator.rb +60 -0
- data/lib/generators/geoblacklight_sidecar_images/services_generator.rb +19 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-image.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-line.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-mixed.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-multipoint.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-paper-map.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-point.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-polygon.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/images/thumbnail-raster.png +0 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/javascripts/geoblacklight.js +9 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/assets/stylesheets/geoblacklight.scss +3 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/jobs/store_image_job.rb +8 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/models/concerns/wms_rewrite_concern.rb +20 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/models/solr_document_sidecar.rb +16 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service.rb +193 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/dynamic_map_layer.rb +11 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/iiif.rb +13 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/image_map_layer.rb +13 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/tiled_map_layer.rb +11 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/wms.rb +24 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/uploaders/image_uploader.rb +53 -0
- data/lib/generators/geoblacklight_sidecar_images/templates/views/catalog/_index_split_default.html.erb +27 -0
- data/lib/generators/geoblacklight_sidecar_images/uploaders_generator.rb +19 -0
- data/lib/generators/geoblacklight_sidecar_images/views_generator.rb +21 -0
- data/lib/geoblacklight_sidecar_images.rb +5 -0
- data/lib/geoblacklight_sidecar_images/engine.rb +5 -0
- data/lib/geoblacklight_sidecar_images/version.rb +3 -0
- data/lib/tasks/geoblacklight_sidecar_images_tasks.rake +76 -0
- data/solr/conf/_rest_managed.json +3 -0
- data/solr/conf/admin-extra.html +31 -0
- data/solr/conf/elevate.xml +36 -0
- data/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/conf/protwords.txt +21 -0
- data/solr/conf/schema.xml +190 -0
- data/solr/conf/scripts.conf +24 -0
- data/solr/conf/solrconfig.xml +243 -0
- data/solr/conf/spellings.txt +2 -0
- data/solr/conf/stopwords.txt +58 -0
- data/solr/conf/stopwords_en.txt +58 -0
- data/solr/conf/synonyms.txt +31 -0
- data/solr/conf/xslt/example.xsl +132 -0
- data/solr/conf/xslt/example_atom.xsl +67 -0
- data/solr/conf/xslt/example_rss.xsl +66 -0
- data/solr/conf/xslt/luke.xsl +337 -0
- data/spec/fixtures/files/actual-papermap1.json +23 -0
- data/spec/fixtures/files/actual-point1.json +24 -0
- data/spec/fixtures/files/actual-polygon1.json +23 -0
- data/spec/fixtures/files/actual-raster1.json +37 -0
- data/spec/fixtures/files/baruch_ancestor1.json +46 -0
- data/spec/fixtures/files/baruch_ancestor2.json +46 -0
- data/spec/fixtures/files/baruch_documentation_download.json +49 -0
- data/spec/fixtures/files/esri-dynamic-layer-all-layers.json +36 -0
- data/spec/fixtures/files/esri-dynamic-layer-single-layer.json +37 -0
- data/spec/fixtures/files/esri-feature-layer.json +33 -0
- data/spec/fixtures/files/esri-image-map-layer.json +21 -0
- data/spec/fixtures/files/esri-tiled_map_layer.json +22 -0
- data/spec/fixtures/files/esri-wms-layer.json +33 -0
- data/spec/fixtures/files/harvard_raster.json +44 -0
- data/spec/fixtures/files/no_spatial.json +21 -0
- data/spec/fixtures/files/public_direct_download.json +28 -0
- data/spec/fixtures/files/public_iiif_princeton.json +36 -0
- data/spec/fixtures/files/public_polygon_mit.json +39 -0
- data/spec/fixtures/files/restricted-line.json +36 -0
- data/spec/fixtures/files/umich_iiif_jpg.json +28 -0
- data/spec/fixtures/files/umn_iiif_jpg.json +30 -0
- data/spec/fixtures/files/umn_metro_result1.json +37 -0
- data/spec/fixtures/files/umn_metro_result2.json +35 -0
- data/spec/fixtures/files/umn_state_result1.json +31 -0
- data/spec/fixtures/files/umn_state_result2.json +36 -0
- data/spec/models/solr_document_sidecar_spec.rb +13 -0
- data/spec/models/solr_document_spec.rb +14 -0
- data/spec/rails_helper.rb +59 -0
- data/spec/services/image_service_spec.rb +31 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +33 -0
- data/template.rb +13 -0
- metadata +395 -0
@@ -0,0 +1,193 @@
|
|
1
|
+
require 'rack/mime'
|
2
|
+
|
3
|
+
class ImageService
|
4
|
+
def initialize(document)
|
5
|
+
@document = document
|
6
|
+
@logger ||= ActiveSupport::TaggedLogging.new(
|
7
|
+
Logger.new(
|
8
|
+
File.join(
|
9
|
+
Rails.root, '/log/', "image_service_#{Rails.env}.log"
|
10
|
+
)
|
11
|
+
)
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Stores the document's image in SolrDocumentSidecar
|
16
|
+
# using Carrierwave
|
17
|
+
# @return [Boolean]
|
18
|
+
#
|
19
|
+
# @TODO: EWL
|
20
|
+
def store
|
21
|
+
sidecar = @document.sidecar
|
22
|
+
sidecar.image = image_tempfile(@document.id)
|
23
|
+
sidecar.save!
|
24
|
+
@logger.tagged(@document.id, 'STATUS') { @logger.info 'SUCCESS' }
|
25
|
+
@logger.tagged(@document.id, 'SIDECAR_IMAGE_URL') { @logger.info @document.sidecar.image_url }
|
26
|
+
rescue ActiveRecord::RecordInvalid, FloatDomainError => invalid
|
27
|
+
@logger.tagged(@document.id, 'STATUS') { @logger.info 'FAILURE' }
|
28
|
+
@logger.tagged(@document.id, 'EXCEPTION') { @logger.info invalid.inspect }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns hash containing placeholder thumbnail for the document.
|
32
|
+
# @return [Hash]
|
33
|
+
# * :type [String] image mime type
|
34
|
+
# * :data [String] image file data
|
35
|
+
def placeholder
|
36
|
+
placeholder_data
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def image_tempfile(document_id)
|
42
|
+
@logger.tagged(@document.id, 'remote_content_type') { @logger.info remote_content_type }
|
43
|
+
@logger.tagged(@document.id, 'viewer_protocol') { @logger.info @document.viewer_protocol }
|
44
|
+
@logger.tagged(@document.id, 'service_url') { @logger.info service_url }
|
45
|
+
@logger.tagged(@document.id, 'image_extension') { @logger.info image_extension }
|
46
|
+
|
47
|
+
file = Tempfile.new([document_id, image_extension])
|
48
|
+
file.binmode
|
49
|
+
file.write(image_data[:data])
|
50
|
+
file.close
|
51
|
+
|
52
|
+
@logger.tagged(@document.id, 'IMAGE_TEMPFILE') { @logger.info file.inspect }
|
53
|
+
|
54
|
+
file
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns geoserver auth credentials if the document is a restriced Local WMS layer.
|
58
|
+
def geoserver_credentials
|
59
|
+
return unless restricted_wms_layer?
|
60
|
+
Settings.PROXY_GEOSERVER_AUTH.gsub('Basic ', '')
|
61
|
+
end
|
62
|
+
|
63
|
+
# Tests if geoserver credentials are set beyond the default.
|
64
|
+
def geoserver_credentials_valid?
|
65
|
+
Settings.PROXY_GEOSERVER_AUTH != 'Basic base64encodedusername:password'
|
66
|
+
end
|
67
|
+
|
68
|
+
def placeholder_base_path
|
69
|
+
Rails.root.join('app', 'assets', 'images')
|
70
|
+
end
|
71
|
+
|
72
|
+
# Generates hash containing placeholder mime_type and image.
|
73
|
+
def placeholder_data
|
74
|
+
{ type: 'image/png', data: placeholder_image }
|
75
|
+
end
|
76
|
+
|
77
|
+
# Gets placeholder image from disk.
|
78
|
+
def placeholder_image
|
79
|
+
File.read(placeholder_image_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
# Path to placeholder image based on the layer geometry.
|
83
|
+
def placeholder_image_path
|
84
|
+
geom_type = @document.fetch('layer_geom_type_s', '').tr(' ', '-').downcase
|
85
|
+
thumb_path = "#{placeholder_base_path}/thumbnail-#{geom_type}.png"
|
86
|
+
return "#{placeholder_base_path}/thumbnail-paper-map.png" unless File.exist?(thumb_path)
|
87
|
+
thumb_path
|
88
|
+
end
|
89
|
+
|
90
|
+
# Generates hash containing thumbnail mime_type and image.
|
91
|
+
def image_data
|
92
|
+
return placeholder_data unless image_url
|
93
|
+
{ type: remote_content_type, data: remote_image }
|
94
|
+
end
|
95
|
+
|
96
|
+
# Gets thumbnail image from URL. On error, returns document's placeholder image.
|
97
|
+
def remote_content_type
|
98
|
+
auth = geoserver_credentials
|
99
|
+
|
100
|
+
conn = Faraday.new(url: image_url) do |b|
|
101
|
+
b.use FaradayMiddleware::FollowRedirects
|
102
|
+
b.adapter :net_http
|
103
|
+
end
|
104
|
+
|
105
|
+
conn.options.timeout = timeout
|
106
|
+
conn.options.timeout = timeout
|
107
|
+
conn.authorization :Basic, auth if auth
|
108
|
+
|
109
|
+
conn.head.headers['content-type']
|
110
|
+
rescue Faraday::Error::ConnectionFailed
|
111
|
+
placeholder_data[:type]
|
112
|
+
rescue Faraday::Error::TimeoutError
|
113
|
+
placeholder_data[:type]
|
114
|
+
end
|
115
|
+
|
116
|
+
# Gets thumbnail image from URL. On error, returns document's placeholder image.
|
117
|
+
def remote_image
|
118
|
+
auth = geoserver_credentials
|
119
|
+
conn = Faraday.new(url: image_url)
|
120
|
+
conn.options.timeout = timeout
|
121
|
+
conn.options.timeout = timeout
|
122
|
+
conn.authorization :Basic, auth if auth
|
123
|
+
|
124
|
+
conn.get.body
|
125
|
+
rescue Faraday::Error::ConnectionFailed
|
126
|
+
placeholder_image
|
127
|
+
rescue Faraday::Error::TimeoutError
|
128
|
+
placeholder_image
|
129
|
+
end
|
130
|
+
|
131
|
+
# Returns the thumbnail url.
|
132
|
+
# If the layer is restriced Local WMS, and the geoserver credentials
|
133
|
+
# have not been set beyond the default, then a thumbnail url from
|
134
|
+
# dct references is used instead.
|
135
|
+
def image_url
|
136
|
+
@image_url ||= begin
|
137
|
+
if restricted_scanned_map?
|
138
|
+
image_reference
|
139
|
+
elsif restricted_wms_layer? && !geoserver_credentials_valid?
|
140
|
+
image_reference
|
141
|
+
else
|
142
|
+
service_url || image_reference
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Determines the image file extension
|
148
|
+
def image_extension
|
149
|
+
@image_extension ||= Rack::Mime::MIME_TYPES.rassoc(remote_content_type).try(:first) || '.png'
|
150
|
+
end
|
151
|
+
|
152
|
+
# Checks if the document is Local restriced access and is a scanned map.
|
153
|
+
def restricted_scanned_map?
|
154
|
+
@document.local_restricted? && @document['layer_geom_type_s'] == 'Image'
|
155
|
+
end
|
156
|
+
|
157
|
+
# Checks if the document is Local restriced access and is a wms layer.
|
158
|
+
def restricted_wms_layer?
|
159
|
+
@document.local_restricted? && @document.viewer_protocol == 'wms'
|
160
|
+
end
|
161
|
+
|
162
|
+
# Gets the url for a specific service endpoint if the item is
|
163
|
+
# public, has the same institution as the GBL instance, and the viewer
|
164
|
+
# protocol is not 'map' or nil. A module name is then dynamically generated
|
165
|
+
# from the viewer protocol, and if it's loaded, the image_url
|
166
|
+
# method is called.
|
167
|
+
def service_url
|
168
|
+
@service_url ||= begin
|
169
|
+
return unless @document.available?
|
170
|
+
protocol = @document.viewer_protocol
|
171
|
+
return if protocol == 'map' || protocol.nil?
|
172
|
+
"ImageService::#{protocol.camelcase}".constantize.image_url(@document, image_size)
|
173
|
+
rescue NameError
|
174
|
+
return nil
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Retreives a url to a static thumbnail from the document's dct_references field, if it exists.
|
179
|
+
def image_reference
|
180
|
+
return nil if @document[@document.references.reference_field].nil?
|
181
|
+
JSON.parse(@document[@document.references.reference_field])['http://schema.org/thumbnailUrl']
|
182
|
+
end
|
183
|
+
|
184
|
+
# Default thumbnail size.
|
185
|
+
def image_size
|
186
|
+
300
|
187
|
+
end
|
188
|
+
|
189
|
+
# Faraday timeout value.
|
190
|
+
def timeout
|
191
|
+
30
|
192
|
+
end
|
193
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ImageService
|
2
|
+
module DynamicMapLayer
|
3
|
+
##
|
4
|
+
# Formats and returns a thumbnail url from an ESRI Dynamic Map Layer endpoint.
|
5
|
+
# @param [SolrDocument]
|
6
|
+
# @return [String] image url
|
7
|
+
def self.image_url(document, _size)
|
8
|
+
"#{document.viewer_endpoint}/info/thumbnail/thumbnail.png"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ImageService
|
2
|
+
module Iiif
|
3
|
+
##
|
4
|
+
# Formats and returns a thumbnail url from an International Image
|
5
|
+
# Interoperability Framework endpoint.
|
6
|
+
# @param [SolrDocument]
|
7
|
+
# @param [Integer] thumbnail size
|
8
|
+
# @return [String] iiif thumbnail url
|
9
|
+
def self.image_url(document, size)
|
10
|
+
"#{document.viewer_endpoint.gsub('info.json', '')}full/#{size},/0/default.jpg"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/image_map_layer.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class ImageService
|
2
|
+
module ImageMapLayer
|
3
|
+
##
|
4
|
+
# Formats and returns a thumbnail url from an ESRI Image Map Layer endpoint.
|
5
|
+
# information about the layer.
|
6
|
+
# @param [SolrDocument]
|
7
|
+
# @param [Integer] thumbnail size
|
8
|
+
# @return [String] thumbnail url
|
9
|
+
def self.image_url(document, _size)
|
10
|
+
"#{document.viewer_endpoint}/info/thumbnail/thumbnail.png"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/generators/geoblacklight_sidecar_images/templates/services/image_service/tiled_map_layer.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class ImageService
|
2
|
+
module TiledMapLayer
|
3
|
+
##
|
4
|
+
# Formats and returns an image url from an ESRI Tiled Map Layer endpoint.
|
5
|
+
# @param [SolrDocument]
|
6
|
+
# @return [String] image url
|
7
|
+
def self.image_url(document, _size)
|
8
|
+
"#{document.viewer_endpoint}/info/thumbnail/thumbnail.png"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class ImageService
|
2
|
+
module Wms
|
3
|
+
##
|
4
|
+
# Formats and returns a thumbnail url from a Web Map Service endpoint.
|
5
|
+
# This utilizes the GeoServer specific 'reflect' service to generate
|
6
|
+
# parameters like bbox that are difficult to tweak without more detailed
|
7
|
+
# information about the layer.
|
8
|
+
# @param [SolrDocument]
|
9
|
+
# @param [Integer] thumbnail size
|
10
|
+
# @return [String] wms thumbnail url
|
11
|
+
def self.image_url(document, size)
|
12
|
+
# Swap proxy url with princeton geoserver url.
|
13
|
+
# Thumbnail requests send geoserver auth.
|
14
|
+
endpoint = document.viewer_endpoint.gsub(Settings.PROXY_GEOSERVER_URL,
|
15
|
+
Settings.INSTITUTION_GEOSERVER_URL)
|
16
|
+
"#{endpoint}/reflect?" \
|
17
|
+
'&FORMAT=image%2Fpng' \
|
18
|
+
'&TRANSPARENT=TRUE' \
|
19
|
+
"&LAYERS=#{document['layer_id_s']}" \
|
20
|
+
"&WIDTH=#{size}" \
|
21
|
+
"&HEIGHT=#{size}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
2
|
+
# Include RMagick or MiniMagick support:
|
3
|
+
# include CarrierWave::RMagick
|
4
|
+
include CarrierWave::MiniMagick
|
5
|
+
|
6
|
+
# Choose what kind of storage to use for this uploader:
|
7
|
+
storage :file
|
8
|
+
# storage :fog
|
9
|
+
|
10
|
+
# Override the directory where uploaded files will be stored.
|
11
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
12
|
+
def store_dir
|
13
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
17
|
+
# def default_url(*args)
|
18
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
19
|
+
# # ActionController::Base.helpers.asset_path(
|
20
|
+
# "fallback/" + [version_name, "default.png"].compact.join('_')
|
21
|
+
# # )
|
22
|
+
#
|
23
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Process files as they are uploaded:
|
27
|
+
# process scale: [200, 300]
|
28
|
+
#
|
29
|
+
# def scale(width, height)
|
30
|
+
# # do something
|
31
|
+
# end
|
32
|
+
|
33
|
+
# Create different versions of your uploaded files:
|
34
|
+
version :thumb do
|
35
|
+
process resize_to_fill: [300, 300]
|
36
|
+
end
|
37
|
+
|
38
|
+
version :square, from_version: :thumb do
|
39
|
+
process resize_to_fill: [100, 100]
|
40
|
+
end
|
41
|
+
|
42
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
43
|
+
# For images you might use something like this:
|
44
|
+
def extension_whitelist
|
45
|
+
%w[jpg jpeg gif png]
|
46
|
+
end
|
47
|
+
|
48
|
+
# Override the filename of the uploaded files:
|
49
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
50
|
+
# def filename
|
51
|
+
# "something.jpg" if original_filename
|
52
|
+
# end
|
53
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<% # header bar for doc items in index view -%>
|
2
|
+
<%= content_tag :div, class: 'documentHeader row', data: { layer_id: document.id, bbox: document.bounding_box_as_wsen } do %>
|
3
|
+
<div class='more-info-area-split'>
|
4
|
+
<div class='status-icons'>
|
5
|
+
<%= render partial: 'header_icons', locals: { document: document } %>
|
6
|
+
</div>
|
7
|
+
<div class="thumbnail">
|
8
|
+
<img src="<%=document.sidecar.image_url%>"/>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
<div class="document-wrapper">
|
12
|
+
<h3 class="index_title col-sm-9s cosl-lg-10 text-span">
|
13
|
+
<% counter = document_counter_with_offset(document_counter) %>
|
14
|
+
<span class="document-counter">
|
15
|
+
<%= t('blacklight.search.documents.counter', :counter => counter) if counter %>
|
16
|
+
</span>
|
17
|
+
<%= link_to_document document, document_show_link_field(document), counter: counter, title: document[blacklight_config.index.title_field] %>
|
18
|
+
</h3>
|
19
|
+
<div class='col-xs-12'>
|
20
|
+
<div>
|
21
|
+
<small>
|
22
|
+
<%= geoblacklight_present(:index_fields_display, document) %>
|
23
|
+
</small>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module GeoblacklightSidecarImages
|
6
|
+
class UploadersGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
desc <<-DESCRIPTION
|
10
|
+
This generator makes the following changes to your application:
|
11
|
+
1. Creates an app/uploaders directory
|
12
|
+
2. Creates uploader models within the app/uploaders directory
|
13
|
+
DESCRIPTION
|
14
|
+
|
15
|
+
def create_image_uploader
|
16
|
+
directory 'uploaders', 'app/uploaders'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails/generators'
|
4
|
+
|
5
|
+
module GeoblacklightSidecarImages
|
6
|
+
class ViewsGenerator < Rails::Generators::Base
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
desc <<-DESCRIPTION
|
10
|
+
This generator makes the following changes to your application:
|
11
|
+
1. Creates an app/views/catalog directory
|
12
|
+
DESCRIPTION
|
13
|
+
|
14
|
+
def create_views
|
15
|
+
copy_file(
|
16
|
+
'views/catalog/_index_split_default.html.erb',
|
17
|
+
'app/views/catalog/_index_split_default.html.erb'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
namespace :geoblacklight_sidecar_images do
|
2
|
+
namespace :sample_data do
|
3
|
+
desc 'Ingests a directory of geoblacklight.json files'
|
4
|
+
task :ingest, [:directory] => :environment do |_t, args|
|
5
|
+
args.with_defaults(directory: 'data')
|
6
|
+
Dir.glob(File.join(args[:directory], '**', '*.json')).each do |fn|
|
7
|
+
puts "Ingesting #{fn}"
|
8
|
+
begin
|
9
|
+
Blacklight.default_index.connection.add(JSON.parse(File.read(fn)))
|
10
|
+
rescue => e
|
11
|
+
puts "Failed to ingest #{fn}: #{e.inspect}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
puts 'Committing changes to Solr'
|
15
|
+
Blacklight.default_index.connection.commit
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
namespace :images do
|
20
|
+
desc 'Pre-cache specific image'
|
21
|
+
task :precache_id, [:doc_id] => [:environment] do |_t, args|
|
22
|
+
query = "dc_identifier_s:#{args[:doc_id]}"
|
23
|
+
layers = %w[
|
24
|
+
layer_slug_s
|
25
|
+
layer_id_s
|
26
|
+
dc_rights_s
|
27
|
+
dct_provenance_s
|
28
|
+
layer_geom_type_s
|
29
|
+
dct_references_s
|
30
|
+
]
|
31
|
+
index = Geoblacklight::SolrDocument.index
|
32
|
+
results = index.send_and_receive(index.blacklight_config.solr_path,
|
33
|
+
q: query,
|
34
|
+
fl: layers.join(','),
|
35
|
+
rows: 100_000_000)
|
36
|
+
num_found = results.response[:numFound]
|
37
|
+
doc_counter = 0
|
38
|
+
results.docs.each do |document|
|
39
|
+
begin
|
40
|
+
StoreImageJob.perform_later(document.to_h)
|
41
|
+
rescue Blacklight::Exceptions::RecordNotFound
|
42
|
+
next
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'Pre-cache all images'
|
48
|
+
task :precache_all, [:override_existing] => [:environment] do |_t, args|
|
49
|
+
begin
|
50
|
+
query = 'layer_slug_s:*'
|
51
|
+
layers = %w[
|
52
|
+
layer_slug_s
|
53
|
+
layer_id_s
|
54
|
+
dc_rights_s
|
55
|
+
dct_provenance_s
|
56
|
+
layer_geom_type_s
|
57
|
+
dct_references_s
|
58
|
+
]
|
59
|
+
index = Geoblacklight::SolrDocument.index
|
60
|
+
results = index.send_and_receive(index.blacklight_config.solr_path,
|
61
|
+
q: query,
|
62
|
+
fl: layers.join(','),
|
63
|
+
rows: 100_000_000)
|
64
|
+
num_found = results.response[:numFound]
|
65
|
+
doc_counter = 0
|
66
|
+
results.docs.each do |document|
|
67
|
+
begin
|
68
|
+
StoreImageJob.perform_later(document.to_h)
|
69
|
+
rescue Blacklight::Exceptions::RecordNotFound
|
70
|
+
next
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|