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

TBD #110

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

TBD #110

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
113 changes: 113 additions & 0 deletions app/controllers/hyrax/collections_controller_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module Hyrax
module CollectionsControllerBehavior
# overriding this to figure something out
# test to tsee if this is where the issue is !??
extend ActiveSupport::Concern
include Blacklight::AccessControls::Catalog
include Blacklight::Base

included do
# include the display_trophy_link view helper method
helper Hyrax::TrophyHelper

# This is needed as of BL 3.7
copy_blacklight_config_from(::CatalogController)

class_attribute :presenter_class,
:form_class,
:single_item_search_builder_class,
:membership_service_class

self.presenter_class = Hyrax::CollectionPresenter

# The search builder to find the collection
self.single_item_search_builder_class = SingleCollectionSearchBuilder
# The search builder to find the collections' members
# Maybe here!??
self.membership_service_class = Collections::CollectionMemberService
end

def show
@curation_concern ||= ActiveFedora::Base.find(params[:id])
presenter
query_collection_members
end

def collection
action_name == 'show' ? @presenter : @collection
end

private

def presenter
@presenter ||= begin
# Query Solr for the collection.
# run the solr query to find the collection members
response = repository.search(single_item_search_builder.query)
curation_concern = response.documents.first
raise CanCan::AccessDenied unless curation_concern
presenter_class.new(curation_concern, current_ability)
end
end

# Instantiates the search builder that builds a query for a single item
# this is useful in the show view.
def single_item_search_builder
single_item_search_builder_class.new(self).with(params.except(:q, :page))
end

def collection_params
form_class.model_attributes(params[:collection])
end

# Include 'catalog' and 'hyrax/base' in the search path for views, while prefering
# our local paths. Thus we are unable to just override `self.local_prefixes`
def _prefixes
@_prefixes ||= super + ['catalog', 'hyrax/base']
end

def query_collection_members
member_works
member_subcollections if collection.collection_type.nestable?
parent_collections if collection.collection_type.nestable? && action_name == 'show'
end

# Instantiate the membership query service
def collection_member_service
@collection_member_service ||= membership_service_class.new(scope: self, collection: collection, params: params_for_query)
end

def member_works
@response = collection_member_service.available_member_works
@member_docs = @response.documents
@members_count = @response.total
end

def parent_collections
page = params[:parent_collection_page].to_i
query = Hyrax::Collections::NestedCollectionQueryService
collection.parent_collections = query.parent_collections(child: collection_object, scope: self, page: page)
end

def collection_object
action_name == 'show' ? Collection.find(collection.id) : collection
end

def member_subcollections
results = collection_member_service.available_member_subcollections
@subcollection_solr_response = results
@subcollection_docs = results.documents
@subcollection_count = @presenter.subcollection_count = results.total
end

# You can override this method if you need to provide additional inputs to the search
# builder. For example:
# search_field: 'all_fields'
# @return <Hash> the inputs required for the collection member query service
def params_for_query
Rails.logger.error "TEST TEST"
Rails.logger.error "cq is " + params[:cq].to_s()
params.merge(q: params[:cq])
end
end
end
10 changes: 10 additions & 0 deletions app/controllers/hyrax/my/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def collection_type_list_presenter
def managed_collections_count
@managed_collection_count = Hyrax::Collections::ManagedCollectionsService.managed_collections_count(scope: self)
end


# Maybe we change the query paramaters to take into account visibility
# You can override this method if you need to provide additional
# inputs to the search builder. For example:
# search_field: 'all_fields'
# @return <Hash> the inputs required for the collection member search builder
def params_for_query
params.merge(q: params[:cq])
end
end
end
end
Loading