Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contribute back OER and ETD work types from Hyku Commons #2237

Merged
merged 17 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/actors/hyrax/actors/etd_actor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
# Generated via
# `rails generate hyrax:work Etd`
module Hyrax
module Actors
class EtdActor < Hyrax::Actors::BaseActor
end
end
end
92 changes: 92 additions & 0 deletions app/actors/hyrax/actors/oer_actor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true
# Generated via
# `rails generate hyrax:work Oer`
module Hyrax
module Actors
class OerActor < Hyrax::Actors::BaseActor
def create(env)
attributes_collection = env.attributes.delete(:related_members_attributes)
env = add_custom_relations(env, attributes_collection)
super
end

def update(env)
attributes_collection = env.attributes.delete(:related_members_attributes)
env = add_custom_relations(env, attributes_collection)
super
end

private

# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
def add_custom_relations(env, attributes_collection)
return env unless attributes_collection
attributes = attributes_collection&.sort_by { |i, _| i.to_i }&.map { |_, attrs| attrs }

# checking for existing works to avoid rewriting/loading works that are already attached
existing_previous_works = env.curation_concern.previous_version_id
existing_newer_works = env.curation_concern.newer_version_id
existing_alternate_works = env.curation_concern.alternate_version_id
existing_related_items = env.curation_concern.related_item_id

attributes&.each do |attrs|
next if attrs['id'].blank?
if existing_previous_works&.include?(attrs['id']) ||
existing_newer_works&.include?(attrs['id']) ||
existing_alternate_works&.include?(attrs['id']) ||
existing_related_items&.include?(attrs['id'])

if existing_previous_works&.include?(attrs['id'])
env = remove(env, attrs['id'], attrs['relationship']) if
ActiveModel::Type::Boolean.new.cast(attrs['_destroy']) && attrs['relationship'] == 'previous-version'
elsif existing_newer_works&.include?(attrs['id'])
env = remove(env, attrs['id'], attrs['relationship']) if
ActiveModel::Type::Boolean.new.cast(attrs['_destroy']) && attrs['relationship'] == 'newer-version'
elsif existing_alternate_works&.include?(attrs['id'])
env = remove(env, attrs['id'], attrs['relationship']) if
ActiveModel::Type::Boolean.new.cast(attrs['_destroy']) && attrs['relationship'] == 'alternate-version'
elsif existing_related_items&.include?(attrs['id'])
env = remove(env, attrs['id'], attrs['relationship']) if
ActiveModel::Type::Boolean.new.cast(attrs['_destroy']) && attrs['relationship'] == 'related-item'
end
else
env = add(env, attrs['id'], attrs['relationship'])
end
end
env
end

def add(env, id, relationship)
rel = "#{relationship.underscore}_id"
case rel
when "previous_version_id"
env.curation_concern.previous_version_id = (env.curation_concern.previous_version_id.to_a << id)
when "newer_version_id"
env.curation_concern.newer_version_id = (env.curation_concern.newer_version_id.to_a << id)
when "alternate_version_id"
env.curation_concern.alternate_version_id = (env.curation_concern.alternate_version_id.to_a << id)
when "related_item_id"
env.curation_concern.related_item_id = (env.curation_concern.related_item_id.to_a << id)
end
env.curation_concern.save
env
end

def remove(env, id, relationship)
rel = "#{relationship.underscore}_id"
case rel
when "previous_version_id"
env.curation_concern.previous_version_id = (env.curation_concern.previous_version_id.to_a - [id])
when "newer_version_id"
env.curation_concern.newer_version_id = (env.curation_concern.newer_version_id.to_a - [id])
when "alternate_version_id"
env.curation_concern.alternate_version_id = (env.curation_concern.alternate_version_id.to_a - [id])
when "related_item_id"
env.curation_concern.related_item_id = (env.curation_concern.related_item_id.to_a - [id])
end
env.curation_concern.save
env
end
end
end
end
4 changes: 2 additions & 2 deletions app/assets/javascripts/hyrax/relationships/control.es6
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ export default class RelationshipsControl {
* @param {String} message the warning message text to set
*/
setWarningMessage(message) {
this.warning.text(message).removeClass("hidden");
this.warning.text(message).hidden= false;
}

/**
* Hide the warning message on the appropriate row
*/
hideWarningMessage(){
this.warning.addClass("hidden");
this.warning.hidden= true;
}
}
15 changes: 10 additions & 5 deletions app/assets/javascripts/hyrax/relationships/registry.es6
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ export default class Registry {
}

addHiddenField(index, key, value) {
$('<input>').attr({
type: 'hidden',
name: `${this.fieldPrefix(index)}[${key}]`,
value: value
}).appendTo(this.element);
// Check if the value is an object and not null
if (typeof value === 'object' && value !== null) {
value = JSON.stringify(value);
}

$('<input>').attr({
type: 'hidden',
name: `${this.fieldPrefix(index)}[${key}]`,
value: value
}).appendTo(this.element);
}

// ADDED RELATIONSHIP
Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/hyrax/relationships/registry_entry.es6
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ import ConfirmRemoveDialog from 'hyrax/relationships/confirm_remove_dialog'

// Hides the row and adds a _destroy=true field to the form
removeResource(evt) {
evt.preventDefault();
let button = $(evt.target);
this.view.addClass('hidden'); // do not show the block
this.destroyed = true
this.registry.showSaveNote();
}
evt.preventDefault();
let button = $(evt.target);
this.view.attr("hidden", ""); // do not show the block
this.destroyed = true
this.registry.showSaveNote();
}
}
193 changes: 190 additions & 3 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ def self.uploaded_field
config.add_facet_field 'based_near_label_sim', limit: 5
config.add_facet_field 'publisher_sim', limit: 5
config.add_facet_field 'file_format_sim', limit: 5
config.add_facet_field 'contributing_library_sim', limit: 5
config.add_facet_field 'member_of_collections_ssim', limit: 5, label: 'Collections'

# TODO: deal with part of facet changes
# config.add_facet_field solr_name("part", :facetable), limit: 5, label: 'Part'
# config.add_facet_field solr_name("part_of", :facetable), limit: 5
# config.add_facet_field 'part_sim', limit: 5, label: 'Part'
# config.add_facet_field 'part_of_sim', limit: 5

# Have BL send all facet field names to Solr, which has been the default
# previously. Simply remove these lines if you'd rather use Solr request
Expand All @@ -151,6 +152,7 @@ def self.uploaded_field
config.add_index_field 'keyword_tesim', itemprop: 'keywords', link_to_search: 'keyword_sim'
config.add_index_field 'subject_tesim', itemprop: 'about', link_to_search: 'subject_sim'
config.add_index_field 'creator_tesim', itemprop: 'creator', link_to_search: 'creator_sim'
config.add_index_field 'date_tesim', itemprop: 'date'
config.add_index_field 'contributor_tesim', itemprop: 'contributor', link_to_search: 'contributor_sim'
config.add_index_field 'proxy_depositor_ssim', label: "Depositor", helper_method: :link_to_profile
config.add_index_field 'depositor_tesim', label: "Owner", helper_method: :link_to_profile
Expand All @@ -167,6 +169,10 @@ def self.uploaded_field
config.add_index_field 'identifier_tesim', helper_method: :index_field_link, field_name: 'identifier'
config.add_index_field 'embargo_release_date_dtsi', label: "Embargo release date", helper_method: :human_readable_date
config.add_index_field 'lease_expiration_date_dtsi', label: "Lease expiration date", helper_method: :human_readable_date
config.add_index_field 'learning_resource_type_tesim', label: "Learning resource type"
config.add_index_field 'education_level_tesim', label: "Education level"
config.add_index_field 'audience_tesim', label: "Audience"
config.add_index_field 'discipline_tesim', label: "Discipline"

# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
Expand All @@ -188,6 +194,27 @@ def self.uploaded_field
config.add_show_field 'format_tesim'
config.add_show_field 'identifier_tesim'
config.add_show_field 'extent_tesim'
config.add_show_field 'admin_note_tesim', label: "Administrative Notes"
config.add_show_field "alternative_title_tesim", label: "Alternative title"
config.add_show_field "related_url_tesim"
config.add_show_field 'learning_resource_type_tesim'
config.add_show_field 'education_level_tesim'
config.add_show_field 'audience_tesim'
config.add_show_field 'discipline_tesim'
config.add_show_field "date_tesim", label: "Date", helper_method: :human_readable_date
config.add_show_field "table_of_contents_tesim", label: "Table of contents"
config.add_show_field "rights_holder_tesim", label: "Rights holder"
config.add_show_field "additional_information_tesim", label: "Additional information"
config.add_show_field "oer_size_tesim", label: "Size"
config.add_show_field 'accessibility_feature_tesim'
config.add_show_field 'accessibility_hazard_tesim'
config.add_show_field 'accessibility_summary_tesim', label: "Accessibility summary"
config.add_show_field 'previous_version_id_tesim'
config.add_show_field 'newer_version_id_tesim'
config.add_show_field 'related_item_id_tesim'
config.add_show_field 'contributing_library_tesim'
config.add_show_field 'library_catalog_identifier_tesim'
config.add_show_field 'chronology_note_tesim'

# "fielded" search configuration. Used by pulldown among other places.
# For supported keys in hash, see rdoc for Blacklight::SearchFields
Expand Down Expand Up @@ -403,7 +430,167 @@ def self.uploaded_field
end

config.add_search_field('source') do |field|
solr_name = solr_name("source", :stored_searchable)
solr_name = 'source_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('advisor') do |field|
solr_name = 'advisor_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('accessibility_feature') do |field|
solr_name = 'accessibility_feature_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('accessibility_hazard') do |field|
solr_name = 'accessibility_hazard_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('accessibility_summary') do |field|
solr_name = 'accessibility_summary_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('additional_information') do |field|
solr_name = 'additional_information_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('alternative_title') do |field|
solr_name = 'alternative_title_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('audience') do |field|
solr_name = 'audience_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('bibliographic_citation') do |field|
solr_name = 'bibliographic_citation_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('committee_member') do |field|
solr_name = 'committee_member_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('department') do |field|
solr_name = 'department_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('degree_discipline') do |field|
solr_name = 'degree_discipline_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('education_level') do |field|
solr_name = 'education_level_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('degree_grantor') do |field|
solr_name = 'degree_grantor_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('learning_resource_type') do |field|
solr_name = 'learning_resource_type_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('degree_level') do |field|
solr_name = 'degree_level_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('related_url') do |field|
solr_name = 'related_url_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('rights_holder') do |field|
solr_name = 'rights_holder_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('rights_notes') do |field|
solr_name = 'rights_notes_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('size') do |field|
solr_name = 'size_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end

config.add_search_field('table_of_contents') do |field|
solr_name = 'table_of_contents_tesim'
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
Expand Down
Loading
Loading