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

[129, 60, 130] Evaluation Form Model, Migration, CRUD, Responsive List View #169

Merged
merged 20 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
list view, clone action
stonefilipczak committed Sep 19, 2024
commit e6aa0cf5f14a1487431c093a6b30ab1d47b88bc3
19 changes: 19 additions & 0 deletions app/controllers/evaluation_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -36,6 +36,25 @@ def create
end
end

# NOTE: to reviewer: the following method works but it's impossible to use because there's a unique index on
# challenge_id and challenge_phase. So we can't clone evaluation forms without automatically advancing the challenge phase,
# or something along those lines
def create_from_existing
@existing_form = EvaluationForm.find(params[:evaluation_form])
@evaluation_form = EvaluationForm.new(@existing_form.attributes.except("id"))
respond_to do |format|
if @evaluation_form.save
format.html do
redirect_to evaluation_forms_url, notice: "Evaluation form was successfully cloned."
end
format.json { render :show, status: :created, location: @evaluation_form }
else
format.html { render :index, status: :unprocessable_entity }
format.json { render json: @evaluation_form.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /evaluation_forms/1 or /evaluation_forms/1.json
def update
respond_to do |format|
7 changes: 7 additions & 0 deletions app/helpers/evaluation_forms_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# frozen_string_literal: true

module EvaluationFormsHelper
def status_colors
{
draft: "FireBrick",
ready: "DarkGoldenRod",
published: "green"
}
end
Comment on lines +4 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these stauts_colors aren't needed anymore, but if we do they should be matching the figma values, e.g. the green is #4d8055

end
36 changes: 36 additions & 0 deletions app/views/evaluation_forms/_table.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<table class="usa-table usa-table--stacked-header width-full">
<thead>
<tr>
<th scope="col">Form Title</th>
<th scope="col">Assigned to Challenge</th>
<th scope="col">Status</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<% @evaluation_forms.each do |evaluation_form| %>
<tr>
<th data-label="Form Title" scope="row">
<%= link_to evaluation_form do %>
<%= evaluation_form.title %>
<% end %>
</th>
<td data-label="Assigned to Challenge">
<%= evaluation_form.challenge.title %>
</td>
<td data-label="Status">
<span style="<%="color: #{status_colors[evaluation_form.status.to_sym]}"%>">
<%= evaluation_form.status.capitalize %>
</span>
</td>
<td>
<div class="display-flex flex-wrap width-full grid-row grid-gap-1">
<%= button_to "Edit", edit_evaluation_form_path(evaluation_form), method: :get, class: "usa-button width-full", form: {class: "grid-col-4"} %>
<%= button_to "Clone", evaluation_forms_clone_path, method: :post, params: {evaluation_form: evaluation_form}, class: "usa-button width-full", style: "background-color: #4d8055", form: {class: "grid-col-4"} %>
<%= button_to "Delete", evaluation_form, method: :delete, class: "usa-button usa-button--secondary width-full padding-x-1", form: {class: "grid-col-4"} %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
39 changes: 25 additions & 14 deletions app/views/evaluation_forms/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
<div class="usa-card__container col-md-6">
<div class="usa-card__body">
<h1>Evaluation Forms</h1>
<div class="usa-card__body">
<h1>Evaluation Forms</h1>
<div class="display-flex flex-wrap tablet:flex-justify width-full">
<span class="text-base margin-bottom-1">Manage existing evaluation forms and create new evaluation forms.</span>

<div id="evaluation_forms">
<% @evaluation_forms.each do |evaluation_form| %>
<%= render evaluation_form %>
<p>
<%= link_to "Show this evaluation form", evaluation_form %>
</p>
<% end %>
</div>
<%= link_to new_evaluation_form_path, class: "width-full tablet:width-auto" do %>
<button class="usa-button font-body-2xs text-no-wrap" style="background-color: #4d8055">
<%= image_tag(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's avoid hard coding styles, especially for colors, and use a class such as bg-green-primary or something like that?

"images/usa-icons/content_copy.svg",
class: "usa-icon icon-white",
alt: "evaluation forms"
)%>
Create New Evaluation Form
</button>
<% end %>
</div>

<%= link_to "New evaluation form", new_evaluation_form_path %>
</div>
</div>
<% if @evaluation_forms.empty? %>
<div class="text-base align-center text-center">
<p>You currently do not have any evaluation forms.</p>
<p>Please create an evaluation form for your challenge before it is published.</p>
</div>
<% else %>
<%= render partial: "table", locals: { evaluation_forms: @evaluation_forms } %>
<% end %>

</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@

resources :evaluations, only: [:index]
resources :evaluation_forms
post '/evaluation_forms/clone', to: 'evaluation_forms#create_from_existing'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove the custom route for now

resources :manage_submissions, only: [:index]

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.