-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Favor overriding CollectionsController
This commit will allow us to override the CollectionsController instead of the Blacklight::ConfigurationHelperBehavior. A bug was noticed when switching the sort fields that the field selected wouldn't stick in the UI even though the fields were actually sorting correctly. Overriding the CollectionsController will be a better pattern since we override the WorksController in the same way. The reason why we didn't do that in the first place was because it caused the show page to have the same sort fields as the index page. In this commit, we are also modifying the show page to reconfigure the sort fields to address the issue. Ref: - #748
- Loading branch information
Showing
5 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
app/controllers/hyrax/my/collections_controller_decorator.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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hyrax | ||
module My | ||
module CollectionsControllerDecorator | ||
def configure_facets | ||
configure_blacklight do |config| | ||
# clear facets copied from the CatalogController | ||
config.sort_fields.clear | ||
# Collections don't seem to have a date_uploaded_dtsi nor date_modified_dtsi | ||
# we can at least use the system_modified_dtsi instead of date_modified_dtsi | ||
# but we will omit date_uploaded_dtsi | ||
config.add_sort_field "system_modified_dtsi desc", label: "date modified \u25BC" | ||
config.add_sort_field "system_modified_dtsi asc", label: "date modified \u25B2" | ||
config.add_sort_field "system_create_dtsi desc", label: "date created \u25BC" | ||
config.add_sort_field "system_create_dtsi asc", label: "date created \u25B2" | ||
config.add_sort_field "depositor_ssi asc, title_ssi asc", label: "depositor (A-Z)" | ||
config.add_sort_field "depositor_ssi desc, title_ssi desc", label: "depositor (Z-A)" | ||
config.add_sort_field "creator_ssi asc, title_ssi asc", label: "creator (A-Z)" | ||
config.add_sort_field "creator_ssi desc, title_ssi desc", label: "creator (Z-A)" | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Hyrax::My::CollectionsController.singleton_class.send(:prepend, Hyrax::My::CollectionsControllerDecorator) | ||
Hyrax::My::CollectionsController.configure_facets |
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
52 changes: 0 additions & 52 deletions
52
app/helpers/blacklight/configuration_helper_behavior_decorator.rb
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Hyrax::My::CollectionsController, type: :controller do | ||
describe "#configure_facets" do | ||
subject { controller.blacklight_config.sort_fields.keys } | ||
|
||
let(:expected_sort_fields) do | ||
[ | ||
"system_modified_dtsi desc", | ||
"system_modified_dtsi asc", | ||
"system_create_dtsi desc", | ||
"system_create_dtsi asc", | ||
"depositor_ssi asc, title_ssi asc", | ||
"depositor_ssi desc, title_ssi desc", | ||
"creator_ssi asc, title_ssi asc", | ||
"creator_ssi desc, title_ssi desc" | ||
] | ||
end | ||
|
||
it "configures the custom sort fields" do | ||
expect(subject).to match_array(expected_sort_fields) | ||
end | ||
end | ||
end |