Skip to content

Commit

Permalink
Assign a work to an admin set. Fixes #2502
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 19, 2016
1 parent 293181b commit 70c3649
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/forms/sufia/forms/work_form.rb
Expand Up @@ -9,7 +9,7 @@ class WorkForm < CurationConcerns::Forms::WorkForm

attr_reader :agreement_accepted

self.terms += [:collection_ids]
self.terms += [:collection_ids, :admin_set_id]
self.required_fields = [:title, :creator, :keyword, :rights]

def initialize(model, current_ability)
Expand All @@ -24,7 +24,7 @@ def [](key)

# Fields that are automatically drawn on the page above the fold
def primary_terms
required_fields
required_fields + [:admin_set_id]
end

# Fields that are automatically drawn on the page below the fold
Expand Down
4 changes: 4 additions & 0 deletions app/indexers/sufia/work_indexer.rb
Expand Up @@ -8,6 +8,10 @@ def generate_solr_document
# when a work in the collection matches the query.
solr_doc[Solrizer.solr_name('file_set_ids', :symbol)] = solr_doc[Solrizer.solr_name('member_ids', :symbol)]
solr_doc[Solrizer.solr_name('resource_type', :facetable)] = object.resource_type

admin_set_label = object.admin_set.to_s
solr_doc[Solrizer.solr_name('admin_set', :facetable)] = admin_set_label
solr_doc[Solrizer.solr_name('admin_set', :stored_searchable)] = admin_set_label
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/sufia/solr_document_behavior.rb
Expand Up @@ -57,6 +57,10 @@ def collection_ids
Array.wrap(self['collection_ids_tesim'])
end

def admin_set
fetch(Solrizer.solr_name('admin_set'), [])
end

# Find the solr documents for the collections this object belongs to
def collections
return @collections if @collections
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/sufia/work_show_presenter.rb
Expand Up @@ -2,7 +2,7 @@ module Sufia
class WorkShowPresenter < ::CurationConcerns::WorkShowPresenter
# delegate fields from Sufia::Works::Metadata to solr_document
delegate :based_near, :related_url, :depositor, :identifier, :resource_type,
:keyword, :itemtype, to: :solr_document
:keyword, :itemtype, :admin_set, to: :solr_document

def editor?
current_ability.can?(:edit, solr_document)
Expand Down
17 changes: 9 additions & 8 deletions app/views/curation_concerns/base/_attribute_rows.html.erb
@@ -1,11 +1,12 @@
<%= presenter.attribute_to_html(:creator, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:creator, render_as: :faceted) %>
<%= presenter.attribute_to_html(:contributor, label: 'Contributors', render_as: :faceted) %>
<%= presenter.attribute_to_html(:subject, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:publisher, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:language, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:admin_set, render_as: :faceted) %>
<%= presenter.attribute_to_html(:subject, render_as: :faceted) %>
<%= presenter.attribute_to_html(:publisher, render_as: :faceted) %>
<%= presenter.attribute_to_html(:language, render_as: :faceted) %>
<%= presenter.attribute_to_html(:identifier, render_as: :linked, search_field: 'identifier_tesim') %>
<%= presenter.attribute_to_html(:keyword, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:date_created, render_as: :linked, search_field: 'date_created_tesim' ) %>
<%= presenter.attribute_to_html(:based_near, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:keyword, render_as: :faceted) %>
<%= presenter.attribute_to_html(:date_created, render_as: :linked, search_field: 'date_created_tesim') %>
<%= presenter.attribute_to_html(:based_near, render_as: :faceted) %>
<%= presenter.attribute_to_html(:related_url) %>
<%= presenter.attribute_to_html(:resource_type, render_as: :faceted ) %>
<%= presenter.attribute_to_html(:resource_type, render_as: :faceted) %>
4 changes: 4 additions & 0 deletions app/views/records/edit_fields/_admin_set_id.html.erb
@@ -0,0 +1,4 @@
<%= f.input :admin_set_id, as: :select,
collection: CurationConcerns::AdminSetService.new(controller).select_options,
include_blank: true,
input_html: { class: 'form-control' } %>
5 changes: 5 additions & 0 deletions spec/factories/admin_sets.rb
@@ -0,0 +1,5 @@
FactoryGirl.define do
factory :admin_set do
sequence(:title) { |n| ["Title #{n}"] }
end
end
2 changes: 1 addition & 1 deletion spec/forms/curation_concerns/generic_work_form_spec.rb
Expand Up @@ -9,7 +9,7 @@

describe "#primary_terms" do
subject { form.primary_terms }
it { is_expected.to eq [:title, :creator, :keyword, :rights] }
it { is_expected.to eq [:title, :creator, :keyword, :rights, :admin_set_id] }
end

describe "#secondary_terms" do
Expand Down
5 changes: 3 additions & 2 deletions spec/forms/sufia/forms/batch_upload_form_spec.rb
Expand Up @@ -6,7 +6,7 @@

describe "#primary_terms" do
subject { form.primary_terms }
it { is_expected.to eq [:creator, :keyword, :rights] }
it { is_expected.to eq [:creator, :keyword, :rights, :admin_set_id] }
it { is_expected.not_to include(:title) }
end

Expand Down Expand Up @@ -59,6 +59,7 @@
:ordered_member_ids,
:source,
:in_works_ids,
:collection_ids] }
:collection_ids,
:admin_set_id] }
end
end
14 changes: 14 additions & 0 deletions spec/indexers/sufia/work_indexer_spec.rb
@@ -0,0 +1,14 @@
require 'spec_helper'

RSpec.describe Sufia::WorkIndexer do
let(:indexer) { described_class.new(work) }
describe "#generate_solr_document" do
let(:work) { create(:generic_work, admin_set: create(:admin_set)) }
subject(:document) { indexer.generate_solr_document }

it "indexes the correct fields" do
expect(document.fetch('admin_set_sim')).to eq ["Title 1"]
expect(document.fetch('admin_set_tesim')).to eq ["Title 1"]
end
end
end
1 change: 1 addition & 0 deletions spec/test_app_templates/Gemfile.extra
@@ -1,6 +1,7 @@
# Use this file to reference specific commits of gems.
gem 'breadcrumbs_on_rails', git: 'https://github.com/weppos/breadcrumbs_on_rails.git'
gem 'blacklight', git: 'https://github.com/projectblacklight/blacklight'
gem 'curation_concerns', git: 'https://github.com/projecthydra/curation_concerns.git', branch: 'admin-set-context'
gem 'acts_as_follower', git: 'https://github.com/awjecc/acts_as_follower.git', branch: 'rails5-fix-parent_class_name'

group :development do
Expand Down

0 comments on commit 70c3649

Please sign in to comment.