Skip to content

Commit

Permalink
Adding Save, Next and Previous buttons to the wizard form (#1729)
Browse files Browse the repository at this point in the history
* Adding Save, Next and Previois buttons to the wizard form

* adding previous, next, and save on the attachment select page

* woowoo 🚨

* Add previous and next for file_upload and review inclind adding it to the tests
Also changed the spacing to make each page more visible

* testing the alternate file upload path

* Updating tests to click on the new button text
Also completed the other file path test

* Removing save concept from step zero of the wizard.
Once you decide to create a work you can not go back... The DOI gets minted

* Fixing a couple more tests

---------

Co-authored-by: HyppoliteJ <jh6441@princeton.edu>
  • Loading branch information
carolyncole and JaymeeH committed Apr 3, 2024
1 parent cc183cd commit b546c01
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 127 deletions.
11 changes: 11 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ th {
background-color: #666666ff;
}

.actions .btn-previous {
background-color: #666666ff;
color: white;
margin-right: 0.5em;
}

.actions .btn-save {
margin-right: 0.5em;
border-color: black;
}

.actions .btn-primary {
background-color: #467dd1ff;
margin-right: 0.5em;
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/works_wizard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class WorksWizardController < ApplicationController
# get Renders the "step 0" information page before creating a new dataset
# GET /works/new_submission
def new_submission
group = Group.find_by(code: params[:group_code]) || current_user.default_group
group_id = group.id
@work = Work.new(created_by_user_id: current_user.id, group_id:)
@work = WorkMetadataService.new(params:, current_user:).work_for_new_submission
prepare_decorators_for_work_form(@work)
end

Expand All @@ -32,7 +30,7 @@ def new_submission
def new_submission_save
@work = WorkMetadataService.new(params:, current_user:).new_submission
@errors = @work.errors.to_a
if params[:save_only] == "true" || @errors.count.positive?
if @errors.count.positive?
prepare_decorators_for_work_form(@work)
render :new_submission
else
Expand Down Expand Up @@ -120,7 +118,7 @@ def file_other; end
# GET /works/1/review
# POST /works/1/review
def review
if request.method == "POST"
if request.method == "POST" || request.method == "PATCH"
@work.location_notes = params["location_notes"]
@work.save!
if params[:save_only] == "true"
Expand All @@ -133,10 +131,11 @@ def review
# GET /works/1/validate
def validate
@work.submission_notes = params["submission_notes"]
@work.complete_submission!(current_user)
if params[:save_only] == "true"
@work.save
render :review
else
@work.complete_submission!(current_user)
redirect_to user_url(current_user)
end
end
Expand Down
41 changes: 18 additions & 23 deletions app/services/work_metadata_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ def initialize(params:, current_user:)
@current_user = current_user
end

# generates or load the work for a new submission based on the parameters
#
# creates or finds the work for the new submission form based on the parameters
#
# @returns the new or updated work
#
def new_submission
def work_for_new_submission
if params[:id].present?
update_work
Work.find(params[:id])
else
draft_work
group = Group.find_by(code: params[:group_code]) || current_user.default_group
Work.new(created_by_user_id: current_user.id, group_id: group.id)
end
end

# generates the work for a new submission
#
# @returns the new work
def new_submission
group_id = group_code.id
work = Work.new(created_by_user_id: current_user.id, group_id:)
work.resource = FormToResourceService.convert(params, work)
if work.valid_to_draft
work.draft!(current_user)
end
work
end

def self.file_location_url(work)
Expand All @@ -35,23 +47,6 @@ def self.file_location_url(work)

private

def update_work
work = Work.find(params[:id])
update_params = { group: group_code, resource: FormToResourceService.convert(params, work) }
WorkCompareService.update_work(work:, update_params:, current_user:)
work
end

def draft_work
group_id = group_code.id
work = Work.new(created_by_user_id: current_user.id, group_id:)
work.resource = FormToResourceService.convert(params, work)
if work.valid_to_draft
work.draft!(current_user)
end
work
end

def group_code
@group_code ||= Group.find_by(code: params[:group_code]) || current_user.default_group
end
Expand Down
8 changes: 3 additions & 5 deletions app/views/works_wizard/_form_wizard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
<hr />
<div class="actions">
<%= link_to 'Cancel', @work, class: "btn btn-secondary" %>
<% if @work.persisted? %>
<%= form.submit "Save Work", class: "btn btn-primary wizard-next-button", id: "btn-submit" %>
<% else %>
<%= form.submit "Create", class: "btn btn-primary wizard-next-button", id: "btn-submit", name: "submit" %>
<% end %>
<%= form.submit "Next", class: "btn btn-primary wizard-next-button", id: "btn-submit" %>
<%= form.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
</div>

<%= render '/works/form_hidden_fields' %>
Expand Down
8 changes: 4 additions & 4 deletions app/views/works_wizard/attachment_select.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<p>Begin the process to upload your submission. Please select the most appropriate description.</p>

<p>My submission is...</p>

<%= form_tag(action: "attachment_selected", id: @work) do %>
<%= form_with(model: @work, url: work_attachment_selected_path(@work)) do |form| %>
<input type="radio" id="attachment_type" name="attachment_type" value="file_upload" class="wizard-radio-button"
<%= @work.files_location_upload? ? "checked" : "" %>>under 100MB and I want to upload the files directly.</input><br/>

<input type="radio" id="attachment_type" name="attachment_type" value="file_other" class="wizard-radio-button"
<%= @work.files_location_other? ? "checked" : "" %>>more than 100MB or I am unable to upload.</input><br/>

<div class="actions">
<%= link_to "Go Back", work_readme_select_path(@work, wizard: true), class: "btn btn-secondary" %>
<%= submit_tag "Continue", class: "btn btn-primary wizard-next-button" %>
<%= link_to "Previous", work_readme_select_path(@work, wizard: true), class: "btn btn-secondary" %>
<%= form.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
<%= submit_tag "Next", class: "btn btn-primary wizard-next-button" %>
</div>
<% end %>
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/views/works_wizard/file_other.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
For now, please indicate where your files are currently stored, approximately how many files you have,
the total size of your submission, and whether you have a specific deadline to meet.</p>

<%= form_tag(action: "review", id: @work) do %>
<%= form_with(model: @work, url: work_review_path(@work)) do |form| %>
<textarea id="location_notes" name="location_notes"cols="80", rows="10"
placeholder="Where and how we may access your files"><%= @work.location_notes %></textarea>
<div class="actions">
<%= link_to "Go Back", work_attachment_select_url(@work, wizard: true), class: "btn btn-secondary" %>
<%= submit_tag "Continue", class: "btn btn-primary wizard-next-button" %>
<%= submit_tag "Next", class: "btn btn-primary wizard-next-button" %>
<%= form.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-primary wizard-next-button" %>
<%= link_to "Previous", work_attachment_select_url(@work, wizard: true), class: "btn btn-secondary" %>
</div>
<% end %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/works_wizard/file_upload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

<p><%= t('works.form.file_upload.actions') %></p>
<div class="actions">
<%= link_to t('works.form.file_upload.go_back'), work_attachment_select_url(@work, wizard: true), class: "btn btn-secondary" %>
<%= f.submit(t('works.form.file_upload.continue'), class: "btn btn-primary wizard-next-button", id: 'file-upload') %>
<%= f.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
<%= link_to t('works.form.file_upload.go_back'), work_attachment_select_url(@work, wizard: true), class: "btn btn-secondary" %>
</div>
<% end %>
</div>
Expand Down
5 changes: 2 additions & 3 deletions app/views/works_wizard/new_submission.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@
your submission, we may be reached at <a href="mailto:prds@princeton.edu">prds@princeton.edu</a>.
</p>

<%= form_with(model: @work, url: work_new_submission_path(@work)) do |form| %>
<%= form_with(model: @work, url: work_new_submission_path) do |form| %>
<%= render(partial: 'works/required_title', locals: {allow_many: false}) %>
<%= render(partial: 'works/required_creators_table') %>
<%= render '/works/form_hidden_fields' %>
<hr />
<div class="actions">
<%= link_to "Cancel", root_path, class: "btn btn-secondary" %>
<%= submit_tag "Next", class: "btn btn-primary wizard-next-button", id: "btn-create-new" %>
<%= form.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-primary wizard-next-button" %>
<%= submit_tag "Create New", class: "btn btn-primary wizard-next-button", id: "btn-create-new" %>
</div>
<% end %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/works_wizard/readme_select.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
</div>

<div class="actions">
<%= link_to t('works.form.readme_upload.go_back'), edit_work_wizard_path(@work), class: "btn btn-secondary" %>
<%= f.submit(t('works.form.readme_upload.continue'), class: "btn btn-primary wizard-next-button", id: 'readme-upload', disabled: @readme.blank?) %>
<%= f.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
<%= link_to 'Previous', edit_work_wizard_path(@work), class: "btn btn-previous wizard-next-button" %>
</div>
<% end %>
</div>
Expand Down
5 changes: 3 additions & 2 deletions app/views/works_wizard/review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
it more discoverable and reusable. Recommendations will be available in the "unfinished submissions"
section of this form within 5-10 business days.</p>

<%= form_tag(action: "validate", id: @work) do %>
<%= form_with(model: @work, url: work_validate_path(@work)) do |form| %>
<textarea id="submission_notes" name="submission_notes" cols="80", rows="10"
placeholder="(optional) Type here to leave a message for the curators"><%= @work.submission_notes %></textarea>
<div class="actions">
<%= link_to "Go Back", file_location_url , class: "btn btn-secondary" %>
<%= submit_tag "Grant License and Complete", class: "btn btn-primary wizard-next-button" %>
<%= form.button 'Save', type: 'submit', name: 'save_only', value: 'true', class: "btn btn-save wizard-next-button" %>
<%= link_to "Previous", file_location_url , class: "btn btn-secondary" %>
</div>
<% end %>
</div>
Expand Down
8 changes: 4 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ en:
file_upload:
heading: "New Submission (%{work_title})"
actions: 'Once you have uploaded your files, select the "continue" button.'
go_back: 'Go Back'
continue: 'Continue'
go_back: 'Previous'
continue: 'Next'
curation_uploads:
filename: "Filename"
created_at: "Time of Upload"
Expand All @@ -68,8 +68,8 @@ en:
heading: "New Submission (%{work_title})"
title: "Please upload the README file for this submission."
actions: 'We will ask you about your data files on the next step.'
go_back: 'Go Back'
continue: 'Continue'
go_back: 'Previous'
continue: 'Next'
uneditable:
approved: "This work has been approved. Edits are no longer available."
privs: "You do not have permission to edit this work."
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

# The work wizard
get "works/new-submission", to: "works_wizard#new_submission", as: :work_create_new_submission
post "works/new-submission/(:id)", to: "works_wizard#new_submission_save", as: :work_new_submission
patch "works/new-submission/:id", to: "works_wizard#new_submission_save"
post "works/new-submission/", to: "works_wizard#new_submission_save", as: :work_new_submission
get "works/:id/readme-select", to: "works_wizard#readme_select", as: :work_readme_select
patch "works/:id/readme-uploaded", to: "works_wizard#readme_uploaded", as: :work_readme_uploaded
patch "works/:id/file-upload", to: "works_wizard#file_uploaded", as: :work_file_uploaded
Expand All @@ -41,9 +40,12 @@
get "works/:id/file-other", to: "works_wizard#file_other", as: :work_file_other
get "works/:id/review", to: "works_wizard#review", as: :work_review
post "works/:id/review", to: "works_wizard#review"
patch "works/:id/review", to: "works_wizard#review"
post "works/:id/validate", to: "works_wizard#validate", as: :work_validate
patch "works/:id/validate", to: "works_wizard#validate"
get "works/:id/attachment-select", to: "works_wizard#attachment_select", as: :work_attachment_select
post "works/:id/attachment-select", to: "works_wizard#attachment_selected", as: :work_attachment_selected
patch "works/:id/attachment-select", to: "works_wizard#attachment_selected"

get "works/:id/file-list", to: "works#file_list", as: :work_file_list
post "work/:id/approve", to: "works#approve", as: :approve_work
Expand Down
25 changes: 0 additions & 25 deletions spec/controllers/works_wizard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,6 @@
expect(response).to render_template(:new_submission)
end
end

context "save and stay on page" do
let(:save_only_params) { params.merge(save_only: true) }
it "renders the edit page when creating a new dataset with save only" do
sign_in user
post(:new_submission_save, params: save_only_params)
expect(response.status).to be 200
expect(response).to render_template(:new_submission)
end

context "when the user has hit save and the work has already been preserved" do
let(:work) { FactoryBot.create :draft_work }

it "renders the correct page" do
sign_in user
work_params = save_only_params.merge(id: work.id)
expect { post(:new_submission_save, params: work_params) }
.to change { Work.count }.by(0)
.and change { WorkActivity.count }.by(1)
expect(response.status).to be 200
expect(response).to render_template(:new_submission)
expect(work.reload.title).to eq("test dataset updated")
end
end
end
end

describe "#update_wizard" do
Expand Down
12 changes: 6 additions & 6 deletions spec/system/authz_submitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@

fill_in "creators[][given_name]", with: FFaker::Name.first_name
fill_in "creators[][family_name]", with: FFaker::Name.last_name
click_on "Next"
click_on "Create New"
fill_in "description", with: FFaker::Lorem.paragraph
select "GNU General Public License", from: "rights_identifiers"
click_on "Curator Controlled"
expect(page).to have_content "Research Data"
click_on "Save Work"
click_on "Next"
path = Rails.root.join("spec", "fixtures", "files", "readme.txt")
attach_file(path) do
page.find("#patch_readme_file").click
end
click_on "Continue"
click_on "Next"
page.find(:xpath, "//input[@value='file_other']").choose
click_on "Continue"
click_on "Continue"
click_on "Next"
click_on "Next"
click_on "Complete"

expect(page).to have_content "awaiting_approval"
Expand All @@ -60,7 +60,7 @@
sign_in submitter2
visit edit_work_path(work)
expect(current_path).to eq root_path
expect(page).not_to have_content "Save Work"
expect(page).not_to have_content "Next"
expect(page).to have_content "You do not have permission to edit this work"
end

Expand Down
10 changes: 5 additions & 5 deletions spec/system/authz_super_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@

fill_in "creators[][given_name]", with: FFaker::Name.first_name
fill_in "creators[][family_name]", with: FFaker::Name.last_name
click_on "Next"
click_on "Create New"
fill_in "description", with: FFaker::Lorem.paragraph
select "GNU General Public License", from: "rights_identifiers"
click_on "Curator Controlled"
expect(page).to have_content "Research Data"
click_on "Save Work"
click_on "Next"
path = Rails.root.join("spec", "fixtures", "files", "readme.txt")
attach_file(path) do
page.find("#patch_readme_file").click
end
click_on "Continue"
click_on "Next"
page.find(:xpath, "//input[@value='file_other']").choose
click_on "Continue"
click_on "Continue"
click_on "Next"
click_on "Next"
click_on "Complete"

expect(page).to have_content "awaiting_approval"
Expand Down
10 changes: 5 additions & 5 deletions spec/system/external_ids_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

fill_in "creators[][given_name]", with: "Sally"
fill_in "creators[][family_name]", with: "Smith"
click_on "Next"
click_on "Create New"
fill_in "description", with: "test description"
select "GNU General Public License", from: "rights_identifiers"
click_on "Save Work"
click_on "Next"
path = Rails.root.join("spec", "fixtures", "files", "readme.txt")
attach_file(path) do
page.find("#patch_readme_file").click
end
click_on "Continue"
click_on "Continue"
click_on "Continue"
click_on "Next"
click_on "Next"
click_on "Next"
click_on "Complete"

expect(page).to have_content "awaiting_approval"
Expand Down
Loading

0 comments on commit b546c01

Please sign in to comment.