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

dynamic forms that load flexible metadata #6844

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5ec7d1b
:construction: WIP: Port over AFlex UI to upload profile
Jun 4, 2024
2b95bb1
Add admin set selection to worktype modal
Jun 6, 2024
449de96
Relocated the Metadata Profiles link
kirkkwang Jun 12, 2024
2e351d6
Merge branch 'flexible_metadata' into metadata-profiles-ui
kirkkwang Jun 12, 2024
c5be4bc
Make metadata profiles index work
kirkkwang Jun 12, 2024
7cd2eff
Make export work
kirkkwang Jun 13, 2024
121787d
Make it possible to create more schemas
kirkkwang Jun 13, 2024
2b087c6
Favoring fetch over [] to follow existing pattern
kirkkwang Jun 13, 2024
0450385
Add hint text to modal
kirkkwang Jun 13, 2024
3737db8
Update translations
kirkkwang Jun 13, 2024
e8c6664
Merge branch 'flexible_metadata' into metadata-profiles-ui
kirkkwang Jun 13, 2024
9a61fd8
Merge branch 'flexible_metadata' into metadata-profiles-ui
kirkkwang Jun 13, 2024
bdaa9ee
Remove locked_at and locked_by_id
kirkkwang Jun 14, 2024
d8e9189
Merge branch 'flexible_metadata' into metadata-profiles-ui
kirkkwang Jun 19, 2024
c8d0e85
Merge branch 'flexible_metadata' into metadata-profiles-ui
kirkkwang Jun 20, 2024
a40f18d
Move db query into the controller
kirkkwang Jun 20, 2024
d743501
Rename admin set dropdown options
Jun 20, 2024
c495c34
Add guard for @admin_sets_for_select
kirkkwang Jun 20, 2024
25d722f
Merge branch 'flexible_metadata' into flexible_double_combo
kirkkwang Jun 24, 2024
fd6cea9
Merge branch 'metadata-profiles-ui' into flexible_double_combo
kirkkwang Jun 24, 2024
8b95caf
Merge branch 'select-admin-set-prior-to-worktype' into flexible_doubl…
kirkkwang Jun 24, 2024
62fefce
Rubocop fixes
kirkkwang Jun 24, 2024
bb652c5
Merge branch 'metadata-profiles-ui' into flexible_double_combo
kirkkwang Jun 24, 2024
deac768
dynamic forms that load flexible metadata
orangewolf Jun 24, 2024
18125d7
Merge branch 'flexible_forms' into flexible_double_combo
orangewolf Jun 24, 2024
5d870fb
Merge branch 'flexible_double_combo' of https://github.com/samvera/hy…
orangewolf Jun 24, 2024
3af2f31
Merge branch 'flexible_metadata' into flexible_forms
orangewolf Jun 25, 2024
3e06bd1
remove some false starts and debug code
orangewolf Jun 25, 2024
a5ba06b
Merge branch 'flexible_metadata' into flexible_forms
orangewolf Jun 25, 2024
0a761ef
Merge branch 'flexible_metadata' into flexible_double_combo
orangewolf Jun 25, 2024
3158922
Merge branch 'flexible_forms' into flexible_double_combo
orangewolf Jun 25, 2024
55fd95a
WIP getting attribute_rows to be dynamic
kirkkwang Jun 25, 2024
3a601f5
🧹 Enables dynamic display for attribute rows
Jun 25, 2024
40d33bf
🚧 WIP - handle dynamic translations
Jun 25, 2024
536f87c
Expand support for i18n labels
kirkkwang Jun 25, 2024
d6e0ea9
Merge branch 'flexible_metadata' into flexible_forms
kirkkwang Jun 25, 2024
b1de02b
Rubocop fixes
kirkkwang Jun 25, 2024
d7a2d1d
Merge branch 'flexible_double_combo' into flexible_forms
kirkkwang Jun 26, 2024
f860fd4
Fix return logic
kirkkwang Jun 26, 2024
631732c
Add flexible conditional
kirkkwang Jun 26, 2024
55b1d0a
Merge pull request #6851 from samvera/flexible_forms
kirkkwang Jun 26, 2024
e060c84
Add flexible conditional
kirkkwang Jun 26, 2024
1fc5d05
Merge branch 'flexible_double_combo' into flexible_forms
kirkkwang Jun 26, 2024
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
4 changes: 2 additions & 2 deletions .dassie/app/forms/collection_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .dassie/app/forms/generic_work_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
4 changes: 2 additions & 2 deletions .dassie/app/forms/monograph_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
4 changes: 2 additions & 2 deletions .dassie/app/indexers/collection_resource_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .dassie/app/indexers/monograph_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .koppie/app/forms/collection_resource_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .koppie/app/forms/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
4 changes: 2 additions & 2 deletions .koppie/app/forms/monograph_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
4 changes: 2 additions & 2 deletions .koppie/app/indexers/collection_resource_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .koppie/app/indexers/generic_work_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .koppie/app/indexers/monograph_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .koppie/config/metadata_profiles/m3_profile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ properties:
- Hyrax::FileSet
- CollectionResource
- GenericWork
- Monograph
cardinality:
minimum: 1
multi_value: true
Expand Down Expand Up @@ -77,6 +78,7 @@ properties:
- Hyrax::FileSet
- CollectionResource
- GenericWork
- Monograph
cardinality:
minimum: 0
maximum: 1
Expand All @@ -94,6 +96,7 @@ properties:
- Hyrax::FileSet
- CollectionResource
- GenericWork
- Monograph
cardinality:
minimum: 0
maximum: 1
Expand All @@ -111,6 +114,7 @@ properties:
- Hyrax::FileSet
- CollectionResource
- GenericWork
- Monograph
cardinality:
minimum: 0
maximum: 1
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/hyrax/select_work_type.es6
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
12 changes: 12 additions & 0 deletions app/assets/stylesheets/hyrax/_select_work_type.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@
}
}
}

.select-work-admin-set {
margin: 20px;
select {
width: 100%;
}

.admin-set-title {
font-size: $h4-font-size;
margin-top: 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 54 additions & 0 deletions app/controllers/hyrax/metadata_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions app/controllers/hyrax/my/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
42 changes: 42 additions & 0 deletions app/forms/concerns/hyrax/based_near_field_behavior.rb
Original file line number Diff line number Diff line change
@@ -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
35 changes: 3 additions & 32 deletions app/forms/concerns/hyrax/basic_metadata_form_fields_behavior.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions app/forms/hyrax/forms/file_set_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/forms/hyrax/forms/pcdm_collection_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/forms/hyrax/forms/pcdm_object_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/forms/hyrax/forms/resource_batch_edit_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading