From 791e78aa90d03de3c181f8fb88072c6b5f1d7d13 Mon Sep 17 00:00:00 2001
From: Jeremy Prevost
Date: Tue, 29 Oct 2024 16:22:54 -0400
Subject: [PATCH 1/7] Holy heck this might work?
---
app/controllers/record_controller.rb | 13 +++++++++++
app/views/record/_record_geo.html.erb | 33 +++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/app/controllers/record_controller.rb b/app/controllers/record_controller.rb
index 9ac8ea3d..2ac5134f 100644
--- a/app/controllers/record_controller.rb
+++ b/app/controllers/record_controller.rb
@@ -16,10 +16,23 @@ def view
# Manipulation of returned record would go here...
@record = response&.data&.to_h&.dig('recordId')
+ @rectangle = bounding_box_to_coords
end
private
+ def bounding_box_to_coords
+ return unless geospatial_coordinates?(@record['locations'])
+
+ raw_bbox = @record['locations'].select { |l| l if l['kind'] == 'Bounding Box' }.first
+ bbox = raw_bbox['geoshape'].sub('BBOX (', '').sub(')', '')
+ bbox_array = bbox.split(', ')
+ coords = [[bbox_array[2].to_f, bbox_array[0].to_f], [bbox_array[3].to_f, bbox_array[1].to_f]]
+ Rails.logger.info("Raw BBox: #{raw_bbox}")
+ Rails.logger.info("Rectangle: #{coords}")
+ coords
+ end
+
def validate_id!
return if params[:id]&.strip.present?
diff --git a/app/views/record/_record_geo.html.erb b/app/views/record/_record_geo.html.erb
index aa247a62..04cf7632 100644
--- a/app/views/record/_record_geo.html.erb
+++ b/app/views/record/_record_geo.html.erb
@@ -79,6 +79,39 @@
<% end %>
<% end %>
+
+ <% content_for :additional_meta_tag do %>
+
+
+
+
+ <% end %>
+
+
+
<% end %>
<% if @record['notes'].present? %>
From 43e14ccd12c25eecf3ba38c9877ef9bcd1d85bbf Mon Sep 17 00:00:00 2001
From: Jeremy Prevost
Date: Wed, 30 Oct 2024 11:03:58 -0400
Subject: [PATCH 2/7] Handle some edge cases
- bbox is sometimes in a different field (ticket opened to understand why)
- bbox sometimes has spaces and sometimes not so we handle both
- convert strings to floats during initial string extraction rather than during coords array creation
- if bbox_array is not 4 elements, don't use it
- if we don't have a record at all, don't try to use it
---
app/controllers/record_controller.rb | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/app/controllers/record_controller.rb b/app/controllers/record_controller.rb
index 2ac5134f..f54baf7e 100644
--- a/app/controllers/record_controller.rb
+++ b/app/controllers/record_controller.rb
@@ -21,13 +21,34 @@ def view
private
+ # Converts a bounding box into a top left, bottom right set of coordinates
def bounding_box_to_coords
+ return unless @record.present?
return unless geospatial_coordinates?(@record['locations'])
+ # Our preference is to use the `Bounding Box` kind
raw_bbox = @record['locations'].select { |l| l if l['kind'] == 'Bounding Box' }.first
+
+ # If we had no `Bounding Box` kind, see if we have a `Geometry kind`
+ if raw_bbox.blank?
+ raw_bbox = @record['locations'].select { |l| l if l['kind'] == 'Geometry' }.first
+ end
+
+ return unless raw_bbox.present?
+
+ # extract just the geo coordinates and remove the extra syntax
bbox = raw_bbox['geoshape'].sub('BBOX (', '').sub(')', '')
- bbox_array = bbox.split(', ')
- coords = [[bbox_array[2].to_f, bbox_array[0].to_f], [bbox_array[3].to_f, bbox_array[1].to_f]]
+
+ # conver the string into an array of floats
+ bbox_array = bbox.split(',').map!(&:strip).map!(&:to_f)
+
+ # Protect against unexpected data
+ if bbox_array.count != 4
+ Rails.logger.info("Unexpected Bounding Box: #{raw_bbox}")
+ return
+ end
+
+ coords = [[bbox_array[2], bbox_array[0]], [bbox_array[3], bbox_array[1]]]
Rails.logger.info("Raw BBox: #{raw_bbox}")
Rails.logger.info("Rectangle: #{coords}")
coords
From f6a5870c66954669209f597063273e6a07b33ccf Mon Sep 17 00:00:00 2001
From: Jeremy Prevost
Date: Wed, 30 Oct 2024 11:19:06 -0400
Subject: [PATCH 3/7] Reorder record view to show map more prominently
---
app/views/record/_record_geo.html.erb | 36 ++++++++++++++-------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/app/views/record/_record_geo.html.erb b/app/views/record/_record_geo.html.erb
index 04cf7632..9c5b239e 100644
--- a/app/views/record/_record_geo.html.erb
+++ b/app/views/record/_record_geo.html.erb
@@ -60,26 +60,9 @@
<% end %>
<% end %>
- <% if @record['subjects'].present? %>
-
Subjects
-
- <% deduplicate_subjects(@record['subjects'])&.each do |subject| %>
-
<%= subject.join('; ') %>
- <% end %>
-
- <% end %>
-
<% if geospatial_coordinates?(@record['locations']) %>
Geospatial coordinates
-
- <% parse_nested_field(@record['locations']).each do |location| %>
- <% if location['geoshape'].present? %>
-
+ <% end %>
+
+ <% if @record['subjects'].present? %>
+
Subjects
+
+ <% deduplicate_subjects(@record['subjects'])&.each do |subject| %>
+
<%= subject.join('; ') %>
+ <% end %>
+
<% end %>
<% if @record['notes'].present? %>
From 399bfcbbea1633ccc310f249d72e4c7edc6f9ef0 Mon Sep 17 00:00:00 2001
From: Jeremy Prevost
Date: Wed, 30 Oct 2024 15:08:35 -0400
Subject: [PATCH 4/7] This needs a refactor. Do not merge.
yes, I know the tests are failing too. It needs cassette regen but wanted to share the idea before tuning it up
---
app/controllers/record_controller.rb | 35 +------------------
app/helpers/record_helper.rb | 33 ++++++++++++++++++
app/models/timdex_search.rb | 20 +++++++++++
app/views/record/_record_geo.html.erb | 1 +
app/views/search/_result_geo.html.erb | 50 +++++++++++++++++++++++++++
5 files changed, 105 insertions(+), 34 deletions(-)
diff --git a/app/controllers/record_controller.rb b/app/controllers/record_controller.rb
index f54baf7e..14e3eecc 100644
--- a/app/controllers/record_controller.rb
+++ b/app/controllers/record_controller.rb
@@ -16,44 +16,11 @@ def view
# Manipulation of returned record would go here...
@record = response&.data&.to_h&.dig('recordId')
- @rectangle = bounding_box_to_coords
+ @rectangle = bounding_box_to_coords(@record)
end
private
- # Converts a bounding box into a top left, bottom right set of coordinates
- def bounding_box_to_coords
- return unless @record.present?
- return unless geospatial_coordinates?(@record['locations'])
-
- # Our preference is to use the `Bounding Box` kind
- raw_bbox = @record['locations'].select { |l| l if l['kind'] == 'Bounding Box' }.first
-
- # If we had no `Bounding Box` kind, see if we have a `Geometry kind`
- if raw_bbox.blank?
- raw_bbox = @record['locations'].select { |l| l if l['kind'] == 'Geometry' }.first
- end
-
- return unless raw_bbox.present?
-
- # extract just the geo coordinates and remove the extra syntax
- bbox = raw_bbox['geoshape'].sub('BBOX (', '').sub(')', '')
-
- # conver the string into an array of floats
- bbox_array = bbox.split(',').map!(&:strip).map!(&:to_f)
-
- # Protect against unexpected data
- if bbox_array.count != 4
- Rails.logger.info("Unexpected Bounding Box: #{raw_bbox}")
- return
- end
-
- coords = [[bbox_array[2], bbox_array[0]], [bbox_array[3], bbox_array[1]]]
- Rails.logger.info("Raw BBox: #{raw_bbox}")
- Rails.logger.info("Rectangle: #{coords}")
- coords
- end
-
def validate_id!
return if params[:id]&.strip.present?
diff --git a/app/helpers/record_helper.rb b/app/helpers/record_helper.rb
index 142ef5d6..2a86b92b 100644
--- a/app/helpers/record_helper.rb
+++ b/app/helpers/record_helper.rb
@@ -146,6 +146,39 @@ def deduplicate_subjects(subjects)
subjects.map { |subject| subject['value'].uniq(&:downcase) }.uniq { |values| values.map(&:downcase) }
end
+ # Converts a bounding box into a top left, bottom right set of coordinates
+ def bounding_box_to_coords(record)
+ return unless record.present?
+ return unless geospatial_coordinates?(record['locations'])
+
+ # Our preference is to use the `Bounding Box` kind
+ raw_bbox = record['locations'].select { |l| l if l['kind'] == 'Bounding Box' }.first
+
+ # If we had no `Bounding Box` kind, see if we have a `Geometry kind`
+ if raw_bbox.blank?
+ raw_bbox = record['locations'].select { |l| l if l['kind'] == 'Geometry' }.first
+ end
+
+ return unless raw_bbox.present?
+
+ # extract just the geo coordinates and remove the extra syntax
+ bbox = raw_bbox['geoshape'].sub('BBOX (', '').sub(')', '')
+
+ # conver the string into an array of floats
+ bbox_array = bbox.split(',').map!(&:strip).map!(&:to_f)
+
+ # Protect against unexpected data
+ if bbox_array.count != 4
+ Rails.logger.info("Unexpected Bounding Box: #{raw_bbox}")
+ return
+ end
+
+ coords = [[bbox_array[2], bbox_array[0]], [bbox_array[3], bbox_array[1]]]
+ Rails.logger.info("Raw BBox: #{raw_bbox}")
+ Rails.logger.info("Rectangle: #{coords}")
+ coords
+ end
+
private
def render_kind_value(list)
diff --git a/app/models/timdex_search.rb b/app/models/timdex_search.rb
index c2dd9ee5..5520098a 100644
--- a/app/models/timdex_search.rb
+++ b/app/models/timdex_search.rb
@@ -67,6 +67,11 @@ class TimdexSearch < TimdexBase
text
url
}
+ locations {
+ geoshape
+ kind
+ value
+ }
notes {
kind
value
@@ -199,6 +204,11 @@ class TimdexSearch < TimdexBase
text
url
}
+ locations {
+ geoshape
+ kind
+ value
+ }
notes {
kind
value
@@ -325,6 +335,11 @@ class TimdexSearch < TimdexBase
text
url
}
+ locations {
+ geoshape
+ kind
+ value
+ }
notes {
kind
value
@@ -461,6 +476,11 @@ class TimdexSearch < TimdexBase
text
url
}
+ locations {
+ geoshape
+ kind
+ value
+ }
notes {
kind
value
diff --git a/app/views/record/_record_geo.html.erb b/app/views/record/_record_geo.html.erb
index 9c5b239e..f52ec753 100644
--- a/app/views/record/_record_geo.html.erb
+++ b/app/views/record/_record_geo.html.erb
@@ -77,6 +77,7 @@
+ <% end %>
+
style="height: 180px">
+
+
+
+
+
+ <% parse_nested_field(result_geo['locations']).each do |location| %>
+ <% if location['geoshape'].present? %>
+