Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Merge pull request #59 from MITLibraries/47_update_form
Browse files Browse the repository at this point in the history
47 update form
  • Loading branch information
JPrevost committed Feb 23, 2016
2 parents 4743971 + 58fd73a commit 874ff5e
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 46 deletions.
3 changes: 0 additions & 3 deletions app/assets/stylesheets/submission.css

This file was deleted.

11 changes: 5 additions & 6 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
# documents :string
# status :string
# handle :string
# uuid :string
# pub_date :datetime
# funders :string
#

class SubmissionsController < ApplicationController
Expand Down Expand Up @@ -87,8 +86,8 @@ def callback_uri
end

def submission_params
params.require(:submission).permit(:title, :agreed_to_license, :author,
:journal, :doi, :grant_number, :doe,
:documents_cache, documents: [])
params.require(:submission).permit(:title, :agreed_to_license, :pub_date,
:journal, :doi, :documents_cache,
documents: [], funders: [])
end
end
1 change: 0 additions & 1 deletion app/models/epdcx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def work(submission)
statement('http://libraries.mit.edu/xmlns/callback', @callback_uri)
scholarly_work
statement('http://purl.org/dc/elements/1.1/title', submission.title)
statement('http://purl.org/dc/elements/1.1/creator', submission.author)

@xml['epdcx'].statement('epdcx:propertyURI' =>
'http://purl.org/eprint/terms/isExpressedAs',
Expand Down
20 changes: 17 additions & 3 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
# documents :string
# status :string
# handle :string
# uuid :string
# pub_date :datetime
# funders :string
#

class Submission < ActiveRecord::Base
Expand All @@ -25,9 +24,11 @@ class Submission < ActiveRecord::Base
validates :title, presence: true
validates :agreed_to_license, inclusion: { in: [true] }
validates :documents, presence: true
validates :funders, presence: true
validates :handle, format: URI.regexp, allow_nil: true
validates :handle, presence: true, if: :status_approved?
serialize :documents, JSON
serialize :funders, JSON
before_create :generate_uuid

def status_approved?
Expand Down Expand Up @@ -77,4 +78,17 @@ def document_uri(document)
"https:#{document}"
end
end

def valid_funders
['Department of Defense (DoD)',
'Department of Energy (DOE)',
'Department of Transportation (DOT)',
'National Aeronautics and Space Administration (NASA)',
'National Institutes of Health (NIH)',
'National Center for Atmospheric Research (NCAR)',
'National Ocean and Atmospheric Administration (NOAA)',
'National Science Foundation (NSF)',
'United States Department of Agriculture (USDA)',
'None / Other']
end
end
28 changes: 16 additions & 12 deletions app/views/submissions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@
data: { 'form-data' => (@s3_direct_post.fields),
'url' => @s3_direct_post.url,
'host' => URI.parse(@s3_direct_post.url).host } },
layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
layout: :horizontal, label_col: "col-sm-2",
control_col: "col-sm-10") do |f| %>
<%= f.alert_message "Please fix the errors below." %>
<%= f.text_field :author %>
<%= f.text_field :title %>
<%= f.text_field :journal %>
<%= f.text_field :doi %>
<%= f.text_field :grant_number %>
<%= f.text_field :journal, placeholder: 'Optional' %>
<%= f.text_field :doi, label: 'DOI', placeholder: 'Optional' %>
<%= f.date_select :pub_date, discard_day: true, include_blank: true,
label: 'Publication Date',
help: 'If not yet published, please enter an estimated Publication Date.'%>
<%= f.form_group :doe do %>
<%= f.check_box :doe, label: "This submission was funded in part by grants from the DOE." %>
<% end %>
<%= f.form_group :agreed_to_license do %>
<%= f.form_group :agreed_to_license, label: { text: "Authorized", class: 'required' } do %>
<%= f.check_box :agreed_to_license,
label: "I am authorized to submit this article." %>
<% end %>
<%= f.file_field :documents, multiple: true %>
<%= f.select :funders,
options_for_select(@submission.valid_funders, @submission.funders),
{ include_hidden: false, help: 'Multiple funder selections are allowed' },
{ multiple: true, size: 10 } %>
<%= f.file_field :documents, multiple: true,
help: 'Drag and Drop files or click "Choose Files"' %>
<% if @submission.documents? %>
<%= f.form_group :documents do %>
Expand Down Expand Up @@ -61,7 +65,7 @@ $(function() {
paramName: 'file', // S3 does not like nested name fields i.e. name="user[avatar_url]"
dataType: 'XML', // S3 returns XML if success_action_status is set to 201
replaceFileInput: true,
acceptFileTypes: /(\.|\/)(pdf)$/i,
//acceptFileTypes: /(\.|\/)(pdf)$/i,
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
progressBar.css('width', progress + '%')
Expand Down
9 changes: 8 additions & 1 deletion app/views/submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
<li>Submitted: <%= @submission.created_at %></li>
<li>Status: <%= @submission.status %></li>
<li>Title: <%= @submission.title %></li>
<li>Funder(s): </li>
<li>Expected Publication Date: <%= @submission.pub_date.strftime("%B %Y") if @submission.pub_date %></li>
<li>Funder(s):
<ul>
<% @submission.funders.each do |funder| %>
<li><%= funder %></li>
<% end %>
</ul>
</li>
<li>File(s):
<ul>
<% @submission.documents.each do |doc| %>
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20160222142533_update_submission.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UpdateSubmission < ActiveRecord::Migration
def change
change_table :submissions do |t|
t.remove :author, :doe, :grant_number
t.datetime :pub_date
t.string :funders
end
end
end
7 changes: 3 additions & 4 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160202152401) do
ActiveRecord::Schema.define(version: 20160222142533) do

create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
Expand All @@ -34,16 +34,15 @@
t.string "title", null: false
t.string "journal"
t.string "doi"
t.string "author"
t.boolean "doe"
t.string "grant_number"
t.boolean "agreed_to_license"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "documents"
t.string "status"
t.string "handle"
t.string "uuid"
t.datetime "pub_date"
t.string "funders"
end

add_index "submissions", ["user_id"], name: "index_submissions_on_user_id"
Expand Down
5 changes: 2 additions & 3 deletions test/controllers/submissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
# documents :string
# status :string
# handle :string
# uuid :string
# pub_date :datetime
# funders :string
#

require 'test_helper'
Expand Down
10 changes: 7 additions & 3 deletions test/features/submission_create_pages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def base_valid_form
fill_in('Journal', with: 'Super Mega Journal')
fill_in('Title', with: 'Alphabetical Order is Good Enough')
check('I am authorized to submit this article.')
select 'Department of Energy (DOE)', from: 'submission_funders'
end

test 'requires signed_in user' do
Expand Down Expand Up @@ -87,13 +88,16 @@ def base_valid_form
assert_equal(2, @sub.documents.count)
end

test 'non pdf cannot be attached' do
test 'non pdf can be attached' do
subs = Submission.count
base_valid_form
attach_file('submission[documents][]',
File.absolute_path('./test/fixtures/a.txt'))
assert page.has_content?('Only PDF files are accepted at this time')
assert_equal(subs, Submission.count)
refute page.has_content?('Only PDF files are accepted at this time')
click_on('Create Submission')
assert_equal(subs + 1, Submission.count)
@sub = Submission.last
assert(@sub.documents.first.include?('a.txt'))
end

test 'pdf retained across invalid form submission' do
Expand Down
11 changes: 5 additions & 6 deletions test/fixtures/submissions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
# documents :string
# status :string
# handle :string
# uuid :string
# pub_date :datetime
# funders :string
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
Expand All @@ -25,6 +24,7 @@ sub_one:
title: 'Popcorn is a fruit.'
agreed_to_license: true
documents: "[\"//s3.amazonaws.com/mitquicksubmitdev/uploads/ea656123-f24f-4b12-9c78-17399338a6d6/b_pdf.pdf\", \"//s3.amazonaws.com/mitquicksubmitdev/uploads/89ce4e35-8573-4def-8114-8767365c954e/a_pdf.pdf\"]"
funders: '["Department of Energy (DOE)"]'
user: one
uuid: 7648b505-af79-4a2b-abcb-2727f716100c

Expand All @@ -33,17 +33,16 @@ sub_two:
user: two
journal: 'Journal of Popcorn Management'
doi: 'doi:10.10.1038/nphys1170'
author: 'Lastname, Firstname'
doe: true
grant_number: 'asdf123'
agreed_to_license: true
documents: "[\"//s3.amazonaws.com/mitquicksubmitdev/uploads/ea656123-f24f-4b12-9c78-17399338a6d6/b_pdf.pdf\"]"
funders: '["Department of Energy (DOE)"]'
uuid: a481170a-8337-4adc-b5b6-289b1037bd76

sub_deposited:
title: 'popcorn soup'
agreed_to_license: true
documents: "[\"//s3.amazonaws.com/mitquicksubmitdev/uploads/ea656123-f24f-4b12-9c78-17399338a6d6/b_pdf.pdf\", \"//s3.amazonaws.com/mitquicksubmitdev/uploads/89ce4e35-8573-4def-8114-8767365c954e/a_pdf.pdf\"]"
funders: '["Department of Energy (DOE)"]'
user: one
uuid: 7648b505-af79-4a2b-abcb-2727f716100c
status: 'deposited'
14 changes: 10 additions & 4 deletions test/models/submission_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
# title :string not null
# journal :string
# doi :string
# author :string
# doe :boolean
# grant_number :string
# agreed_to_license :boolean
# created_at :datetime not null
# updated_at :datetime not null
# documents :string
# status :string
# handle :string
# uuid :string
# pub_date :datetime
# funders :string
#

require 'test_helper'
Expand Down Expand Up @@ -51,6 +50,12 @@ class SubmissionTest < ActiveSupport::TestCase
assert_not sub.valid?
end

test 'invalid without funders' do
sub = submissions(:sub_one)
sub.funders = ''
assert_not sub.valid?
end

test 'valid with uri handle' do
sub = submissions(:sub_one)
sub.handle = 'http://example.com/123456/789.0'
Expand All @@ -73,7 +78,8 @@ class SubmissionTest < ActiveSupport::TestCase
# fixtures bypass callbacks, so this is all manual.
user = users(:one)
sub = Submission.create(title: 'manual sub', agreed_to_license: true,
documents: ['b_pdf.pdf'], user: user)
documents: ['b_pdf.pdf'], user: user,
funders: ['DOE'])
assert(sub.uuid)
end

Expand Down

0 comments on commit 874ff5e

Please sign in to comment.