-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6335 from samvera/valk-location
Fix based_near/Location for resource models
- Loading branch information
Showing
10 changed files
with
143 additions
and
8 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
module Hyrax | ||
module BasicMetadataFormFieldsBehavior | ||
# Provides compatibility with the behavior of the based_near (location) controlled vocabulary form field. | ||
# The form expects a ControlledVocabularies::Location object as input and produces a hash like those | ||
# used with accepts_nested_attributes_for. | ||
def self.included(descendant) | ||
descendant.property :based_near_attributes, virtual: true, populator: :based_near_populator, prepopulator: :based_near_prepopulator | ||
end | ||
|
||
private | ||
|
||
def based_near_populator(fragment:, **_options) | ||
adds = [] | ||
deletes = [] | ||
fragment.each do |_, h| | ||
uri = RDF::URI.parse(h["id"]).to_s | ||
if h["_destroy"] == "true" | ||
deletes << uri | ||
else | ||
adds << uri | ||
end | ||
end | ||
self.based_near = ((model.based_near + adds) - deletes).uniq | ||
end | ||
|
||
def based_near_prepopulator | ||
self.based_near = based_near.map do |loc| | ||
uri = RDF::URI.parse(loc) | ||
if uri | ||
Hyrax::ControlledVocabularies::Location.new(uri) | ||
else | ||
loc | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
## | ||
# Indexes properties common to Hyrax::Resource types | ||
module LocationIndexer | ||
def to_solr | ||
super.tap do |index_document| | ||
index_document[:based_near_label_tesim] = based_near_label_lookup(resource.based_near) if resource.respond_to? :based_near | ||
end | ||
end | ||
|
||
private | ||
|
||
def based_near_label_lookup(locations) | ||
locations.map do |loc| | ||
if URI.parse(loc) | ||
location_service.full_label(loc) | ||
else | ||
loc | ||
end | ||
end | ||
end | ||
|
||
def location_service | ||
Hyrax.config.location_service | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters