diff --git a/.dassie/app/forms/collection_resource_form.rb b/.dassie/app/forms/collection_resource_form.rb index f9b2bf5938..4a0585238e 100644 --- a/.dassie/app/forms/collection_resource_form.rb +++ b/.dassie/app/forms/collection_resource_form.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:collection_resource CollectionResource` class CollectionResourceForm < Hyrax::Forms::PcdmCollectionForm - include Hyrax::FormFields(:basic_metadata) - include Hyrax::FormFields(:collection_resource) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::FormFields(:collection_resource) unless Hyrax.config.flexible? end diff --git a/.dassie/app/forms/generic_work_resource_form.rb b/.dassie/app/forms/generic_work_resource_form.rb index 8aa9348d01..86e350a475 100644 --- a/.dassie/app/forms/generic_work_resource_form.rb +++ b/.dassie/app/forms/generic_work_resource_form.rb @@ -6,8 +6,8 @@ # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class GenericWorkResourceForm < Hyrax::Forms::ResourceForm(GenericWorkResource) - include Hyrax::FormFields(:basic_metadata) - include Hyrax::FormFields(:generic_work_resource) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::FormFields(:generic_work_resource) unless Hyrax.config.flexible? # Define custom form fields using the Valkyrie::ChangeSet interface # diff --git a/.dassie/app/forms/monograph_form.rb b/.dassie/app/forms/monograph_form.rb index b347c1eb4e..448b93aa83 100644 --- a/.dassie/app/forms/monograph_form.rb +++ b/.dassie/app/forms/monograph_form.rb @@ -6,8 +6,8 @@ # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class MonographForm < Hyrax::Forms::ResourceForm(Monograph) - include Hyrax::FormFields(:basic_metadata) - include Hyrax::FormFields(:monograph) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::FormFields(:monograph) unless Hyrax.config.flexible? # Define custom form fields using the Valkyrie::ChangeSet interface # diff --git a/.dassie/app/indexers/collection_resource_indexer.rb b/.dassie/app/indexers/collection_resource_indexer.rb index c8dd88b84e..038eb8e10a 100644 --- a/.dassie/app/indexers/collection_resource_indexer.rb +++ b/.dassie/app/indexers/collection_resource_indexer.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:collection_resource CollectionResource` class CollectionResourceIndexer < Hyrax::PcdmCollectionIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:collection_resource) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:collection_resource) unless Hyrax.config.flexible? end diff --git a/.dassie/app/indexers/monograph_indexer.rb b/.dassie/app/indexers/monograph_indexer.rb index 73fac4e9a6..00c60cfd7d 100644 --- a/.dassie/app/indexers/monograph_indexer.rb +++ b/.dassie/app/indexers/monograph_indexer.rb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class MonographIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:monograph) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:monograph) unless Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/.koppie/app/forms/collection_resource_form.rb b/.koppie/app/forms/collection_resource_form.rb index f9b2bf5938..4a0585238e 100644 --- a/.koppie/app/forms/collection_resource_form.rb +++ b/.koppie/app/forms/collection_resource_form.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:collection_resource CollectionResource` class CollectionResourceForm < Hyrax::Forms::PcdmCollectionForm - include Hyrax::FormFields(:basic_metadata) - include Hyrax::FormFields(:collection_resource) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::FormFields(:collection_resource) unless Hyrax.config.flexible? end diff --git a/.koppie/app/forms/generic_work_form.rb b/.koppie/app/forms/generic_work_form.rb index 7e541b0e5e..d0e3141c7c 100644 --- a/.koppie/app/forms/generic_work_form.rb +++ b/.koppie/app/forms/generic_work_form.rb @@ -6,8 +6,8 @@ # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class GenericWorkForm < Hyrax::Forms::ResourceForm(GenericWork) - include Hyrax::FormFields(:basic_metadata) - include Hyrax::FormFields(:generic_work) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::FormFields(:generic_work) unless Hyrax.config.flexible? # Define custom form fields using the Valkyrie::ChangeSet interface # diff --git a/.koppie/app/forms/monograph_form.rb b/.koppie/app/forms/monograph_form.rb index b347c1eb4e..448b93aa83 100644 --- a/.koppie/app/forms/monograph_form.rb +++ b/.koppie/app/forms/monograph_form.rb @@ -6,8 +6,8 @@ # @see https://github.com/samvera/hyrax/wiki/Hyrax-Valkyrie-Usage-Guide#forms # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class MonographForm < Hyrax::Forms::ResourceForm(Monograph) - include Hyrax::FormFields(:basic_metadata) - include Hyrax::FormFields(:monograph) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::FormFields(:monograph) unless Hyrax.config.flexible? # Define custom form fields using the Valkyrie::ChangeSet interface # diff --git a/.koppie/app/indexers/collection_resource_indexer.rb b/.koppie/app/indexers/collection_resource_indexer.rb index c8dd88b84e..038eb8e10a 100644 --- a/.koppie/app/indexers/collection_resource_indexer.rb +++ b/.koppie/app/indexers/collection_resource_indexer.rb @@ -3,6 +3,6 @@ # Generated via # `rails generate hyrax:collection_resource CollectionResource` class CollectionResourceIndexer < Hyrax::PcdmCollectionIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:collection_resource) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:collection_resource) unless Hyrax.config.flexible? end diff --git a/.koppie/app/indexers/generic_work_indexer.rb b/.koppie/app/indexers/generic_work_indexer.rb index c71c28b6b3..84ded03718 100644 --- a/.koppie/app/indexers/generic_work_indexer.rb +++ b/.koppie/app/indexers/generic_work_indexer.rb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource GenericWork` class GenericWorkIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:generic_work) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:generic_work) unless Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/.koppie/app/indexers/monograph_indexer.rb b/.koppie/app/indexers/monograph_indexer.rb index 73fac4e9a6..00c60cfd7d 100644 --- a/.koppie/app/indexers/monograph_indexer.rb +++ b/.koppie/app/indexers/monograph_indexer.rb @@ -3,8 +3,8 @@ # Generated via # `rails generate hyrax:work_resource Monograph` class MonographIndexer < Hyrax::ValkyrieWorkIndexer - include Hyrax::Indexer(:basic_metadata) - include Hyrax::Indexer(:monograph) + include Hyrax::Indexer(:basic_metadata) unless Hyrax.config.flexible? + include Hyrax::Indexer(:monograph) unless Hyrax.config.flexible? # Uncomment this block if you want to add custom indexing behavior: # def to_solr diff --git a/.koppie/config/metadata_profiles/m3_profile.yaml b/.koppie/config/metadata_profiles/m3_profile.yaml index 39fe059a67..51ce6e5f5f 100644 --- a/.koppie/config/metadata_profiles/m3_profile.yaml +++ b/.koppie/config/metadata_profiles/m3_profile.yaml @@ -39,6 +39,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWork + - Monograph cardinality: minimum: 1 multi_value: true @@ -77,6 +78,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWork + - Monograph cardinality: minimum: 0 maximum: 1 @@ -94,6 +96,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWork + - Monograph cardinality: minimum: 0 maximum: 1 @@ -111,6 +114,7 @@ properties: - Hyrax::FileSet - CollectionResource - GenericWork + - Monograph cardinality: minimum: 0 maximum: 1 diff --git a/app/assets/javascripts/hyrax/select_work_type.es6 b/app/assets/javascripts/hyrax/select_work_type.es6 index 263cc58550..320d071715 100644 --- a/app/assets/javascripts/hyrax/select_work_type.es6 +++ b/app/assets/javascripts/hyrax/select_work_type.es6 @@ -39,6 +39,8 @@ export default class SelectWorkType { // for a single work. So, given the value of 'this.type', return the appropriate // path. destination() { - return this.form.find('input[type="radio"]:checked').data(this.type) + let admin_set_id = this.form.find('select').val() + let url = this.form.find('input[type="radio"]:checked').data(this.type) + return url + "&admin_set_id=" + admin_set_id } } diff --git a/app/assets/stylesheets/hyrax/_select_work_type.scss b/app/assets/stylesheets/hyrax/_select_work_type.scss index ff9b04fbe1..9864dfbe8b 100644 --- a/app/assets/stylesheets/hyrax/_select_work_type.scss +++ b/app/assets/stylesheets/hyrax/_select_work_type.scss @@ -54,3 +54,15 @@ } } } + +.select-work-admin-set { + margin: 20px; + select { + width: 100%; + } + + .admin-set-title { + font-size: $h4-font-size; + margin-top: 0; + } +} diff --git a/app/controllers/concerns/hyrax/works_controller_behavior.rb b/app/controllers/concerns/hyrax/works_controller_behavior.rb index 019b67ddeb..e65dd1ca32 100644 --- a/app/controllers/concerns/hyrax/works_controller_behavior.rb +++ b/app/controllers/concerns/hyrax/works_controller_behavior.rb @@ -58,7 +58,7 @@ def new @admin_set_options = available_admin_sets # TODO: move these lines to the work form builder in Hyrax curation_concern.depositor = current_user.user_key - curation_concern.admin_set_id = admin_set_id_for_new + curation_concern.admin_set_id = params[:admin_set_id] || admin_set_id_for_new build_form end diff --git a/app/controllers/hyrax/metadata_profiles_controller.rb b/app/controllers/hyrax/metadata_profiles_controller.rb new file mode 100644 index 0000000000..3dbd305e9f --- /dev/null +++ b/app/controllers/hyrax/metadata_profiles_controller.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +module Hyrax + class MetadataProfilesController < ApplicationController + include Hyrax::ThemedLayoutController + require 'yaml' + + with_themed_layout 'dashboard' + + # GET /allinson_flex_profiles + def index + add_breadcrumbs + @metadata_profiles = Hyrax::FlexibleSchema.page(params[:profile_entries_page]) + end + + # rubocop:disable Metrics/MethodLength + def import + uploaded_io = params[:file] + if uploaded_io.blank? + redirect_to metadata_profiles_path, alert: 'Please select a file to upload' + return + end + + begin + @flexible_schema = Hyrax::FlexibleSchema.create(profile: YAML.safe_load_file(uploaded_io.path)) + + if @flexible_schema.persisted? + redirect_to metadata_profiles_path, notice: 'AllinsonFlexProfile was successfully created.' + else + redirect_to metadata_profiles_path, alert: @flexible_schema.errors.messages.to_s + end + rescue => e + redirect_to metadata_profiles_path, alert: e.message + nil + end + end + # rubocop:enable Metrics/MethodLength + + def export + @schema = Hyrax::FlexibleSchema.find(params[:metadata_profile_id]) + filename = "metadata-profile-v.#{@schema.version}.yml" + yaml_data = @schema.profile.to_hash.to_yaml(indentation: 2) + send_data yaml_data, filename: filename, type: "application/yaml" + end + + private + + def add_breadcrumbs + add_breadcrumb t(:'hyrax.controls.home'), main_app.root_path + add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path + add_breadcrumb t(:'hyrax.dashboard.metadata_profiles'), hyrax.metadata_profiles_path + end + end +end diff --git a/app/controllers/hyrax/my/works_controller.rb b/app/controllers/hyrax/my/works_controller.rb index beba532028..aefa80363a 100644 --- a/app/controllers/hyrax/my/works_controller.rb +++ b/app/controllers/hyrax/my/works_controller.rb @@ -24,6 +24,7 @@ def index add_breadcrumb t(:'hyrax.admin.sidebar.works'), hyrax.my_works_path managed_works_count @create_work_presenter = create_work_presenter_class.new(current_user) + @admin_sets_for_select = admin_sets_for_select super end @@ -47,6 +48,11 @@ def search_facet_path(args = {}) def managed_works_count @managed_works_count = Hyrax::Works::ManagedWorksService.managed_works_count(scope: self) end + + def admin_sets_for_select + source_ids = Hyrax::Collections::PermissionsService.source_ids_for_deposit(ability: current_ability, source_type: 'admin_set') + source_ids.map { |admin_set_id| [Hyrax.query_service.find_by(id: admin_set_id).title.first, admin_set_id] } + end end end end diff --git a/app/forms/concerns/hyrax/based_near_field_behavior.rb b/app/forms/concerns/hyrax/based_near_field_behavior.rb new file mode 100644 index 0000000000..208f1e84f9 --- /dev/null +++ b/app/forms/concerns/hyrax/based_near_field_behavior.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +module Hyrax + module BasedNearFieldBehavior + # Provides compatibility with the behavior of the based_near (location) controlled vocabulary form field. + # The form expects a ControlledVocabularies::Location object as input and produces a hash like those + # used with accepts_nested_attributes_for. + def self.included(descendant) + descendant.property :based_near_attributes, virtual: true, populator: :based_near_populator, prepopulator: :based_near_prepopulator + end + + private + + def based_near_populator(fragment:, **_options) + return unless respond_to?(:based_near) + adds = [] + deletes = [] + fragment.each do |_, h| + uri = RDF::URI.parse(h["id"]).to_s + if h["_destroy"] == "true" + deletes << uri + else + adds << uri + end + end + self.based_near = ((model.based_near + adds) - deletes).uniq + end + + def based_near_prepopulator + return unless respond_to?(:based_near) + self.based_near = based_near&.map do |loc| + uri = RDF::URI.parse(loc) + if uri + Hyrax::ControlledVocabularies::Location.new(uri) + else + loc + end + end + based_near ||= [] + based_near << Hyrax::ControlledVocabularies::Location.new if based_near.empty? + end + end +end diff --git a/app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb b/app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb index 19ebcd02cb..a59405479f 100644 --- a/app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb +++ b/app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb @@ -1,39 +1,10 @@ # frozen_string_literal: true module Hyrax module BasicMetadataFormFieldsBehavior - # Provides compatibility with the behavior of the based_near (location) controlled vocabulary form field. - # The form expects a ControlledVocabularies::Location object as input and produces a hash like those - # used with accepts_nested_attributes_for. - def self.included(descendant) - descendant.property :based_near_attributes, virtual: true, populator: :based_near_populator, prepopulator: :based_near_prepopulator - end - - private - - def based_near_populator(fragment:, **_options) - adds = [] - deletes = [] - fragment.each do |_, h| - uri = RDF::URI.parse(h["id"]).to_s - if h["_destroy"] == "true" - deletes << uri - else - adds << uri - end - end - self.based_near = ((model.based_near + adds) - deletes).uniq - end + extend ActiveSupport::Concern - def based_near_prepopulator - self.based_near = based_near.map do |loc| - uri = RDF::URI.parse(loc) - if uri - Hyrax::ControlledVocabularies::Location.new(uri) - else - loc - end - end - based_near << Hyrax::ControlledVocabularies::Location.new if based_near.empty? + included do + include Hyrax::BasedNearFieldBehavior end end end diff --git a/app/forms/hyrax/forms/file_set_form.rb b/app/forms/hyrax/forms/file_set_form.rb index 529a90c77c..5c361ead8a 100644 --- a/app/forms/hyrax/forms/file_set_form.rb +++ b/app/forms/hyrax/forms/file_set_form.rb @@ -5,12 +5,12 @@ module Forms ## # A form for +Hyrax::FileSet+s. class FileSetForm < Hyrax::Forms::ResourceForm - include Hyrax::FormFields(:core_metadata) + include Hyrax::FormFields(:core_metadata) unless Hyrax.config.flexible? # The fields in +:file_set_metadata+ were hardcoded into this form in a # previous version of Hyrax, but ideally in the future this metadata will # be configurable. - include Hyrax::FormFields(:file_set_metadata) + include Hyrax::FormFields(:file_set_metadata) unless Hyrax.config.flexible? include Hyrax::DepositAgreementBehavior include Hyrax::ContainedInWorksBehavior diff --git a/app/forms/hyrax/forms/pcdm_collection_form.rb b/app/forms/hyrax/forms/pcdm_collection_form.rb index 32e6cdc0f2..3d8da0eae7 100644 --- a/app/forms/hyrax/forms/pcdm_collection_form.rb +++ b/app/forms/hyrax/forms/pcdm_collection_form.rb @@ -6,7 +6,7 @@ module Forms # @api public # @see https://github.com/samvera/valkyrie/wiki/ChangeSets-and-Dirty-Tracking class PcdmCollectionForm < Hyrax::Forms::ResourceForm # rubocop:disable Metrics/ClassLength - include Hyrax::FormFields(:core_metadata) + include Hyrax::FormFields(:core_metadata) unless Hyrax.config.flexible? BannerInfoPrepopulator = lambda do |**_options| self.banner_info ||= begin diff --git a/app/forms/hyrax/forms/pcdm_object_form.rb b/app/forms/hyrax/forms/pcdm_object_form.rb index 7965f07388..bc895a157e 100644 --- a/app/forms/hyrax/forms/pcdm_object_form.rb +++ b/app/forms/hyrax/forms/pcdm_object_form.rb @@ -9,7 +9,7 @@ module Forms # Although File Sets are technically also PCDM objects, they use a separate # form class: +Hyrax::Forms::FileSetForm+. class PcdmObjectForm < Hyrax::Forms::ResourceForm - include Hyrax::FormFields(:core_metadata) + include Hyrax::FormFields(:core_metadata) unless Hyrax.config.flexible? include Hyrax::ContainedInWorksBehavior include Hyrax::DepositAgreementBehavior diff --git a/app/forms/hyrax/forms/resource_batch_edit_form.rb b/app/forms/hyrax/forms/resource_batch_edit_form.rb index 0e6fae59af..f08cab01af 100644 --- a/app/forms/hyrax/forms/resource_batch_edit_form.rb +++ b/app/forms/hyrax/forms/resource_batch_edit_form.rb @@ -2,7 +2,7 @@ module Hyrax module Forms class ResourceBatchEditForm < Hyrax::Forms::ResourceForm - include Hyrax::FormFields(:basic_metadata) + include Hyrax::FormFields(:basic_metadata) unless Hyrax.config.flexible? include Hyrax::ContainedInWorksBehavior include Hyrax::DepositAgreementBehavior diff --git a/app/forms/hyrax/forms/resource_form.rb b/app/forms/hyrax/forms/resource_form.rb index 75fb70d5e4..afda49edcc 100644 --- a/app/forms/hyrax/forms/resource_form.rb +++ b/app/forms/hyrax/forms/resource_form.rb @@ -7,6 +7,11 @@ module Forms # # This form wraps +Hyrax::ChangeSet+ in the +HydraEditor::Form+ interface. class ResourceForm < Hyrax::ChangeSet # rubocop:disable Metrics/ClassLength + # These do not get auto loaded when using a flexible schema and should instead + # be added to the individual Form classes for a work type or smart enough + # to be selective as to when they trigger + include BasedNearFieldBehavior if Hyrax.config.flexible? + ## # @api private # @@ -47,7 +52,16 @@ class ResourceForm < Hyrax::ChangeSet # rubocop:disable Metrics/ClassLength # # Forms should be initialized with an explicit +resource:+ parameter to # match indexers. - def initialize(deprecated_resource = nil, resource: nil) + def initialize(deprecated_resource = nil, resource: nil) # rubocop:disable Metrics/MethodLength + if Hyrax.config.flexible? + singleton_class.instance_variable_set("@definitions", self.class.definitions) + r = resource || deprecated_resource + Hyrax::Schema.default_schema_loader.form_definitions_for(schema: r.class.to_s, version: r.schema_version).map do |field_name, options| + singleton_class.property field_name.to_sym, options.merge(display: options.fetch(:display, true), default: []) + singleton_class.validates field_name.to_sym, presence: true if options.fetch(:required, false) + end + end + if resource.nil? if !deprecated_resource.nil? Deprecation.warn "Initializing Valkyrie forms without an explicit resource parameter is deprecated. Pass the resource with `resource:` instead." @@ -58,7 +72,7 @@ def initialize(deprecated_resource = nil, resource: nil) else super(resource) end - end + end # rubocop:enable Metrics/MethodLength class << self ## @@ -146,10 +160,20 @@ def display_additional_fields? secondary_terms.any? end + # OVERRIDE disposable 0.6.3 to make schema dynamic + def schema + Definition::Each.new(singleton_class.definitions) + end + private + # OVERRIDE valkyrie 3.0.1 to make schema dynamic + def field(field_name) + singleton_class.definitions.fetch(field_name.to_s) + end + def _form_field_definitions - self.class.definitions + singleton_class.definitions end end end diff --git a/app/helpers/hyrax/attributes_helper.rb b/app/helpers/hyrax/attributes_helper.rb new file mode 100644 index 0000000000..96aa6e53fc --- /dev/null +++ b/app/helpers/hyrax/attributes_helper.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Hyrax + module AttributesHelper + def view_options_for(presenter) + model_name = presenter.model.model_name.name.constantize + hash = Hyrax::Schema.schema_to_hash_for(model_name) || + Hyrax::Schema.schema_to_hash_for((model_name.to_s + 'Resource').safe_constantize) + + hash.select { |_, val| val['view'].present? } + end + + def conform_options(options) + hash_of_locales = options['view']['label'] || {} + current_locale = params['locale'] || I18n.locale.to_s + updated_options = options.deep_dup + return updated_options['view'].transform_keys(&:to_sym) if hash_of_locales.is_a?(String) + + # If the params locale is found in the hash of locales, use that value + if hash_of_locales[current_locale].present? + updated_options['view']['label'] = hash_of_locales[current_locale] + # If the params locale is not found, fall back to english + elsif hash_of_locales['en'] + updated_options['view']['label'] = hash_of_locales['en'] + # If the params locale is not found and english is not found, use the first value in the hash as a fallback + elsif hash_of_locales.present? && hash_of_locales['en'].nil? && hash_of_locales[current_locale].nil? + updated_options['view']['label'] = hash_of_locales.values.first + end + + updated_options['view'].transform_keys(&:to_sym) + end + end +end diff --git a/app/helpers/hyrax/hyrax_helper_behavior.rb b/app/helpers/hyrax/hyrax_helper_behavior.rb index bd1d6030df..5cebfc809c 100644 --- a/app/helpers/hyrax/hyrax_helper_behavior.rb +++ b/app/helpers/hyrax/hyrax_helper_behavior.rb @@ -19,6 +19,7 @@ module HyraxHelperBehavior include Hyrax::WorkFormHelper include Hyrax::WorkflowsHelper include Hyrax::FacetsHelper + include Hyrax::AttributesHelper ## # @return [Array] the list of all user groups diff --git a/app/models/concerns/hyrax/solr_document_behavior.rb b/app/models/concerns/hyrax/solr_document_behavior.rb index ee5125bb71..99bc881725 100644 --- a/app/models/concerns/hyrax/solr_document_behavior.rb +++ b/app/models/concerns/hyrax/solr_document_behavior.rb @@ -82,7 +82,7 @@ def valkyrie? # Method to return the model def hydra_model(classifier: nil) - ((first('has_model_ssim')&.+ 'Resource')&.safe_constantize && Hyrax.config.valkyrie_transition) || + (Hyrax.config.valkyrie_transition && (first('has_model_ssim')&.+ 'Resource')&.safe_constantize) || first('has_model_ssim')&.safe_constantize || model_classifier(classifier).classifier(self).best_model end diff --git a/app/models/hyrax/flexible_schema.rb b/app/models/hyrax/flexible_schema.rb index e0cef5eb2b..a1e3a35001 100644 --- a/app/models/hyrax/flexible_schema.rb +++ b/app/models/hyrax/flexible_schema.rb @@ -2,6 +2,10 @@ class Hyrax::FlexibleSchema < ApplicationRecord serialize :profile, coder: YAML + def self.current_version + order("created_at asc").last.profile + end + def title "#{profile['profile']['responsibility_statement']} - version #{id}" end @@ -10,6 +14,22 @@ def attributes_for(class_name) class_names[class_name] end + def schema_version + profile['m3_version'] + end + + def metadata_profile_type + profile['profile']['type'] + end + + def version + id + end + + def profile_created_at + created_at.strftime("%b %d, %Y") + end + private def class_names diff --git a/app/services/hyrax/schema_loader.rb b/app/services/hyrax/schema_loader.rb index a7d2e04b67..fc5f53dcf7 100644 --- a/app/services/hyrax/schema_loader.rb +++ b/app/services/hyrax/schema_loader.rb @@ -45,6 +45,14 @@ def index_rules_for(schema:, version: 1) end end + def view_definitions_for(schema:, version: 1) + definitions(schema, version).each_with_object({}) do |definition, hash| + next if definition.view_options.empty? + + hash[definition.name] = definition.view_options + end + end + ## # @api private class AttributeDefinition @@ -75,6 +83,12 @@ def index_keys config.fetch('index_keys', [])&.map(&:to_sym) || [] end + ## + # @return [Hash{Symbol => Object}] + def view_options + config.fetch('view', {})&.symbolize_keys || {} + end + ## # @return [Dry::Types::Type] def type diff --git a/app/views/hyrax/base/_attribute_rows.html.erb b/app/views/hyrax/base/_attribute_rows.html.erb index 557e1eaa2c..609fdb120d 100644 --- a/app/views/hyrax/base/_attribute_rows.html.erb +++ b/app/views/hyrax/base/_attribute_rows.html.erb @@ -1,21 +1,3 @@ -<%= presenter.attribute_to_html(:alternative_title, html_dl: true) %> -<%= presenter.attribute_to_html(:abstract, html_dl: true) %> -<%= presenter.attribute_to_html(:date_modified, label: t('hyrax.base.show.last_modified'), html_dl: true) %> -<%= presenter.attribute_to_html(:creator, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:contributor, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:subject, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:publisher, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:bibliographic_citation, html_dl: true) %> -<%= presenter.attribute_to_html(:language, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:identifier, render_as: :linked, search_field: 'identifier_tesim', html_dl: true) %> -<%= presenter.attribute_to_html(:keyword, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:date_created, render_as: :linked, search_field: 'date_created_tesim', html_dl: true) %> -<%= presenter.attribute_to_html(:based_near_label, html_dl: true) %> -<%= presenter.attribute_to_html(:related_url, render_as: :external_link, html_dl: true) %> -<%= presenter.attribute_to_html(:resource_type, render_as: :faceted, html_dl: true) %> -<%= presenter.attribute_to_html(:source, html_dl: true) %> -<%= presenter.attribute_to_html(:extent, html_dl: true) %> -<%= presenter.attribute_to_html(:rights_statement, render_as: :rights_statement, html_dl: true) %> -<%= presenter.attribute_to_html(:rights_notes, html_dl: true) %> -<%= presenter.attribute_to_html(:access_right, html_dl: true) %> -<%= presenter.attribute_to_html(:license, render_as: :license, html_dl: true) %> +<% view_options_for(presenter).each do |field, options| %> + <%= presenter.attribute_to_html(field.to_sym, conform_options(options)) %> +<% end %> diff --git a/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb b/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb index 69e2ccc7b5..1f35a75934 100644 --- a/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb +++ b/app/views/hyrax/dashboard/sidebar/_repository_content.html.erb @@ -14,4 +14,15 @@ <%= t('hyrax.admin.sidebar.works') %> <% end %> + <% if ENV.fetch('HYRAX_FLEXIBLE', false) %> + <% if current_ability.admin? %> + <%= menu.nav_link(hyrax.metadata_profiles_path, + class: "nav-link", + onclick: "dontChangeAccordion(event);", + title: t('hyrax.admin.sidebar.metadata_profiles')) do %> + <%= t('hyrax.admin.sidebar.metadata_profiles') %> + <% end %> + <% end %> + <% end %> + <%= render 'hyrax/dashboard/sidebar/menu_partials', menu: menu, section: :repository_content %> diff --git a/app/views/hyrax/metadata_profiles/_import_modal.html.erb b/app/views/hyrax/metadata_profiles/_import_modal.html.erb new file mode 100644 index 0000000000..da4561dfab --- /dev/null +++ b/app/views/hyrax/metadata_profiles/_import_modal.html.erb @@ -0,0 +1,20 @@ + diff --git a/app/views/hyrax/metadata_profiles/index.html.erb b/app/views/hyrax/metadata_profiles/index.html.erb new file mode 100644 index 0000000000..28f72ff7f7 --- /dev/null +++ b/app/views/hyrax/metadata_profiles/index.html.erb @@ -0,0 +1,54 @@ +<% provide :page_title, t(:'hyrax.dashboard.metadata_profiles') %> + +<% provide :page_header do %> +

<%= t(:'hyrax.admin.sidebar.metadata_profiles') %>

+
+ +
+<% end %> + +
+
+ <% if @metadata_profiles.present? %> +
+ + + + + + + + + + + + <% @metadata_profiles.order("updated_at DESC").each do |hyrax_metadata_profile| %> + + + + + + + + + + <% end %> + +
Schema VersionProfile VersionProfile TypeCreated AtActions
<%= hyrax_metadata_profile.schema_version %><%= hyrax_metadata_profile.id.to_f %><%= hyrax_metadata_profile.metadata_profile_type %><%= hyrax_metadata_profile.created_at.strftime("%b %d, %Y") %><%= link_to raw(''), hyrax.metadata_profile_export_path(hyrax_metadata_profile), target: "_blank" %>
+ + <%= page_entries_info @metadata_profiles %>
+ <%= paginate(@metadata_profiles, param_name: :metadata_profile_entries_page) %> + +
+ <% else %> +

No Metadata Schema Profiles have been created.

+ <% end %> +
+
+ + + +<%= render 'import_modal' %> diff --git a/app/views/shared/_select_work_type_modal.html.erb b/app/views/shared/_select_work_type_modal.html.erb index a9841abbd1..5eb9e6cbf5 100644 --- a/app/views/shared/_select_work_type_modal.html.erb +++ b/app/views/shared/_select_work_type_modal.html.erb @@ -7,12 +7,21 @@