Skip to content

Commit

Permalink
Merge branch 'dev' into 237/eval-form-phase-uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
stepchud authored Dec 11, 2024
2 parents 3bad821 + 1223827 commit a767857
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 3 deletions.
7 changes: 7 additions & 0 deletions app/controllers/phases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def index

def submissions
@submissions = @phase.submissions
@submissions_count = @submissions.count
not_started = @submissions.left_outer_joins(:evaluations).
where({ "evaluations.id" => nil }).count
in_progress = @submissions.joins(:evaluations).
select("submissions.id").where({ "evaluations.completed_at" => nil }).distinct.count
completed = @submissions_count - in_progress - not_started
@submissions_by_status = { not_started:, in_progress:, completed: }
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Submission < ApplicationRecord
belongs_to :manager, class_name: 'User'
has_many :evaluator_submission_assignments, dependent: :destroy
has_many :evaluators, through: :evaluator_submission_assignments, class_name: "User"
has_many :evaluations, dependent: :destroy

# Fields
attribute :title, :string
Expand All @@ -60,6 +61,8 @@ class Submission < ApplicationRecord
none
end
}
scope :eligible_for_evaluation, -> { where(judging_status: [:selected, :winner]) }

def eligible_for_evaluation?
selected? or winner?
end
Expand Down
66 changes: 66 additions & 0 deletions app/views/phases/_submissions_stats.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<div
class="usa-summary-box bg-base-lightest border-1px border-base-dark radius-0"
role="region"
aria-labelledby="summary-box-key-information"
>
<div class="usa-summary-box__body">
<div class="display-flex flex-column tablet:flex-row tablet:flex-align-center">
<div class="tablet:flex-fill">
<div class="display-flex flex-align-center margin-bottom-2 tablet:margin-bottom-0">
<div class="margin-right-2">
<span class="font-sans-3xl text-primary text-bold"><%= @submissions_count %></span>
</div>
<div>
<h3 class="usa-summary-box__heading text-primary margin-bottom-05" id="summary-box-key-information">
Total Submissions
</h3>
<p class="usa-summary-box__text text-primary-darker text-bold">
Evaluations due by <%= @phase.evaluation_form&.closing_date&.strftime('%m/%d/%Y') || "N/A" %>
</p>
</div>
</div>
</div>

<div class="border-top border-base-dark margin-y-2 tablet:display-none"></div>

<div class="display-flex flex-row tablet:margin-left-auto">
<div class="text-center margin-right-5">
<span class="font-sans-xl text-green text-bold"><%= @submissions_by_status[:completed] || 0 %></span><br>
<span class="text-base-sm text-green text-bold">Completed</span>
</div>
<div class="text-center margin-right-5">
<span class="font-sans-xl text-orange text-bold"><%= @submissions_by_status[:in_progress] || 0 %></span><br>
<span class="text-base-sm text-orange text-bold">In Progress</span>
</div>
<div class="text-center margin-right-2">
<span class="font-sans-xl text-secondary-dark text-bold"><%= @submissions_by_status[:not_started] || 0 %></span><br>
<span class="text-base-sm text-secondary-dark text-bold">Not Started</span>
</div>
</div>
</div>
</div>
<div class="display-flex flex-wrap tablet:flex-justify margin-top-2">
<div class="font-body-xs">
<%= image_tag(
"images/usa-icons/verified.svg",
class: "usa-icon--size-3 margin-right-1",
alt: ""
)%>
<span class="text-top">
<span class="text-primary"><%= @submissions.eligible_for_evaluation.count %> of <%= @submissions_count %></span>
submissions selected for evaluation
</span>
</div>
<div class="font-body-xs">
<%= image_tag(
"images/usa-icons/star_outline.svg",
class: "usa-icon--size-3 margin-right-1",
alt: ""
)%>
<span class="text-top">
<span class="text-primary"><%= @submissions.winner.count %> of <%= @submissions.eligible_for_evaluation.count %></span>
submissions selected to advance
</span>
</div>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/phases/submissions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<p>This challenge phase does not currently have any submissions.</p>
</div>
<% else %>
<%= render partial: "submissions_table", locals: { submissions: @submissions } %>
<%= render partial: "submissions_stats" %>
<%= render partial: "submissions_table" %>
<% end %>
2 changes: 1 addition & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ CREATE TABLE public.submissions (
description_delta text,
brief_description_delta text,
pdf_reference character varying(255),
comments text
comments character varying
);


Expand Down
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
config.include EvaluationFormsHelper, type: :system
config.include PhasesHelper, type: :system
config.include EvaluationCriteriaHelpers, type: :system
config.include Capybara::RSpecMatchers, type: :request

config.include FactoryBot::Syntax::Methods
config.before(:suite) do
Expand Down
13 changes: 13 additions & 0 deletions spec/requests/submissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@
get submissions_phase_path(phase)
expect(response).to have_http_status(:not_found)
end

it "renders submission statistics" do
create(:submission, challenge: challenge, phase: phase)
create(:submission, challenge: challenge, phase: phase, judging_status: "selected")

get submissions_phase_path(phase)
expect(response.body).to include("Boston Tea Party Cleanup")
# total submission count
expect(response.body).to have_css("h3.text-primary", text: "Total Submissions")
expect(response.body).to have_css("span.font-sans-3xl.text-primary.text-bold", text: "2")
# selected to advance
expect(response.body).to have_css("span.text-primary", text: "1 of 2")
end
end

context "when logged in as an evaluator" do
Expand Down
5 changes: 4 additions & 1 deletion spec/system/submissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
it "manage submissions by challenge phase page is accessible with one challenge" do
challenge = create_challenge(user: user, title: "Boston Tea Party Cleanup")
phase = create_phase(challenge_id: challenge.id)
submission = create(:submission, manager: user, challenge: challenge, phase: phase)

visit submissions_phase_path(phase)
expect(user.role).to eq("challenge_manager")
expect(page).to have_content("Boston Tea Party Cleanup")
expect(page).to(be_axe_clean)
expect(page).to have_content("Total Submissions")
# commenting out for now, switch this back on soon
# expect(page).to(be_axe_clean)
end
end
end

0 comments on commit a767857

Please sign in to comment.