Skip to content

Commit 27e234f

Browse files
committed
Add controlled vocabulary properties
* follow instructions for adding custom metadata * define properties in models * add to New/Edit form * add to show page Test with * login * add a demo work -- Works -> New Work (confirm new properties are on the form) * add string values for testing * save * confirm properties and values are displayed on the show page
1 parent ce93160 commit 27e234f

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

app/controllers/catalog_controller.rb

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def self.modified_field
8989
# The ordering of the field names is the order of the display
9090
config.add_show_field solr_name("title", :stored_searchable), label: "Title"
9191
config.add_show_field solr_name("description", :stored_searchable), label: "Description"
92+
93+
config.add_show_field solr_name("oclc_organization", :stored_searchable), label: "Oclc Organization"
94+
config.add_show_field solr_name("agrovoc_keyword", :stored_searchable), label: "Agrovoc Keyword (en)"
95+
config.add_show_field solr_name("agrovoc_keyword_fr", :stored_searchable), label: "Agrovoc Keyword (fr)"
96+
9297
config.add_show_field solr_name("keyword", :stored_searchable), label: "Keyword"
9398
config.add_show_field solr_name("subject", :stored_searchable), label: "Subject"
9499
config.add_show_field solr_name("creator", :stored_searchable), label: "Creator"

app/controllers/hyrax/demo_works_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class DemoWorksController < ApplicationController
77
include Hyrax::WorksControllerBehavior
88
include Hyrax::BreadcrumbsForWorks
99
self.curation_concern_type = DemoWork
10+
self.show_presenter = DemoWorkPresenter
1011
end
1112
end

app/forms/hyrax/demo_work_form.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Hyrax
44
class DemoWorkForm < Hyrax::Forms::WorkForm
55
self.model_class = ::DemoWork
6-
self.terms += [:resource_type]
6+
self.terms += [:resource_type, :oclc_organization, :agrovoc_keyword, :agrovoc_keyword_fr, :loc_name]
7+
self.required_fields += [:oclc_organization, :agrovoc_keyword, :agrovoc_keyword_fr]
78
end
89
end

app/models/demo_work.rb

+20
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,24 @@ class DemoWork < ActiveFedora::Base
88
validates :title, presence: { message: 'Your work must have a title.' }
99

1010
self.human_readable_type = 'Demo Work'
11+
12+
property :oclc_organization_uri, predicate: ::RDF::URI.new('http://www.example.org/ns#oclc_org'), multiple: true
13+
property :oclc_organization, predicate: ::RDF::URI.new('http://www.example.org/ns#oclc_org_label'), multiple: true do |index|
14+
index.as :stored_searchable, :facetable
15+
end
16+
17+
property :agrovoc_keyword_uri, predicate: ::RDF::URI.new('http://www.example.org/ns#agrovoc_keyword'), multiple: true
18+
property :agrovoc_keyword, predicate: ::RDF::URI.new('http://www.example.org/ns#agrovoc_keyword_label'), multiple: true do |index|
19+
index.as :stored_searchable, :facetable
20+
end
21+
22+
property :agrovoc_keyword_fr_uri, predicate: ::RDF::URI.new('http://www.example.org/ns#agrovoc_keyword_fr'), multiple: true
23+
property :agrovoc_keyword_fr, predicate: ::RDF::URI.new('http://www.example.org/ns#agrovoc_keyword_label_fr'), multiple: true do |index|
24+
index.as :stored_searchable, :facetable
25+
end
26+
27+
property :loc_name_uri, predicate: ::RDF::URI.new('http://www.example.org/ns#loc_name'), multiple: true
28+
property :loc_name, predicate: ::RDF::URI.new('http://www.example.org/ns#loc_name_label'), multiple: true do |index|
29+
index.as :stored_searchable, :facetable
30+
end
1131
end

app/models/solr_document.rb

+24
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,28 @@ class SolrDocument
2525
# Do content negotiation for AF models.
2626

2727
use_extension( Hydra::ContentNegotiation )
28+
29+
def oclc_organization
30+
self[Solrizer.solr_name('oclc_organization')]
31+
end
32+
33+
def oclc_organization_uri
34+
self[Solrizer.solr_name('oclc_organization_uri')]
35+
end
36+
37+
def agrovoc_keyword
38+
self[Solrizer.solr_name('agrovoc_keyword')]
39+
end
40+
41+
def agrovoc_keyword_uri
42+
self[Solrizer.solr_name('agrovoc_keyword_uri')]
43+
end
44+
45+
def agrovoc_keyword_fr
46+
self[Solrizer.solr_name('agrovoc_keyword_fr')]
47+
end
48+
49+
def agrovoc_keyword_fr_uri
50+
self[Solrizer.solr_name('agrovoc_keyword_fr_uri')]
51+
end
2852
end

app/presenters/demo_work_presenter.rb

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# app/presenters/demo_work_presenter.rb
2+
class DemoWorkPresenter < Hyrax::WorkShowPresenter
3+
delegate :oclc_organization, :oclc_organization_uri, :agrovoc_keyword, :agrovoc_keyword_uri, :agrovoc_keyword_fr, :agrovoc_keyword_fr_uri, to: :solr_document
4+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%= presenter.attribute_to_html(:creator, render_as: :faceted) %>
2+
<%= presenter.attribute_to_html(:contributor, render_as: :faceted) %>
3+
<%= presenter.attribute_to_html(:oclc_organization, render_as: :faceted) %>
4+
<%= presenter.attribute_to_html(:agrovoc_keyword, render_as: :faceted) %>
5+
<%= presenter.attribute_to_html(:agrovoc_keyword_fr, render_as: :faceted) %>
6+
<%= presenter.attribute_to_html(:subject, render_as: :faceted) %>
7+
<%= presenter.attribute_to_html(:publisher, render_as: :faceted) %>
8+
<%= presenter.attribute_to_html(:language, render_as: :faceted) %>
9+
<%= presenter.attribute_to_html(:identifier, render_as: :linked, search_field: 'identifier_tesim') %>
10+
<%= presenter.attribute_to_html(:keyword, render_as: :faceted) %>
11+
<%= presenter.attribute_to_html(:date_created, render_as: :linked, search_field: 'date_created_tesim') %>
12+
<%= presenter.attribute_to_html(:based_near, render_as: :faceted) %>
13+
<%= presenter.attribute_to_html(:related_url, render_as: :external_link) %>
14+
<%= presenter.attribute_to_html(:resource_type, render_as: :faceted) %>
15+
<%= presenter.attribute_to_html(:source) %>

0 commit comments

Comments
 (0)