Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

centralize the list of collection classes #5207

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/helpers/hyrax/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ def available_parent_collections_data(collection:)
end.to_json
end

##
# @since 3.1.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to 3.4.0?

Suggested change
# @since 3.1.0
# @since 3.4.0

# @return [String] the css class for the collection model icon
def collection_model_icon
Hyrax::ModelIcon.css_class_for(Hyrax.config.collection_class)
end

##
# @since 3.0.0
# @return [#to_s]
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hyrax/file_set_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def display_media_download_link?(file_set:)
end

def parent_path(parent)
if parent.is_a?(::Collection)
if parent.collection?
main_app.collection_path(parent)
else
polymorphic_path([main_app, parent])
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hyrax/hyrax_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def user_display_name_and_key(user_key)

# Used by the gallery view
def collection_thumbnail(_document, _image_options = {}, _url_options = {})
tag.span("", class: [Hyrax::ModelIcon.css_class_for(::Collection), "collection-icon-search"])
tag.span("", class: [Hyrax::ModelIcon.css_class_for(Hyrax.config.collection_class), "collection-icon-search"])
end

def collection_title_by_id(id)
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/hyrax/ability/collection_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Hyrax
module Ability
module CollectionAbility
def collection_abilities # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
models = [Hyrax::PcdmCollection, Hyrax.config.collection_class].uniq
models = Hyrax.collection_classes
if admin?
models.each do |collection_model|
can :manage, collection_model
Expand Down
2 changes: 1 addition & 1 deletion app/search_builders/hyrax/exposed_models_relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Hyrax
# A relation that scopes to all user visible models (e.g. works + collections + file sets)
class ExposedModelsRelation < AbstractTypeRelation
def allowable_types
(Hyrax.config.curation_concerns + [Hyrax.config.collection_class, ::Collection, ::FileSet]).uniq
(Hyrax.config.curation_concerns + Hyrax.collection_classes + [::FileSet]).uniq
end
end
end
2 changes: 1 addition & 1 deletion app/search_builders/hyrax/filter_by_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def work_classes

def collection_classes
return [] if only_works?
[::Collection, Hyrax.config.collection_class].uniq
Hyrax.collection_classes
end
end
end
2 changes: 1 addition & 1 deletion app/views/hyrax/collections/_list_collections.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<td></td>
<td>
<div class="media">
<span class="<%= Hyrax::ModelIcon.css_class_for(::Collection) %> collection-icon-small pull-left"></span>
<span class="<%= Hyrax::ModelIcon.css_class_for(Hyrax.config.collection_class) %> collection-icon-small pull-left"></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be changed like the change in app/views/hyrax/collections/_media_display.html.erb?

Suggested change
<span class="<%= Hyrax::ModelIcon.css_class_for(Hyrax.config.collection_class) %> collection-icon-small pull-left"></span>
<span class="<%= collection_model_icon %> collection-icon-small pull-left"></span>

<div class="media-body">
<div class="media-heading">
<%= link_to collection_presenter.show_path do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/collections/_media_display.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
alt: "",
role: "presentation" %>
<% else %>
<span class="<%= Hyrax::ModelIcon.css_class_for(::Collection) %> collection-icon-search" aria-hidden="true"></span>
<span class="<%= collection_model_icon %> collection-icon-search" aria-hidden="true"></span>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="thumbnail-title-wrapper">
<div class="thumbnail-wrapper">
<% if (collection_presenter.thumbnail_path == nil) %>
<span class="<%= Hyrax::ModelIcon.css_class_for(::Collection) %> collection-icon-small"></span>
<span class="<%= Hyrax::ModelIcon.css_class_for(Hyrax.config.collection_class) %> collection-icon-small"></span>
<% else %>
<%= image_tag(collection_presenter.thumbnail_path, alt: "#{collection_presenter.title_or_label} #{t('hyrax.dashboard.my.sr.thumbnail')}") %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/hyrax/my/collections/_list_collections.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="thumbnail-title-wrapper">
<div class="thumbnail-wrapper">
<% if (collection_presenter.thumbnail_path == nil) %>
<span class="<%= Hyrax::ModelIcon.css_class_for(::Collection) %> collection-icon-small"></span>
<span class="<%= Hyrax::ModelIcon.css_class_for(Hyrax.config.collection_class) %> collection-icon-small"></span>
<% else %>
<%= image_tag(collection_presenter.thumbnail_path, alt: "#{collection_presenter.title_or_label} #{t('hyrax.dashboard.my.sr.thumbnail')}") %>
<% end %>
Expand Down
8 changes: 8 additions & 0 deletions lib/hyrax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,12 @@ def self.query_service
def self.custom_queries
query_service.custom_queries
end

##
# @return [Array<Class>] all possible collection classes
def self.collection_classes
klasses = [Hyrax.config.collection_class, Hyrax::PcdmCollection]
klasses << ::Collection if defined? ::Collection
klasses.uniq
end
end
7 changes: 7 additions & 0 deletions spec/lib/hyrax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@
expect(described_class.logger).to respond_to :log
end
end

describe '.collection_classes' do
it 'returns all possible collection classes' do
expect(described_class.collection_classes)
.to match_array [::Collection, Hyrax::PcdmCollection]
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
describe '#models' do
its(:models) do
is_expected
.to contain_exactly(*[::Collection, Hyrax.config.collection_class].uniq)
.to contain_exactly(*Hyrax.collection_classes)
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/search_builders/hyrax/work_search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
end

let(:class_filter_string) do
[Monograph, Collection, Hyrax.config.collection_class].uniq.join(',')
klasses = [Monograph] + Hyrax.collection_classes
klasses.join(',')
end

describe "#query" do
Expand Down