Skip to content

Commit

Permalink
[305] Submission Details - Judging Status and Comments (#318)
Browse files Browse the repository at this point in the history
* working single form approach
* disabling checkboxes with javascript

---------

Co-authored-by: Stephen Chudleigh <[email protected]>
Co-authored-by: Stephen Chudleigh <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 0788919 commit 7f4a480
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def show; end

def update
if @submission.update!(submission_params)
flash.now[:success] = I18n.t("comments_saved")
flash.now[:success] = I18n.t("submission_updated")
render :show, submission: @submission
else
render :show, status: :unprocessable_entity, submission: @submission
Expand All @@ -19,7 +19,7 @@ def update
private

def submission_params
params.require(:submission).permit(:comments)
params.require(:submission).permit(:comments, :judging_status)
end

# User access enforced by role
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ application.register("evaluation-form", EvaluationFormController);
import HotdogController from "./hotdog_controller";
application.register("hotdog", HotdogController);

import SubmissionDetailsController from "./submission_details_controller";
application.register("submission-details", SubmissionDetailsController);

import ModalController from "./modal_controller";
application.register("modal", ModalController);
26 changes: 26 additions & 0 deletions app/javascript/controllers/submission_details_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="submission-details"
export default class extends Controller {
static targets = ["judgingStatusHidden", "eligibleCheckbox", "winnerCheckbox"];

eligibleCheck(e) {
if (e.target.checked) {
this.judgingStatusHiddenTarget.value = "selected"
this.winnerCheckboxTarget.disabled = false
} else {
this.judgingStatusHiddenTarget.value = "not_selected"
this.winnerCheckboxTarget.disabled = true
}
}

selectedCheck(e) {
if (e.target.checked) {
this.judgingStatusHiddenTarget.value = "winner"
this.eligibleCheckboxTarget.disabled = true
} else {
this.judgingStatusHiddenTarget.value = "selected"
this.eligibleCheckboxTarget.disabled = false
}
}
}
9 changes: 0 additions & 9 deletions app/views/submissions/_comment_form.html.erb

This file was deleted.

53 changes: 53 additions & 0 deletions app/views/submissions/_submission_details.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div data-controller="submission-details">
<% rand = SecureRandom.hex(8) %>
<%= form_with(model: @submission, url: submission_path(@submission), class: "maxw-mobile-lg") do |form| %>
<div class="usa-checkbox" id="eligible-for-evaluation">
<input
class="usa-checkbox__input usa-checkbox__input--tile"
type="checkbox"
id="<%= "#{rand}-judging-status-selected" %>"
value="selected"
<%= if @submission.judging_status == "winner" then "disabled" end %>
<%= "checked" if @submission.judging_status.in?(["selected", "winner"]) %>
data-action="change->submission-details#eligibleCheck"
data-submission-details-target="eligibleCheckbox"
/>
<label class="usa-checkbox__label" for="<%= "#{rand}-judging-status-selected" %>"
>This submission is eligible for evaluation.
<span class="usa-checkbox__label-description"
>Check the box if the submission is pre-screened and is eligible for the evaluation process.</span
></label
>
</div>
<div class="usa-checkbox" id="selected-to-advance">
<input
class="usa-checkbox__input usa-checkbox__input--tile"
id="<%= "#{rand}-judging-status-winner" %>"
type="checkbox"
<%= "disabled" unless @submission.judging_status.in?(["selected", "winner"]) %>
<%= "checked" if @submission.judging_status == "winner" %>
data-action="change->submission-details#selectedCheck"
data-submission-details-target="winnerCheckbox"
/>
<label class="usa-checkbox__label" for="<%= "#{rand}-judging-status-winner" %>"
>This submission is selected to advance.
<span class="usa-checkbox__label-description"
>Check the box to select this submission to advance or for award after all evaluations are completed.</span
></label
>
</div>
<input
id="judging-status-hidden"
type="hidden"
name="submission[judging_status]"
data-submission-details-target="judgingStatusHidden"
/>
<div class="usa-form-group">
<%= form.label :comments, "Comments and notes:", class: "usa-label" %>
<%= form.text_area :comments, class: "usa-textarea", default: @submission.comments %>
</div>
<button type="submit" name="commit" class="usa-button font-body-2xs text-no-wrap margin-y-2">
Save
</button>
<% end %>
</div>
4 changes: 2 additions & 2 deletions app/views/submissions/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1>Submission ID <%= @submission.id %></h1>
<p class="text-normal">View submission information and assign evaluators to evaluate the submission.</p>
<h2 class="font-body-sm text-normal">View submission information and assign evaluators to evaluate the submission.</h2>

<%= render partial: "layouts/hotdog", locals: {left: 'submissions/comment_form', right: 'submissions/submission_materials', name: 'Submission Materials'} %>
<%= render partial: "layouts/hotdog", locals: {left: 'submissions/submission_details', right: 'submissions/submission_materials', name: 'Submission Materials'} %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ en:
evaluation_form_destroyed: "Evaluation form was successfully destroyed."
evaluation_form_saved: "Evaluation form was saved successfully."
comments_saved: "Comments saved succesfully."
submission_updated: "Submission was updated succesfully."
login_error: "There was an issue with logging in. Please try again."
please_try_again: "Please try again."
session_expired_alert: "Your session has expired. Please log in again."
Expand Down
1 change: 1 addition & 0 deletions spec/factories/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@

title { Faker::Lorem.sentence }
status { "draft" }
external_url { "www.example.com" }
end
end
45 changes: 45 additions & 0 deletions spec/system/submission_details_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require 'rails_helper'

describe "A11y", :js do
describe "Logged-in as a Challenge Manager" do
let(:user) { create_user(role: "challenge_manager") }
let(:challenge) { create_challenge(user: user, title: "Boston Tea Party Cleanup") }
let(:submission) { create(:submission, manager: user, challenge: challenge) }


before { system_login_user(user) }

it "submission details page is accessible" do
visit submission_path(submission)
expect(user.role).to eq("challenge_manager")
expect(page).to have_css('h1', text: "Submission ID #{submission.id}")
expect(page).to(be_axe_clean)
end

it "allows manipulation of judging status" do
visit submission_path(submission)

find_by_id('eligible-for-evaluation').click
click_on('Save')
updated_submission = Submission.find(submission.id)
expect(updated_submission.judging_status).to eq('selected')

find_by_id('selected-to-advance').click
click_on('Save')
updated_submission = Submission.find(submission.id)
expect(updated_submission.judging_status).to eq('winner')
end

it "saves comments" do
visit submission_path(submission)
comments = Faker::Lorem.sentence

fill_in "Comments and notes:", with: comments
click_on('Save')
updated_submission = Submission.find(submission.id)
expect(updated_submission.comments).to eq(comments)
end
end
end

0 comments on commit 7f4a480

Please sign in to comment.