Skip to content

Commit

Permalink
Update hyrax, fix institutional repository layout & based_near behavi…
Browse files Browse the repository at this point in the history
…or (#2361)

* Fixes institional repository layout on main page

Removes duplication of application name when there is no logo.
Repositions application name to be centered between logo and search bar.

Fixes #2356

* Updates Hyrax to bring in based_near indexer fix

* Includes based_near_form_fields_behavior

When basic_metadata isn't part of the schema, the based_near
prepopulators don't get included via form_fields.rb.

This is including them explicitly to avoidbroken based_near
behaviors in the forms.

* One more hyrax update
  • Loading branch information
laritakr authored Oct 17, 2024
1 parent 335eea4 commit 6931967
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ GIT

GIT
remote: https://github.com/samvera/hyrax.git
revision: ce352d3d10390f0032fa131010ab9d76759faddd
revision: 4f0ba25bc0149472f6dd1df2574bc3a3fe7709e8
branch: main
specs:
hyrax (5.0.1)
Expand Down
3 changes: 0 additions & 3 deletions app/assets/stylesheets/themes/institutional_repository.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
// styles the top nav menu application name that is centered
.institutional-repository-application-name {
text-align: center;
position: absolute;
left: 50%;
transform: translateX(-50%);

span {
color: #fff;
Expand Down
41 changes: 41 additions & 0 deletions app/forms/based_near_form_fields_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

# A duplication of Hyrax's BasicMetadataFormFieldsBehavior which gets dynamically included via lib/hyrax/form_fields.rb
# When :basic_metadata is not part of a resource's schema, and the resource includes basec_near, this module
# must be explicitly included in the resources form.
module BasedNearFormFieldsBehavior
# 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
based_near << Hyrax::ControlledVocabularies::Location.new if based_near.empty?
end
end
6 changes: 5 additions & 1 deletion app/forms/etd_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms
# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking
class EtdResourceForm < Hyrax::Forms::ResourceForm(EtdResource)
# Commented out basic_metadata because these terms were added to etd_resource so we can customize it.
# Commented out basic_metadata because the terms were added to the resource's yaml
# so we can customize it
# include Hyrax::FormFields(:basic_metadata)
include Hyrax::FormFields(:bulkrax_metadata)
include Hyrax::FormFields(:etd_resource)
include Hyrax::FormFields(:with_pdf_viewer)
include Hyrax::FormFields(:with_video_embed)
include VideoEmbedBehavior::Validation
# this duplicates Hyrax::BasicMetadataFormFieldsBehavior behavior which previously
# came in dynamically via lib/hyrax/form_fields.rb
include BasedNearFormFieldsBehavior
# Define custom form fields using the Valkyrie::ChangeSet interface
#
# property :my_custom_form_field
Expand Down
6 changes: 5 additions & 1 deletion app/forms/oer_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
# @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms
# @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking
class OerResourceForm < Hyrax::Forms::ResourceForm(OerResource)
# Commented out basic_metadata because these terms were added to etd_resource so we can customize it.
# Commented out basic_metadata because the terms were added to the resource's yaml
# so we can customize it
# include Hyrax::FormFields(:basic_metadata)
include Hyrax::FormFields(:bulkrax_metadata)
include Hyrax::FormFields(:oer_resource)
include Hyrax::FormFields(:with_pdf_viewer)
include Hyrax::FormFields(:with_video_embed)
include VideoEmbedBehavior::Validation
# this duplicates Hyrax::BasicMetadataFormFieldsBehavior behavior which previously
# came in dynamically via lib/hyrax/form_fields.rb
include BasedNearFormFieldsBehavior
# Define custom form fields using the Valkyrie::ChangeSet interface
#
# property :my_custom_form_field
Expand Down
4 changes: 0 additions & 4 deletions app/views/themes/institutional_repository/_logo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
<a id="logo" class="col-sm-5" href="<%= hyrax.root_path %>" data-no-turbolink="true">
<%= image_tag logo_image, alt: block_for(name: 'logo_image_text') %>
</a>
<% else %>
<a id="logo" class="col-sm-5 navbar-brand" href="<%= hyrax.root_path %>" data-no-turbolink="true">
<span class="institution_name"><%= application_name %></span>
</a>
<% end %>
2 changes: 2 additions & 0 deletions config/metadata/oer_resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ attributes:
based_near:
type: string
multiple: true
form:
primary: false
index_keys:
- "based_near_sim"
- "based_near_tesim"
Expand Down

0 comments on commit 6931967

Please sign in to comment.