Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[80] Submission Detail Page #257

Merged
merged 37 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
71a485e
WIP
stonefilipczak Oct 29, 2024
0869211
link from index
stonefilipczak Oct 31, 2024
2db488a
Merge branch 'dev' into 206_view_submissions
stonefilipczak Oct 31, 2024
dd46f8c
tests
stonefilipczak Oct 31, 2024
a328be1
helper methods
stonefilipczak Nov 1, 2024
b76cae6
icons
stonefilipczak Nov 4, 2024
340da9d
Merge remote-tracking branch 'origin/dev' into 206_view_submissions
stepchud Nov 4, 2024
2a651eb
add submission id label on mobile
stonefilipczak Nov 4, 2024
e5fc225
Update app/controllers/manage_submissions_controller.rb
stonefilipczak Nov 5, 2024
cacbaae
Update app/views/manage_submissions/_submissions_table.html.erb
stonefilipczak Nov 5, 2024
c83efc7
Update app/helpers/manage_submissions_helper.rb
stonefilipczak Nov 5, 2024
e9d73f5
scope phase to a user's challenges
stonefilipczak Nov 5, 2024
1580142
move tests into own file
stonefilipczak Nov 5, 2024
b82b779
rubocop
stonefilipczak Nov 5, 2024
a2e7ed7
add closing a tag
stonefilipczak Nov 5, 2024
cde14f4
add margin-right-1 to all icons
stonefilipczak Nov 6, 2024
eaca5b8
testing different states
stonefilipczak Nov 6, 2024
7170729
display booleans as checkboxes on desktop
stonefilipczak Nov 6, 2024
389a1b2
rubocop
stonefilipczak Nov 6, 2024
b4f70a8
set up page
stonefilipczak Nov 6, 2024
89a0e7e
more tests
stonefilipczak Nov 7, 2024
d6247d1
update submission from comment form
stonefilipczak Nov 7, 2024
6ee60fe
comment form
stonefilipczak Nov 7, 2024
3ac1bcd
rubocop
stonefilipczak Nov 7, 2024
032a9ef
merge origin/dev
stepchud Nov 8, 2024
e8a2661
Merge branch 'dev' into 80_submission_detail
stepchud Nov 8, 2024
adcfae4
update evaluation_form routes
stepchud Nov 8, 2024
6d3e79a
update manage_submission routes, DB migration text col
stepchud Nov 9, 2024
1af7ab4
Merge branch 'dev' into 80_submission_detail
stepchud Nov 14, 2024
7644f13
remove manage_ prefixes
stepchud Nov 14, 2024
8de8415
Merge remote-tracking branch 'origin/80_submission_detail' into 80_su…
stepchud Nov 14, 2024
5d5a20b
update session route
stepchud Nov 14, 2024
4b5dd1d
add phases specs
stepchud Nov 14, 2024
20a50ed
adds Submission.by_user(user) scope
stepchud Nov 14, 2024
fc8b85d
gitignore dev files
stepchud Nov 14, 2024
2681b81
revert removed association
stepchud Nov 14, 2024
2bf547e
fix specs, remove comment
stepchud Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@
/node_modules
/coverage/
/vars.*.yml

# dev env configuration files
.direnv/
.vscode/
.yarn/
.yarnrc
10 changes: 7 additions & 3 deletions app/controllers/evaluation_forms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def update
respond_to do |format|
if @evaluation_form.update(evaluation_form_params)
format.html do
redirect_to evaluation_forms_confirmation_path, notice: I18n.t("evaluation_form_saved")
redirect_to confirmation_evaluation_form_path(@evaluation_form), notice: I18n.t("evaluation_form_saved")
end
format.json { render :show, status: :ok, location: @evaluation_form }
else
Expand All @@ -68,11 +68,15 @@ def confirmation; end

# Use callbacks to share common setup or constraints between actions.
def set_evaluation_form
@evaluation_form = EvaluationForm.find(params[:id])
@evaluation_form = EvaluationForm.
by_user(current_user).
find(params[:id])
end

def set_evaluation_forms
@evaluation_forms = EvaluationForm.by_user(current_user).includes([:challenge, :phase])
@evaluation_forms = EvaluationForm.
by_user(current_user).
includes([:challenge, :phase])
end

# Only allow a list of trusted parameters through.
Expand Down
14 changes: 0 additions & 14 deletions app/controllers/manage_submissions_controller.rb

This file was deleted.

21 changes: 21 additions & 0 deletions app/controllers/phases_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

class PhasesController < ApplicationController
before_action -> { authorize_user('challenge_manager') }
before_action :set_phase, except: [:index]

def index
@challenges = current_user.challenge_manager_challenges
end

def submissions
@submissions = @phase.submissions
end

private

def set_phase
@phase = Phase.where(challenge: current_user.challenge_manager_challenges).find(params[:id])
@challenge = @phase.challenge
end
end
28 changes: 28 additions & 0 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

class SubmissionsController < ApplicationController
before_action -> { authorize_user('challenge_manager') }
before_action :set_submission, only: [:show, :update]

def show; end

def update
if @submission.update!(submission_params)
flash.now[:success] = I18n.t("comments_saved")
render :show, submission: @submission
else
render :show, status: :unprocessable_entity, submission: @submission
end
end

private

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

# User access enforced by role
def set_submission
@submission = Submission.by_user(current_user).find(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def dashboard_cards_by_role
challenge_manager: [
{ image_path: 'emoji_events', href: Rails.configuration.phx_interop[:phx_uri],
alt: 'challenges', title: 'Challenges', subtitle: 'Create and manage challenges.' },
{ image_path: 'star_half', href: 'manage_submissions',
{ image_path: 'star_half', href: 'phases',
alt: 'submissions and evaluations', title: 'Submissions & Evaluations', subtitle:
'Manage submissions, evaluations, and evaluators.' },
{ image_path: 'check_circle_outline', href: 'evaluation_forms',
Expand Down
11 changes: 0 additions & 11 deletions app/helpers/manage_submissions_helper.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/javascript/session_timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ document.addEventListener("DOMContentLoaded", function () {
};

const logoutSession = () => {
fetch("/sessions/timeout", {
fetch("/session/timeout", {
method: "DELETE",
headers: {
"X-CSRF-Token": document.querySelector('meta[name="csrf-token"]')
Expand Down Expand Up @@ -67,7 +67,7 @@ document.addEventListener("DOMContentLoaded", function () {
});

var renewSession = () => {
fetch("/sessions/renew", {
fetch("/session/renew", {
method: "POST",
headers: {
"X-CSRF-Token": document
Expand Down
22 changes: 21 additions & 1 deletion app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class Submission < ApplicationRecord
enum :judging_status, { not_selected: "not_selected", selected: "selected", qualified: "qualified", winner: "winner" }

# Associations
belongs_to :submitter, class_name: 'User'
belongs_to :challenge
belongs_to :phase
belongs_to :submitter, class_name: 'User'
belongs_to :manager, class_name: 'User'
has_many :evaluator_submission_assignments, dependent: :destroy
has_many :evaluators, through: :evaluator_submission_assignments, class_name: "User"
Expand All @@ -22,4 +22,24 @@ class Submission < ApplicationRecord

# Validations
validates :title, presence: true

scope :by_user, lambda { |user|
case user.role
when 'challenge_manager'
where(challenge: user.challenge_manager_challenges)
when 'evaluator'
joins(:evaluators).where(evaluators: { id: user.id })
when 'solver'
where(submitter: user)
else
none
end
}
def eligible_for_evaluation?
selected? or winner?
end

def selected_to_advance?
winner?
end
end
2 changes: 1 addition & 1 deletion app/views/evaluation_forms/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div class="usa-hint">Choose the challenge this form will evaluate.</div>
<div class="usa-combo-box" data-default-value="<%= combo_box_default_value %>">
<select class="usa-select" <%= if disabled then "disabled" end %> id="challenge-combo" title="challenge-combo" data-action="evaluation-form#handleChallengeSelect">
<% current_user.challenge_manager_challenges.each do |challenge| %>
<% current_user.challenge_manager_challenges.includes(:phases).each do |challenge| %>
<% challenge.phases.each do |phase| %>
<option value="<%= "#{challenge.id}.#{phase.id}.#{phase.end_date.strftime("%m/%d/%Y")}" %>"><%= challenge_phase_title(challenge, phase) %></option>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_utility_menu.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= utility_menu_link('grid_view', dashboard_path, 'dashboard', 'Dashboard') %>
<% if current_user.role == "challenge_manager" %>
<%= utility_menu_link('emoji_events', Rails.configuration.phx_interop[:phx_uri], 'challenges', 'Challenges') %>
<%= utility_menu_link('star_half', manage_submissions_path, 'Manage Submissions and Evaluations', 'Submissions & Evaluations') %>
<%= utility_menu_link('star_half', phases_path, 'Manage Submissions and Evaluations', 'Submissions & Evaluations') %>
<%= utility_menu_link('check_circle_outline', evaluation_forms_path, 'Evaluation Forms', 'Evaluation Forms') %>
<% end %>
<% if current_user.role == "evaluator" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
Manage Evaluators
</button>
<% unless phase.submissions.empty? %>
<%= link_to(challenge_manage_submission_path(challenge, phase)) do %>
<%= link_to(submissions_phase_path(phase)) do %>
<button class="usa-button font-body-2xs text-no-wrap">
View Submissions
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</th>
<td data-label="Eligible for Evaluation">
<div class="display-flex flex-align-center">
<% if eligible_for_evaluation?(submission) %>
<% if submission.eligible_for_evaluation? %>
<input type="checkbox" disabled checked class="display-none mobile-lg:display-block">
<div class="mobile-lg:display-none">
<%= image_tag(
Expand All @@ -41,7 +41,7 @@
</td>
<td data-label="Selected to Advance">
<div class="display-flex flex-align-center">
<% if selected_to_advance?(submission) %>
<% if submission.selected_to_advance? %>
<input type="checkbox" disabled checked class="display-none mobile-lg:display-block">
<div class="mobile-lg:display-none">
<%= image_tag(
Expand Down Expand Up @@ -72,9 +72,11 @@
</td>
<td>
<div class="display-flex flex-no-wrap grid-row grid-gap-1">
<button class="usa-button font-body-2xs text-no-wrap">
View Submission
</button>
<%= link_to submission_path(submission) do %>
<button class="usa-button font-body-2xs text-no-wrap">
View Submission
</button>
<% end %>
</div>
</td>
</tr>
Expand Down
9 changes: 9 additions & 0 deletions app/views/submissions/_comment_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= form_with(model: @submission, url: submission_path(@submission), class: "width-mobile-lg") do |form| %>
<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 %>
23 changes: 23 additions & 0 deletions app/views/submissions/_submission_materials.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h3>Brief Description:</h3>
<p class="text-normal"><%= @submission.brief_description %></p>

<h3>Description:</h3>
<p class="text-normal"><%= @submission.description %></p>

<h3>External URL:</h3>
<a href=<%= @submission.external_url %>><%= @submission.external_url %></a>

<h3>Status:</h3>
<p class="text-normal"><%= @submission.status.capitalize %></p>

<h3>Submitter:</h3>
<p class="text-normal"><%= @submission.submitter.email %></p>

<h3>Last Updated Date:</h3>
<p class="text-normal"><%= @submission.updated_at %></p>

<h3>Submission ID:</h3>
<p class="text-normal"><%= @submission.id %></p>

<h3>Title:</h3>
<p class="text-normal"><%= @submission.title %></p>
5 changes: 5 additions & 0 deletions app/views/submissions/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>Submission ID <%= @submission.id %></h1>
<p class="text-normal">View submission information and assign evaluators to evaluate the submission.</p>

<%= render partial: "submission_materials" %>
<%= render partial: "comment_form" %>
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ en:
already_logged_in_notice: "You are already logged in."
evaluation_form_destroyed: "Evaluation form was successfully destroyed."
evaluation_form_saved: "Evaluation form was saved successfully."
comments_saved: "Comments saved 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
24 changes: 15 additions & 9 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
Rails.application.routes.draw do
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
get 'auth/result', to: 'sessions#result'
resource 'session', only: [:new, :create, :destroy]
post 'sessions/renew', to: 'sessions#renew'
delete 'sessions/timeout', to: 'sessions#timeout'
resource 'session', only: [:new, :create, :destroy] do
post 'renew'
delete 'timeout'
end

get '/', to: "dashboard#index"
get '/dashboard', to: "dashboard#index"

resources :evaluations, only: [:index]
get '/evaluation_forms/confirmation', to: 'evaluation_forms#confirmation'
resources :evaluation_forms
post '/evaluation_forms/clone', to: 'evaluation_forms#create_from_existing'
resources :manage_submissions, only: [:index]
resources :challenges, only: [] do
resources :manage_submissions, only: [:show]
resources :evaluation_forms do
member do
get 'confirmation'
post 'clone'
end
end
resources :phases, only: [:index] do
member do
get :submissions
end
end
resources :submissions, only: [:index, :show, :update]

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241107161811_add_comments_to_submissions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCommentsToSubmissions < ActiveRecord::Migration[7.2]
def change
add_column :submissions, :comments, :text, limit: 3000, null: true
end
end
4 changes: 3 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,8 @@ CREATE TABLE public.submissions (
review_verified boolean,
description_delta text,
brief_description_delta text,
pdf_reference character varying(255)
pdf_reference character varying(255),
comments text
);


Expand Down Expand Up @@ -2255,6 +2256,7 @@ ALTER TABLE ONLY public.winners
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
(20241107161811),
(20241023195356),
(20241018150049),
(20241017172408),
Expand Down
1 change: 1 addition & 0 deletions spec/factories/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
association :manager, factory: :user

title { Faker::Lorem.sentence }
status { "draft" }
end
end
12 changes: 0 additions & 12 deletions spec/helpers/manage_submissions_helper_spec.rb

This file was deleted.

Loading
Loading