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 instrument type and pathway #1596

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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: '',
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: 'Instrument type'
config.add_show_field 'funding_reference_tesim', label: 'Funding reference'
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
12 changes: 12 additions & 0 deletions app/controllers/dashboard/form/publish_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def update
# WorkVersion#set_thumbnail_selection may be unreliable if the Shrine::ThumbnailJob is delayed
@resource.set_thumbnail_selection
@resource.indexing_source = Proc.new { nil }
@resource.set_publisher_as_scholarsphere if deposit_pathway.instrument?
@resource.save
@resource.publish
elsif request_curation? && [email protected]_curation_requested
Expand Down Expand Up @@ -121,6 +122,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
113 changes: 112 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,107 @@ 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?

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
28 changes: 27 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,
related_identifier: :string,
alternative_identifier: :string,
instrument_resource_type: :string,
funding_reference: :string

belongs_to :work,
inverse_of: :versions
Expand Down Expand Up @@ -227,6 +238,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 +321,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