Last active
July 7, 2020 09:30
-
-
Save mankind/55763ad5694fa5bb972dd2bdb0314136 to your computer and use it in GitHub Desktop.
Add multipart metadata fields to samvera active_fedora models
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
#todo |
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. Remove the field eg 'publisher' from self.required array. | |
https://github.com/ubiquitypress/hyku/blob/test/app/forms/ubiquity/all_forms_shared_behaviour.rb#L41 | |
self.required_fields += %i[title resource_type creator institution publisher date_published] | |
2. Ensure you add the field eg 'publisher' to the self.terms variable in the individual form class for each work | |
in https://github.com/ubiquitypress/hyku/tree/test/app/forms/hyrax | |
eg to make publisger an optional field for ArticleForm, got into | |
app/forms/hyrax/article_form.rb and edit it to have include publisher as shown below | |
module Hyrax | |
class ArticleForm < Hyrax::Forms::WorkForm | |
include Hyrax::FormTerms | |
include ::Ubiquity::AllFormsSharedBehaviour | |
self.model_class = ::Article | |
self.terms += %i[ | |
alternate_identifier related_identifier volume issue pagination publisher | |
place_of_publication ] | |
self.required_fields += %i[journal_title] | |
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
How Hyrax/Hyku search is rendered | |
http://jessiekeck.com/customizing-blacklight/search_fields/ | |
http://jessiekeck.com/customizing-blacklight/metadata_fields/ | |
1. Search sidebar facet: If you want a field to be included there. add it as a config.add_facet_field solr_name() eg https://github.com/ubiquitypress/hyku/blob/test/app/controllers/catalog_controller.rb#L56 | |
2. Main search page results: For a field to appear in the search result, you must add it to: config.add_index_field solr_name() eg https://github.com/ubiquitypress/hyku/blob/test/app/controllers/catalog_controller.rb#L56 | |
3. For each result on the search page, the catalogue index page is rendered: https://github.com/ubiquitypress/hyku/blob/test/app/views/catalog/_index_list_default.html.erb | |
4. For each json metadata field rendered by the index page in step, we the use the display_json_fields helper which in turn renders the partial shared/ubiquity/search_display/_show_array_hash.html.erb | |
See link to both files below | |
https://github.com/ubiquitypress/hyku/blob/test/app/helpers/ubiquity/solr_search_display_helpers.rb#L4 | |
https://github.com/ubiquitypress/hyku/blob/test/app/views/shared/ubiquity/search_display/_show_array_hash.html.erb | |
### | |
displaying on search page | |
app/controllers/catalog_controller.rb | |
a. solr fields to be displayed in the index (search results) view | |
config.add_index_field solr_name("isbn", :stored_searchable), label: "ISBN" | |
b. # solr fields to be displayed in the show (single result) view | |
# The ordering of the field names is the order of the display | |
config.add_show_field solr_name("isbn", :stored_searchable) | |
Add change label by going into the locale file for each work and adding it there | |
config/locales/book.en.yml | |
https://github.com/ubiquitypress/hyku/blob/test/config/locales/book.en.yml#L15 | |
https://github.com/ubiquitypress/hyku/blob/test/config/locales/article.en.yml | |
Added institutional relationship asa sub field to the json fields | |
https://github.com/ubiquitypress/hyku/pull/128 | |
New metadata field: ISBN #53 | |
https://github.com/ubiquitypress/hyku/pull/53/files | |
New metadata field: 'Event location' #142 | |
https://github.com/ubiquitypress/hyku/pull/142/files | |
New metadata field: Library of Congress Classification | |
https://github.com/ubiquitypress/hyku/pull/130 | |
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
add isbn to book_work, book_chapter and uncategorized #678 | |
https://github.com/ubiquitypress/hyku/pull/678 | |
add page_display_order_number metadatata field to article_work #668 | |
https://github.com/ubiquitypress/hyku/pull/668/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
It is this: https://github.com/samvera-labs/hyku/blob/master/app/views/splash/index.html.erb | |
scroll down to the config/route section in the original commit that created the shared page by Claire and you will see her renaming the route from | |
get '/', to: 'splash#index ' | |
to | |
get '/', to: 'splash#shared_layer' | |
https://github.com/ubiquitypress/hyku/pull/185/files#diff-21497849d8f00507c9c8dcaf6288b136 |
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
steps to adding contributor_role to pacific | |
make role key in creator and contributor json to be configurable from settings | |
https://github.com/ubiquitypress/hyku/pull/677 | |
1. check what nature of the array passed as dropdown option | |
in rails console run: | |
ContributorGroupService.new.select_active_options.flatten.uniq! | |
Note the array returned contains both values for bl and pacific from | |
https://github.com/ubiquitypress/hyku/blob/test/config/authorities/contributor_group.yml | |
2. We need to pick out the specific dropdpwn options we want for pacific from the list above and add them to | |
TENANTS_WORK_SETTINGS env variablewith the key of contributor_roles | |
eg | |
TENANTS_WORK_SETTINGS { | |
"contributor_roles": ["Advisor", "Partner Organization", "Contributor ", "Editor"] | |
} | |
Note the array passed to contributor_roles must match the array structure you got in the comsole in step 1 | |
4. create a a method set_role_dropdown_options(metadata_field, tenant_work_settings) in settings_helper.rb to return the right dropdown option from TENANTS_WORK_SETTINGS | |
3. add a partial called role in | |
https://github.com/ubiquitypress/hyku/blob/pacific-test/app/views/shared/ubiquity/json_fields_partials/_role.html.erb | |
conditional render different dropdown for creator and metadata | |
The above _role.html.erb is rendered in | |
https://github.com/ubiquitypress/hyku/blob/pacific-test/app/views/shared/ubiquity/contributor/_contributor_form_fields.html.erb | |
https://github.com/ubiquitypress/hyku/blob/pacific-test/app/views/shared/ubiquity/creator/_creator_form_fields.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
1. Define the metadata in the model. | |
http://samvera.github.io/customize-metadata-model.html | |
Note that for Ubiquitypress, we first add them to a module and then we include the module in the models. | |
If the new field will apply to all models, you will them here: | |
https://github.com/ubiquitypress/hyku/blob/test/app/models/concerns/ubiquity/basic_metadata_decorator.rb | |
If they apply to a selected models, you can add them here: | |
https://github.com/ubiquitypress/hyku/blob/test/app/models/concerns/ubiquity/shared_metadata.rb | |
The metadata fields are defined in the format: | |
property :org_unit, predicate: ::RDF::Vocab::ORG.OrganizationalUnit do |index| | |
index.as :stored_searchable | |
end | |
To get the right vocabulary for the predicate eg RDF::Vocab::ORG.OrganizationalUnit for the field name, you will have to check the web eg | |
https://github.com/ruby-rdf/rdf-vocab#vocabularies | |
http://dublincore.org/documents/dcmi-terms/ | |
2. Adding the field to the form | |
http://samvera.github.io/customize-metadata-edit-form.html | |
Here it depends on if the field being added to the form is optional or required: | |
For optional fields, add them to self.terms eg | |
skip this file and see next line below - https://github.com/ubiquitypress/hyku/blob/test/app/forms/ubiquity/all_forms_shared_behaviour.rb#L23-L37 | |
Instead of the above folder go into each work in app/forms/hyrax eg app/forms/hyrax/book_contribution_form.rb | |
Inside each work add the new field in self.terms or self.required_fields | |
self.terms += %i[audience] | |
If the fields are required, add them to: | |
self.required_fields += [:audience] | |
Any field added to self.terms or self.required_fields will display on the new/edit forms. Which means any field that is not | |
added to atleast one of them will not display on the form. | |
3. Display the field on the show page | |
After the form is submitted it will need to be displayed on the show page. This is where the presenter is used by Hyku. | |
a. The presenter relies on solr documents so add the new field ie 'audience' to app/models/solr_document.rb | |
https://github.com/ubiquitypress/hyku/blob/master/app/models/solr_document.rb | |
attribute :audience, Solr::Array, solr_name('audience') | |
b. Next, you will need to delegate the fetching of 'audience' metadata field to the solr_document in the ManifestEnabledWorkShowPresenter | |
https://github.com/ubiquitypress/hyku/blob/test/app/presenters/hyku/manifest_enabled_work_show_presenter.rb#L5-L12 | |
for eg if the field is called audience, you will add it this way: | |
delegate :audience, to: :solr_document | |
c. The second part that must be done before it to displays on the show page is to add it to app/views/hyrax/base/_attribute_rows.html.erb | |
https://github.com/ubiquitypress/hyku/blob/test/app/views/hyrax/base/_attribute_rows.html.erb#L23-L29 | |
for example if the field is called issue, add it this way: | |
<%= presenter.attribute_to_html(:issue, render_as: :string) %> | |
d. solr fields to be displayed in the show (single result) view | |
https://github.com/ubiquitypress/hyku/blob/test/app/controllers/catalog_controller.rb#L131 | |
config.add_show_field solr_name("title", :stored_searchable) | |
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
multipart meta-datafield | |
1. add a single property to represent the multi-part field or use an existing one eg contributor | |
in a new module or an existing one like basic_metadata_decorator and then add the line below to you models | |
include Ubiquity::BasicMetadataDecorator | |
include Ubiquity::EditorMetadataModelConcern | |
2. add virtual fields in the model in app/models/concerns/ubiquity/all_models_virtual_fields.rb to represent the multi-part field ie the sub fields. | |
Note one of those virtual attributes will act as a container for the other sub attributes eg | |
attr_accessor creator_group, will be use in the html form to hold array of hashes contain other sub_fields eg creator_name, creator_orcid etc | |
*note creator_group is then used to populate the active-fedora's creator field thereby avoiding ActionController unpermitted params issues in the controller | |
or ActiveTriples set_value error in the model | |
see modules in now in implemented in a concern see: | |
include Ubiquity::AllModelsVirtualFields | |
3. override the work controllers form class in app/forms/ubiquity/all_forms_shared_behaviours.rb adding those virtual methods via attr_accessor. | |
include ::Ubiquity::AllFormsSharedBehaviour | |
include Ubiquity::EditorMetadataFormBehavior | |
**no more in use**In the form_class remove the field eg contributor self.required_terms+[] and add it to self.required_terms -= [creator] | |
4. create view or use already created helpers methods to extract the virtual attributes from the form curation_courn method which represents the model in app/helpers/journal_articles_helper | |
5. create a form and partial and generate the html form fields using vanila rails. | |
for each metadata field eg :contributor, to the edit/ new form by creating a a partial with that name in the views subfolder using the model name eg journal_articles | |
https://github.com/ubiquitypress/hyku/blob/test/app/views/records/edit_fields/_creator.html.erb | |
6. Step 5 above functions by including various partials for show, edit etc defined in sub folders that bear the metadata field's name eg for creator the partials | |
will be in: | |
app/views/shared/ubiquity/creator/_show.html.erb | |
6. for dropdowns, add a file in config/authories and adda service for those files app/service | |
then use that as value for the collection key in segment tag eg creator_name_type sub field, we have this in app/views/shared/ubiquity/creator/_edit_form_fields.html.erb | |
https://github.com/ubiquitypress/hyku/blob/test/app/views/shared/ubiquity/creator/_new_form.html.erb#L38 | |
%= text_field_tag "#{template}[creator_group][][creator_organization_name]", nil, | |
class: "generic_work_creator_organization_name form-control multi-text-field multi_value ubiquity_creator_organization_name", | |
placeholder: 'Please enter the organisation\'s name.', | |
name: "#{template}[creator_group][][creator_organization_name]", | |
data: {field_name:'ubiquity_creator_organization_name'} | |
%> | |
7. for each metadata field add javascript in the fields name eg for contributor | |
app/views/shared/ubiquity/contributor/_contributor_js.erb | |
8. see below the section on getting multipart fields to save | |
9. in app/helpers/multiple_metadata_fields_helper.rb add a method that can be shared across all multi-part metadadata fields to help with display. I added 4 helper methods at the moment. | |
https://github.com/ubiquitypress/hyku/blob/test/app/helpers/multiple_metadata_fields_helper.rb#L120 | |
get_model(model_class, model_id, field, multipart_sort_field_name) | |
valid_json?(json) | |
fetch_model(model_class, model_id) | |
sort_hash(array_of_hash, key) | |
### | |
Added institutional relationship as a sub field to the json fields | |
basically you add methods to tehe form class and then to the view file | |
https://github.com/ubiquitypress/hyku/pull/128/files | |
## original pr adding multi field parts | |
https://github.com/ubiquitypress/hyku/pull/49/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
steps to getting creator to display on show-page | |
1. create a partial for the creator in app/views/shared/ubiquity/creator/_show.html.erb | |
2. go to app/views/hyrax/base/_attribute_rows.html.erb | |
and comment out or remove | |
<%# presenter.attribute_to_html(:creator, render_as: :faceted) %> | |
3. to get it to display on the show page, add the partials from step 2 into | |
app/views/hyrax/base/_metadata.html.erb | |
replacing: | |
<%= presenter.attribute_to_html(:creator, render_as: :faceted) %> | |
with | |
<%= render "shared/ubiquity/creator/show", presenter: @presenter %> | |
4. Add it to | |
ManifestEnabledWorkShowPresenter < Hyrax::WorkShowPresenter | |
eg for editor: | |
delegate :editor, to: :solr_document | |
5. In app/models/solr_document.rb | |
Add the metadata field as a new attribute. if the metadata field is called editor, add: | |
attribute :editor, Solr::Array, solr_name('editor') | |
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. For instance, for date_published fields | |
To display for new form: | |
<%= select_year(parse_date(date_published, 'year').to_i, {start_year: 2021, end_year: 1900}) %> | |
<%= select_month(parse_date(date_published, 'month').to_i, { use_two_digit_numbers: true}) %> | |
To display in edit form | |
<%= select_year(parse_date(date_published, 'year').to_i, {start_year: 2021, end_year: 1900}) %> | |
<%= select_month(parse_date(date_published, 'month').to_i, { use_two_digit_numbers: true}) %> | |
To add a prompt, modify it to: | |
<%= select_year(parse_date(date_published, 'year').to_i, {start_year: 2021, end_year: 1900, prompt: 'select year'}) %> | |
<%= select_month(parse_date(date_published, 'month').to_i, { use_two_digit_numbers: true, prompt: 'select month if available'}) %> | |
To add css class and html from name attribute, modify it to: | |
<%= select_year(parse_date(date_published, 'year').to_i, {start_year: 2021, end_year: 1900, | |
prompt: 'select year'}, {name: "#{template}[date_published_group][][date_published_year]", :class => 'form-control ubiquity-date-published-year ubiquity-date-input'}) %> | |
<%= select_month(parse_date(date_published, 'month').to_i, { use_two_digit_numbers: true, | |
prompt: 'select month if available'}, {name: "#{template}[date_published_group][][date_published_month]", :class => 'form-control ubiquity-date-published-month ubiquity-date-input'}) %> | |
<br/> | |
Note that without the proper html name attribute rails will not process the form field value accurately. | |
####### Implementing partials to shared across some date fields | |
1. create a folder called dates or whatever you want in app/views/shared/ubiquity, which becomes app/views/shared/ubiquity/dates | |
2. create the partial in app/views/shared/ubiquity/dates/_date_fields | |
<label class="control-label" for="date_"#{date_field_name}">Date <%= "#{date_field_name}" %> </label> | |
<p class="help-block"><%= t("simple_form.hints.defaults.date_#{date_field_name}") %></p> | |
<%= select_year(parse_date(curation_concern.send("date_#{date_field_name}"), 'year').to_i, {start_year: 2025, end_year: 1860, | |
prompt: 'select year'}, {name: "#{template}[date_#{date_field_name}_group][][date_#{date_field_name}_year]", :class => "form-control ubiquity-date-#{date_field_name}-year ubiquity-date-input"}) %> | |
<%= select_month(parse_date(curation_concern.send("date_#{date_field_name}"), 'month').to_i, { use_two_digit_numbers: true, | |
prompt: 'select month if available'}, {name: "#{template}[date_#{date_field_name}_group][][date_#{date_field_name}_month]", :class => "form-control ubiquity-date-#{date_field_name}-month ubiquity-date-input"}) %> | |
3. render each partial from date_published, date_accepted, date_submitted | |
Ensure date_field_name matches the name for the file you are in. For instance, in _date_accepted.html.erb, the date_field_name will be 'accepted' as shown below. | |
<%= render "shared/ubiquity/dates/date_fields", template: template, date_field_name: 'accepted', curation_concern: @curation_concern %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment