-
Notifications
You must be signed in to change notification settings - Fork 4
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 #33 from pulibrary/collections
Implement Collections
- Loading branch information
Showing
33 changed files
with
379 additions
and
70 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
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,13 @@ | ||
# frozen_string_literal: true | ||
class CollectionChangeSet < Valkyrie::ChangeSet | ||
delegate :human_readable_type, to: :model | ||
property :title, multiple: false, required: true | ||
property :slug, multiple: false, required: true | ||
property :description, multiple: false, required: false | ||
property :visibility, multiple: false, required: false | ||
validates :title, :slug, presence: true | ||
|
||
def primary_terms | ||
[:title, :slug, :description] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
class CollectionsController < ApplicationController | ||
include Valhalla::ResourceController | ||
self.change_set_class = DynamicChangeSet | ||
self.resource_class = Collection | ||
self.change_set_persister = PlumChangeSetPersister.new( | ||
metadata_adapter: Valkyrie::MetadataAdapter.find(:indexing_persister), | ||
storage_adapter: Valkyrie.config.storage_adapter | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
class CollectionDecorator < Valkyrie::ResourceDecorator | ||
def title | ||
Array(super).first | ||
end | ||
|
||
def manageable_files? | ||
false | ||
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 |
---|---|---|
@@ -1,4 +1,22 @@ | ||
# frozen_string_literal: true | ||
class ScannedResourceDecorator < Valkyrie::ResourceDecorator | ||
self.display_attributes = [:author, :internal_resource, :created_at, :updated_at] | ||
self.display_attributes = [:author, :internal_resource, :created_at, :updated_at, :member_of_collections] | ||
delegate :query_service, to: :metadata_adapter | ||
|
||
def member_of_collections | ||
@member_of_collections ||= | ||
begin | ||
member_of_collection_ids.map do |id| | ||
query_service.find_by(id: id).decorate | ||
end.map(&:title) | ||
end | ||
end | ||
|
||
def member_of_collection_ids | ||
super || [] | ||
end | ||
|
||
def metadata_adapter | ||
Valkyrie.config.metadata_adapter | ||
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ def updated_at | |
end | ||
|
||
def header | ||
title.to_sentence | ||
Array(title).to_sentence | ||
end | ||
|
||
def manageable_files? | ||
|
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,27 @@ | ||
# frozen_string_literal: true | ||
class CollectionIndexer | ||
delegate :query_service, to: :metadata_adapter | ||
attr_reader :resource | ||
def initialize(resource:) | ||
@resource = resource | ||
end | ||
|
||
def to_solr | ||
return {} unless resource.respond_to?(:member_of_collection_ids) | ||
{ | ||
"member_of_collection_titles_ssim" => collections.map(&:title).to_a | ||
} | ||
end | ||
|
||
def collections | ||
return [] if resource.member_of_collection_ids.blank? | ||
@collections ||= | ||
begin | ||
query_service.find_references_by(resource: resource, property: :member_of_collection_ids).map(&:decorate) | ||
end | ||
end | ||
|
||
def metadata_adapter | ||
Valkyrie.config.metadata_adapter | ||
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,23 @@ | ||
# frozen_string_literal: true | ||
class CompositeIndexer | ||
attr_reader :indexers | ||
def initialize(*indexers) | ||
@indexers = indexers | ||
end | ||
|
||
def new(resource:) | ||
Instance.new(indexers, resource: resource) | ||
end | ||
|
||
class Instance | ||
attr_reader :indexers, :resource | ||
def initialize(indexers, resource:) | ||
@resource = resource | ||
@indexers = indexers.map { |i| i.new(resource: resource) } | ||
end | ||
|
||
def to_solr | ||
indexers.map(&:to_solr).inject({}, &:merge) | ||
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,9 @@ | ||
# frozen_string_literal: true | ||
class Collection < Valhalla::Resource | ||
include Valkyrie::Resource::AccessControls | ||
attribute :id, Valkyrie::Types::ID.optional | ||
attribute :title, Valkyrie::Types::Set | ||
attribute :slug, Valkyrie::Types::Set | ||
attribute :description, Valkyrie::Types::Set | ||
attribute :visibility, Valkyrie::Types::Set | ||
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
1 change: 1 addition & 0 deletions
1
app/views/records/edit_fields/_member_of_collection_ids.html.erb
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 @@ | ||
<%= f.input :member_of_collection_ids, collection: @collections, label_method: :title, value_method: :id, input_html: { multiple: f.object.multiple?(key) }, include_blank: true %> |
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
Oops, something went wrong.