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

Create instruments work type and pathway #1595

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ Style/EmptyCaseCondition:
Layout/LineLength:
Exclude:
- 'spec/features/dashboard/work_version_form_spec.rb'
- 'spec/forms/work_deposit_pathways/instrument/publish_form_spec.rb'

2 changes: 1 addition & 1 deletion app/components/citation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def render?
end

def citation_display
return unless deposit_pathway.data_and_code?
return unless deposit_pathway.data_and_code? || deposit_pathway.instrument?

"#{creators_citation_display}(#{year_published}). #{work_version.title} [Data set]. Scholarsphere.#{doi_url}"
end
Expand Down
4 changes: 3 additions & 1 deletion app/components/delete_resource_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def work_version?
'WorkDepositPathway::ScholarlyWorks::PublishForm',
'WorkDepositPathway::General::DetailsForm',
'WorkDepositPathway::DataAndCode::DetailsForm',
'WorkDepositPathway::DataAndCode::PublishForm'
'WorkDepositPathway::DataAndCode::PublishForm',
'WorkDepositPathway::Instrument::DetailsForm',
'WorkDepositPathway::Instrument::PublishForm'
].include?(type)
end

Expand Down
1 change: 1 addition & 0 deletions app/components/thumbnail_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def icon_map
dataset: 'analytics',
dissertation: 'subject',
image: 'image',
instrument: 'precision_manufacturing',
journal: 'subject',
map_or_cartographic_material: 'map',
masters_culminating_experience: 'landscape',
Expand Down
13 changes: 12 additions & 1 deletion app/components/work_version_metadata_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ class WorkVersionMetadataComponent < BaseMetadataComponent
:based_near,
:related_url,
:source,
:deposited_at
:deposited_at,
:owner,
:manufacturer,
:model,
:instrument_type,
:measured_variable,
:available_date,
:decommission_date,
:related_identifier,
:alternative_identifier,
:instrument_resource_type,
:funding_reference
].freeze

MINI_ATTRIBUTES = [
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ def index
config.add_show_field 'language_tesim', label: 'Language'
config.add_show_field 'identifier_tesim', label: 'Identifier'
config.add_show_field 'based_near_tesim', label: 'Based Near'
config.add_show_field 'owner_tesim', label: 'Owner'
config.add_show_field 'manufacturer_tesim', label: 'Manufacturer'
config.add_show_field 'model_tesim', label: 'Model'
config.add_show_field 'instrument_type_tesim', label: 'Instrument Type'
config.add_show_field 'measured_variable_tesim', label: 'Measured Variable'
config.add_show_field 'available_date_tesim', label: 'Available Date'
config.add_show_field 'decommission_date_tesim', label: 'Decommission Date'
config.add_show_field 'related_identifier_tesim', label: 'Related Identifier'
config.add_show_field 'alternative_identifier_tesim', label: 'Alternative Identifier'
config.add_show_field 'instrument_resource_type_tesim', label: 'Resource Type'
config.add_show_field 'funding_reference_tesim', label: 'Funding Reference'
Smullz622 marked this conversation as resolved.
Show resolved Hide resolved
config.add_show_field 'related_url_tesim', label: 'Related URL'
config.add_show_field 'source_tesim', label: 'Source'
config.add_show_field 'version_number_isi', label: 'Version Number'
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/dashboard/form/publish_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def work_version_params
:published_date,
:depositor_agreement,
:draft_curation_requested,
:owner,
:manufacturer,
:model,
:instrument_type,
:measured_variable,
:available_date,
:decommission_date,
:related_identifier,
:alternative_identifier,
:instrument_resource_type,
:funding_reference,
:mint_doi_requested,
keyword: [],
contributor: [],
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/dashboard/form/work_version_details_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ def work_version_params
:rights,
:version_name,
:published_date,
:owner,
:manufacturer,
:model,
:instrument_type,
:measured_variable,
:available_date,
:decommission_date,
:related_identifier,
:alternative_identifier,
:instrument_resource_type,
:funding_reference,
keyword: [],
contributor: [],
publisher: [],
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/dashboard/work_versions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,17 @@ def metadata_params
:rights,
:version_name,
:published_date,
:owner,
:manufacturer,
:model,
:instrument_type,
:measured_variable,
:available_date,
:decommission_date,
:related_identifier,
:alternative_identifier,
:instrument_resource_type,
:funding_reference,
keyword: [],
contributor: [],
publisher: [],
Expand Down
119 changes: 118 additions & 1 deletion app/forms/work_deposit_pathway.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def details_form
ScholarlyWorks::DetailsForm.new(resource)
elsif data_and_code?
DataAndCode::DetailsForm.new(resource)
elsif instrument?
Instrument::DetailsForm.new(resource)
else
General::DetailsForm.new(resource)
end
Expand All @@ -20,6 +22,8 @@ def publish_form
ScholarlyWorks::PublishForm.new(resource)
elsif data_and_code?
DataAndCode::PublishForm.new(resource)
elsif instrument?
Instrument::PublishForm.new(resource)
else
resource
end
Expand All @@ -34,7 +38,7 @@ def allows_curation_request?
end

def allows_mint_doi_request?
data_and_code? && @resource.doi_blank? && DoiMintingStatus.new(@resource.work).blank?
(data_and_code? || instrument?) && @resource.doi_blank? && DoiMintingStatus.new(@resource.work).blank?
end

def work?
Expand All @@ -45,6 +49,10 @@ def data_and_code?
Work::Types.data_and_code.include?(work_type)
end

def instrument?
Work::Types.instrument.include?(work_type)
end

private

attr_reader :resource
Expand Down Expand Up @@ -282,4 +290,113 @@ def includes_readme_file
end
end
end

module Instrument
class DetailsForm < DetailsFormBase
def self.form_fields
WorkVersionFormBase::COMMON_FIELDS.union(
%w{
title
owner
identifier
manufacturer
model
instrument_type
measured_variable
available_date
decommission_date
related_identifier
alternative_identifier
instrument_resource_type
funding_reference
}
).freeze
end

form_fields.each do |attr_name|
delegate attr_name, to: :work_version, prefix: false
delegate "#{attr_name}=", to: :work_version, prefix: false
end

def form_partial
'instrument_work_version'
end
end

class PublishForm < WorkVersionFormBase
def self.form_fields
WorkVersionFormBase::COMMON_FIELDS.union(
%w{
title
owner
identifier
manufacturer
model
instrument_type
measured_variable
available_date
decommission_date
related_identifier
alternative_identifier
instrument_resource_type
funding_reference
rights
depositor_agreement
contributor
}
).freeze
end

form_fields.each do |attr_name|
delegate attr_name, to: :work_version, prefix: false
delegate "#{attr_name}=", to: :work_version, prefix: false
end

validate :includes_readme_file_and_image,
if: :published?

validates :decommission_date,
edtf_date: true

validates :available_date,
edtf_date: true

def form_partial
'instrument_work_version'
end

delegate :aasm_state=,
:aasm_state,
:publish,
:file_resources,
:work_attributes=,
:creators_attributes=,
:creators,
:contributor,
:file_version_memberships,
:initial_draft?,
:aasm,
:update_column,
:draft_curation_requested=,
:mint_doi_requested=,
:set_thumbnail_selection,
:set_publisher_as_scholarsphere,
to: :work_version,
prefix: false

private

def includes_readme_file_and_image
unless file_resources.find do |fr|
fr.file_data['metadata']['size'].positive? &&
fr.file_data['metadata']['filename'] =~ /readme/i
end && file_resources.find do |fr|
(fr.file_data['metadata']['filename'] !~ /readme/i &&
fr.file_data['metadata']['filename'] =~ /png|jpeg|tiff/i)
end
errors.add(:file_resources, :readme_and_image)
end
end
end
end
end
18 changes: 18 additions & 0 deletions app/javascript/controllers/work_type_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Controller } from 'stimulus'

export default class extends Controller {
static targets = ['workTypeSelect', 'helpText']

connect () {
this.toggleHelpText()
this.workTypeSelectTarget.addEventListener('change', () => this.toggleHelpText())
}

toggleHelpText () {
if (this.workTypeSelectTarget.value === 'instrument') {
this.helpTextTarget.style.display = 'block'
} else {
this.helpTextTarget.style.display = 'none'
}
}
}
8 changes: 7 additions & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Work < ApplicationRecord

module Types
def self.all
general.union(scholarly_works).union(data_and_code).freeze
general.union(scholarly_works).union(data_and_code).union(instrument).freeze
end

def self.general
Expand Down Expand Up @@ -102,6 +102,12 @@ def self.data_and_code
].freeze
end

def self.instrument
%w[
instrument
].freeze
end

def self.default
'dataset'
end
Expand Down
37 changes: 36 additions & 1 deletion app/models/work_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ class WorkVersion < ApplicationRecord
identifier: [:string, array: true, default: []],
based_near: [:string, array: true, default: []],
related_url: [:string, array: true, default: []],
source: [:string, array: true, default: []]
source: [:string, array: true, default: []],
owner: :string,
manufacturer: :string,
model: :string,
instrument_type: :string,
measured_variable: :string,
available_date: :string,
decommission_date: :string,
Comment on lines +40 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't notice this before. We should run these dates through the date validation that published_date runs through below:

validates :published_date,
            presence: true,
            edtf_date: true,
            if: :published?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the EdtfDate module #valid? required the date to be a valid and present to return true so an empty available and/or decommission date would throw an error. This feels redundant because presence: true on published_date already handles this. I modified it so the module just validates format, allowing for blank values, and let presence: true handle that validation as needed.

related_identifier: :string,
alternative_identifier: :string,
instrument_resource_type: :string,
funding_reference: :string

belongs_to :work,
inverse_of: :versions
Expand Down Expand Up @@ -160,6 +171,14 @@ def label(id)
edtf_date: true,
if: :published?

validates :decommission_date,
edtf_date: true,
if: :published?

validates :available_date,
edtf_date: true,
if: :published?

validates :description,
presence: true,
if: :published?
Expand Down Expand Up @@ -188,6 +207,7 @@ def label(id)
to: :published,
after: Proc.new {
work.try(:update_deposit_agreement)
set_publisher_as_scholarsphere if work_type == 'instrument'
self.reload_on_index = true
}
end
Expand Down Expand Up @@ -227,6 +247,17 @@ def label(id)
rights
subtitle
version_name
owner
manufacturer
model
instrument_type
measured_variable
available_date
decommission_date
related_identifier
alternative_identifier
instrument_resource_type
funding_reference
].each do |field|
define_method "#{field}=" do |val|
super(val.presence)
Expand Down Expand Up @@ -299,6 +330,10 @@ def set_thumbnail_selection
end
end

def set_publisher_as_scholarsphere
metadata['publisher'] = ['Scholarsphere']
end

def initial_draft?
version_number == 1 &&
(draft? || temporarily_published_draft?)
Expand Down
Loading