diff --git a/Gemfile b/Gemfile index 6ab03734..61ecc8f3 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,8 @@ gem 'fancybox2-rails' # Used in helper classes. TODO: Confirm that this is neede gem 'gaffe' gem 'grape' gem 'grape-entity' -gem 'grape-swagger', '0.31.0' +# pinning swagger to commit that supports braces in array params; functionality is broken in next version - 0.31.0 +gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger', ref: 'da351d0f99228f31329210d21b975a64500e73ab' gem 'http' gem 'jbuilder' gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 1e376b10..cff57def 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,14 @@ GIT blacklight_range_limit (8.2.4) blacklight (>= 7.25.2, < 9) +GIT + remote: https://github.com/ruby-grape/grape-swagger + revision: da351d0f99228f31329210d21b975a64500e73ab + ref: da351d0f99228f31329210d21b975a64500e73ab + specs: + grape-swagger (0.30.1) + grape (>= 0.16.2) + GIT remote: https://github.com/samvera-deprecated/jettywrapper.git revision: 6b03c21726a83dcecf09d9b20683bfcd63f106d1 @@ -247,8 +255,6 @@ GEM grape-entity (0.10.1) activesupport (>= 3.0.0) multi_json (>= 1.3.2) - grape-swagger (0.31.0) - grape (>= 0.16.2) haml (5.2.2) temple (>= 0.8.0) tilt @@ -651,7 +657,7 @@ DEPENDENCIES gaffe grape grape-entity - grape-swagger (= 0.31.0) + grape-swagger! http jbuilder jettywrapper (>= 1.4.0)! diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 4931a218..30534de1 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -45,7 +45,7 @@ def create def upload_params params.require(:deposit) - .permit(:title, :abstract, :year, :doi, :license, :rights, :notes, :degree_program, :academic_advisor, + .permit(:title, :abstract, :year, :doi, :license, :rights, :notes, :degree_program, :academic_advisor, :current_student, :thesis_or_dissertation, :degree_earned, :embargo_date, :previously_published, :article_version, :keywords, :current_student, files: [], creators: %i[first_name last_name uni]) end diff --git a/app/javascript/src/mediaelement.js b/app/javascript/src/mediaelement.js deleted file mode 100644 index d8bef552..00000000 --- a/app/javascript/src/mediaelement.js +++ /dev/null @@ -1,27 +0,0 @@ - -$(document).ready(function(){ - MediaElementPlayer.prototype.buildbranding = function(player, controls, layers, media) { - // create the branding button, with Academic Commons logo and link back out to the Academic Commons item page. - - var branding = - $('
' + - 'Columbia Academic Commons
') - // append it to the toolbar - .appendTo(controls) - // add a click toggle event - .click(function() { - if (player.node.dataset.brandLink) { - window.open(player.node.dataset.brandLink, '_blank') - } - }); - } - - $('.mediaelement-player video, .mediaelement-player audio').each(function() { - $(this).mediaelementplayer({ - customError: '

There was an error loading this file.

', - features: ['playpause', 'current', 'progress', 'duration', 'tracks', 'volume', 'fullscreen', 'branding'], - stretching: 'responsive', - toggleCaptionsButtonWhenOnlyOne: true - }) - }); -}); diff --git a/app/javascript/src/upload/current-student.js b/app/javascript/src/upload/current-student.js index 3b19ce4f..d25ae028 100644 --- a/app/javascript/src/upload/current-student.js +++ b/app/javascript/src/upload/current-student.js @@ -1,10 +1,22 @@ $(document).ready(function () { + // onChange only fires when radio button is selected + $("form#upload input#deposit_current_student_true") + .change(function () { + document.getElementsByClassName("student-section")[0].style.display = + "block"; + }) + .change(); - $('form#upload input#deposit_current_student').change(function () { - document.getElementsByClassName('student-section')[0].style.display = "none"; - if (document.getElementById('deposit_current_student').checked == true) { - document.getElementsByClassName('student-section')[0].style.display = "block"; - } - }).change(); + $("form#upload input#deposit_current_student_false") + .change(function () { + document.getElementsByClassName("student-section")[0].style.display = + "none"; + }) + .change(); + //check if button is already selected on page render, ie after validation failure + if ($("form#upload input#deposit_current_student_true").is(":checked")) { + document.getElementsByClassName("student-section")[0].style.display = + "block"; + } }); diff --git a/app/models/deposit.rb b/app/models/deposit.rb index 1995aee8..403c2796 100644 --- a/app/models/deposit.rb +++ b/app/models/deposit.rb @@ -28,7 +28,7 @@ class Deposit < ApplicationRecord }.freeze before_validation :clean_up_creators - before_save :convert_embargo_value_to_date_string, :finalize_notes_contents + before_save :finalize_notes_contents # validates_presence_of :agreement_version # validates_presence_of :name @@ -41,7 +41,7 @@ class Deposit < ApplicationRecord validate :one_creator_must_be_present, on: :create validate :cco_must_be_selected, if: proc { |a| a.rights == RIGHTS_OPTIONS['No Copyright'] } validates :title, :abstract, :year, :rights, :files, presence: true, on: :create - validates :previously_published, inclusion: { in: [true, false] }, on: :create + validates :previously_published, :current_student, inclusion: { in: [true, false] }, on: :create validates :rights, inclusion: { in: RIGHTS_OPTIONS.values }, on: :create validates :license, inclusion: { in: LICENSE_OPTIONS }, on: :create, if: proc { |a| a.license.present? } validates :degree_program, :academic_advisor, :thesis_or_dissertation, @@ -180,21 +180,12 @@ def finalize_notes_contents #{self.notes} Degree Program: #{self.degree_program} - Advisor Name: #{self.academic_advisor} + Academic Advisor: #{self.academic_advisor} Thesis or Dissertation: #{self.thesis_or_dissertation} Degree Earned: #{self.degree_earned} - Embargo Date: #{self.embargo_date} + Embargo Year(s): #{self.embargo_date} Previously Published: #{self.previously_published} Article Version: #{self.article_version} Keywords: #{self.keywords} TEXT end - -def convert_embargo_value_to_date_string - return self.embargo_date = '' unless embargo_date&.present? - - embargo_date_int = Integer(self.embargo_date) - return self.embargo_date = '' unless embargo_date_int.positive? - - self.embargo_date = embargo_date_int.year.from_now.strftime('%-Y-%-m-%-y') -end diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index 717500f5..235e0521 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -72,10 +72,13 @@ -
-

Current student?

- <%= form.check_box :current_student %> - <%= form.label :current_student, 'Check here if you are a current student at Columbia or one of its affiliate institutions.' %> +
+

Current student*

+

Are you a current student at Columbia or one of its affiliate institutions?

+ <%= form.radio_button(:current_student, true) %> + <%= form.label(:current_student, 'Yes') %>
+ <%= form.radio_button(:current_student, false) %> + <%= form.label(:current_student, 'No') %>
@@ -86,7 +89,8 @@
- <%= form.label(:academic_advisor, 'Academic Advisor*', class: 'control-label') %> +

Academic Advisor*

+

(If you are uploading a thesis, please give us the name of your thesis advisor.)

<%= form.text_field(:academic_advisor) %>
diff --git a/db/schema.rb b/db/schema.rb index 6c0e4cc2..9f62e6af 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_12_08_202313) do +ActiveRecord::Schema.define(version: 2023_05_18_134528) do create_table "active_storage_attachments", force: :cascade do |t| t.string "name", null: false diff --git a/spec/controllers/uploads_controller_spec.rb b/spec/controllers/uploads_controller_spec.rb index c9411de0..7025e49d 100644 --- a/spec/controllers/uploads_controller_spec.rb +++ b/spec/controllers/uploads_controller_spec.rb @@ -18,7 +18,8 @@ rights: 'http://rightsstatements.org/vocab/InC/1.0/', previously_published: true, creators: [{ first_name: 'Jane', last_name: 'Doe', uni: 'abc123' }], - files: [file] + files: [file], + current_student: false } } end diff --git a/spec/factories/deposit.rb b/spec/factories/deposit.rb index 28326b62..5691344f 100644 --- a/spec/factories/deposit.rb +++ b/spec/factories/deposit.rb @@ -14,6 +14,7 @@ rights { 'http://rightsstatements.org/vocab/InC/1.0/' } license { 'https://creativecommons.org/licenses/by/4.0/' } previously_published { true } + current_student { false } after(:build) do |deposit| deposit.files.attach( diff --git a/spec/features/upload_spec.rb b/spec/features/upload_spec.rb index b19b364d..93f1b5f5 100644 --- a/spec/features/upload_spec.rb +++ b/spec/features/upload_spec.rb @@ -68,8 +68,8 @@ expect(page).to have_field 'Notes' end - it 'renders student checkbox' do - expect(page).to have_unchecked_field('Check here if you are a current student at Columbia or one of its affiliate institutions.') + it 'renders student radio buttons' do + expect(page).to have_unchecked_field 'deposit[current_student]' end it 'contains creator field with user\'s information' do @@ -89,9 +89,9 @@ expect(page).to have_css 'input[type="file"]', visible: false end - context 'when user selects current student' do + context 'when user is a current student' do before do - check 'Check here if you are a current student at Columbia or one of its affiliate institutions.' + choose('deposit[current_student]', option: true) end it 'contains degree program input' do @@ -99,7 +99,11 @@ end end - context 'when user does not select current student' do + context 'when user is not a current student' do + before do + choose('deposit[current_student]', option: false) + end + it 'does not contain academic advisor input' do expect(page).not_to have_css 'input[name="deposit[academic_advisor]"]', visible: true end @@ -107,11 +111,11 @@ context 'when student submits form with all required data' do before do - check 'Check here if you are a current student at Columbia or one of its affiliate institutions.' + choose('deposit[current_student]', option: true) fill_in 'Title*', with: 'Test Deposit' fill_in 'Abstract*', with: 'Blah Blah Blah' fill_in 'Year Created*', with: '2017' - fill_in 'Academic Advisor*', with: 'Advisor Name' + fill_in 'deposit[academic_advisor]', with: 'Advisor Name' fill_in 'Degree Program*', with: 'Economics' choose 'deposit[thesis_or_dissertation]', option: 'dissertation' choose 'deposit[license]', option: 'https://creativecommons.org/publicdomain/zero/1.0/' @@ -140,7 +144,7 @@ context 'when student submits form with missing required data' do before do - check 'Check here if you are a current student at Columbia or one of its affiliate institutions.' + choose('deposit[current_student]', option: true) fill_in 'Title*', with: 'Test Deposit' fill_in 'Abstract*', with: 'Blah Blah Blah' fill_in 'Year Created*', with: '2017'