-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish implementing confirmation workflow
** Why are these changes being introduced: A previous PR started the implementation of our confirmation workflow, but did not include a form in the view template, nor the controller logic to receive the form submissions. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/tco-101 ** How does this address that need: This finishes the job of the previous PR, completing the confirmation workflow. More specifically, it: * Updates the routes information, moving the "index" display to a better route name, and defining Confirmations as resources under Terms. This makes dealing with routing more logical, and takes advantage of Rails' magic. * Moves the confirmation form out of the Terms controller, and into a new Confirmation controller, which is where records like this should be managed, in the Confirmation#new method. * Form submissions are received in Confirmation#create, which is helped by two new private methods for dealing with category values (which are either a category_id or a "flag" boolean), and for user feedback based on the create result. * The site_nav and tests are updated to reflect the new controller and route information * The view templates are updated, most notably the new confirmation template, which now has a working form using Rails' built-in form tool. ** Document any side effects to this change: The confirmation form has some inline styles to quickly get the UI into something not-awful. Rubocop is complaining about lack of translation in the feedback messages in the Confirmation controller, and for the complexity of the feedback_for method.
- Loading branch information
1 parent
74bd38b
commit 05c193d
Showing
8 changed files
with
91 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
class ConfirmationController < ApplicationController | ||
def new | ||
@term = Term.find(params[:term_id]) | ||
@categories = Category.all | ||
@confirmation = Confirmation.new | ||
end | ||
|
||
def create | ||
confirmation = Confirmation.new({ | ||
term_id: params[:term_id], | ||
user: current_user | ||
}) | ||
set_category(confirmation, params[:confirmation][:category]) | ||
result = confirmation.save | ||
feedback_for(result) | ||
end | ||
|
||
private | ||
|
||
def feedback_for(result) | ||
if result == true && params[:confirmation][:category] == 'flag' | ||
flash[:success] = 'Term flagged for review' | ||
redirect_to terms_unconfirmed_path | ||
elsif result == true | ||
flash[:success] = "Term confirmed as #{Category.find_by(id: params[:confirmation][:category]).name}" | ||
redirect_to terms_unconfirmed_path | ||
else | ||
flash[:warning] = 'Unable to finish confirming this term. Please try again, or try a different term.' | ||
redirect_back_or_to terms_unconfirmed_path | ||
end | ||
end | ||
|
||
def set_category(confirmation, category) | ||
if category == 'flag' | ||
confirmation.flag = true | ||
else | ||
confirmation.category_id = category | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<h3>Term confirmation</h3> | ||
|
||
<div class="well"> | ||
<p><%= @term.phrase %></p> | ||
</div> | ||
<%= form_for @confirmation, url: term_confirmation_index_path(@term) do |f| %> | ||
<fieldset> | ||
<legend>Please put the above term into one of the following categories:</legend> | ||
<ul class="list-unbulleted categories"> | ||
<% @categories.all.each do |cat| %> | ||
<li> | ||
<%= f.radio_button :category, cat.id %> | ||
<%= f.label(:category, cat.name, :value => cat.id) do | ||
raw("<h4>#{cat.name}</h4><p>#{cat.description}</p>") | ||
end %> | ||
</li> | ||
<% end %> | ||
<li> | ||
<%= f.radio_button :category, 'flag' %> | ||
<%= f.label(:category, 'flag', :value => 'flag') do | ||
raw("<h4>Flag for review</h4><p>Does this term need to be reviewed for removal from TACOS?</p>") | ||
end %> | ||
</li> | ||
</ul> | ||
</fieldset> | ||
<%= f.submit %> | ||
<% end %> | ||
|
||
<style type="text/css"> | ||
ul.categories li { | ||
display: flex; | ||
flex-flow: row nowrap; | ||
align-items: baseline; | ||
column-gap: 1rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters