Add collections to your Hydra application. These collections are typically created by depositors (instead of librarians or curators). Any collectible item can belong to many different collections. The collection does not confer access rights onto any of the members of the collections.
Add this line to your application's Gemfile:
gem 'hydra-collections'
And then execute:
$ bundle
Finally run: $ rails generate hydra:collections:install
Or install it yourself as:
$ gem install hydra-collections
mount Hydra::Collections::Engine => '/'
First add helper :collections
to your catalog_controller.rb
Next, we recommend putting the view helper in catalog/_sort_and_per_page.html.erb which you will manually override in you app.
<%= button_for_create_collection %>
collections.new_collections_path
Add include Hydra::Works::WorkBehavior
to the models for anything that you want to be able to add to collections (ie. GenericFile, Book, Article, etc.).
Example:
class GenericFile < ActiveFedora::Base
include Hydra::Works::WorkBehavior
end
Any items that include the Hydra::Works::WorkBehavior
module can look up which collections they belong to via .in_collections
.
Add include Hydra::Collections::AcceptsBatches
to the collections you would like to process batches of models
You can access the batch in your update.
Example:
class BatchEditsController < ApplicationController
include Hydra::Collections::AcceptsBatches
...
def update
batch.each do |doc_id|
obj = ActiveFedora::Base.find(doc_id, :cast=>true)
update_document(obj)
obj.save
end
flash[:notice] = "Batch update complete"
after_update
end
end
add to your application.js
//= require hydra/batch_select
//= require hydra_collections
Take a look at the helpers located in:
- app/helpers/collections_helper.rb
- app/helpers/batch_select_helper.rb
- app/helpers/collections_search_helper.rb
include <%= button_for_add_to_batch document %>
Example:
<% # views/catalog/_document_header.html.erb -%>
<% # header bar for doc items in index view -%>
<div class="documentHeader clearfix">
<%= button_for_add_to_batch(document) %>
...
</div>
Add submits-batches
class to your view input to initialize batch processing
Example:
<%= button_to label, edit_batch_edits_path, method: :get, class: "btn submits-batches",
'data-behavior'=>'batch-edit', id: 'batch-edit' %>
Add updates-batches
class to your button for submitting the batch
Example:
<%= button_to label, collections.collection_path(collection_id), method: :put,
class: "btn btn-primary updates-collection submits-batches collection-update",
'data-behavior'=>'hydra-collections', id: 'hydra-collection-update' %>
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
In order to make modifications to the gem code and run the tests, clone the repository then
$ bundle install
$ bundle exec rake ci
The hydra-collections source code is freely available under the Apache 2.0 license. Read the copyright statement and license.
This software has been developed by and is brought to you by the Hydra community. Learn more at the Project Hydra website