Skip to content

Commit

Permalink
Touch ups for show survey requests and navigation, and skipping will …
Browse files Browse the repository at this point in the history
…update stats
  • Loading branch information
smellsblue committed Sep 18, 2023
1 parent 41a44e8 commit cb1035c
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 9 deletions.
8 changes: 4 additions & 4 deletions app/controllers/survey_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SurveyRequestsController < ApplicationController
active_tab "surveys"

def index
@survey_requests = SurveyRequest.order(created_at: :desc).all.to_a
@survey_requests = SurveyRequest.includes(:survey).order(created_at: :desc).all.to_a
end

def new
Expand All @@ -29,8 +29,7 @@ def skip
return redirect_to survey_request_path(survey_request), flash: { error: "Organization already submitted an answer, cannot be skipped" }
end

org_request.skipped = true
org_request.save!
org_request.mark_skipped
end

redirect_to survey_request_path(survey_request), flash: { warning: "Marked organization as skipped" }
Expand All @@ -48,7 +47,8 @@ def submit_answer
survey_request = SurveyRequest.find(params[:id])
org_request = survey_request.survey_organization_requests.find(params[:org_request_id])
raise PermissionError unless current_user.can_answer_organization_survey?(org_request)
raise "TODO"
raise "TODO: #{params.inspect}"
redirect_to Redirect.to(orders_path, params, allow: ["orders", "survey_request"])
end

def create
Expand Down
2 changes: 2 additions & 0 deletions app/models/redirect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def self.to(default, params, allow: [])
Rails.application.routes.url_helpers.edit_organization_path(id_from(params))
when "organizations"
Rails.application.routes.url_helpers.organizations_path
when "organizations_deleted"
Rails.application.routes.url_helpers.deleted_organizations_path
when "order"
Rails.application.routes.url_helpers.edit_order_path(id_from(params))
when "orders"
Expand Down
8 changes: 8 additions & 0 deletions app/models/survey_organization_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ class SurveyOrganizationRequest < ApplicationRecord
belongs_to :survey_request
belongs_to :organization

def mark_skipped
transaction do
self.skipped = true
self.save!
survey_request.update_organization_counts
end
end

def unanswered?
!answered && !skipped
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/survey_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ class SurveyRequest < ApplicationRecord
belongs_to :survey_revision
has_many :survey_organization_requests

def complete?
organizations_waiting <= 0
end

def status_class
unless complete?
"danger"
end
end

def organizations_waiting
organizations_requested - organizations_responded - organizations_skipped
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/organizations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@
</div>
<% end %>
<%= link_to "Back", deleted_organizations_path, type: "button", class: "btn btn-default" %>
<%= link_to "Back", Redirect.to(deleted_organizations_path, params, allow: [:organizations_deleted, :survey_request]), class: "btn btn-default" %>
<% end %>
3 changes: 2 additions & 1 deletion app/views/survey_requests/answer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<% content_for :content do %>
<h3><%= @survey.title %></h3>

<%= form_tag demo_survey_path(@survey), method: :post, data: { live_guarded: true } do %>
<%= form_tag submit_answer_survey_request_path(@survey_request), method: :post, data: { live_guarded: true } do %>
<input type="hidden" name="org_request_id" value="<%= @org_request.id %>" />
<input type="hidden" name="redirect_to" value="<%= params[:redirect_to] %>" />
<input type="hidden" name="redirect_id" value="<%= params[:redirect_id] %>" />
<%= render partial: "surveys/survey_answer_fields", locals: { survey: @survey, revision: @revision, answers: @revision.blank_answers } %>
Expand Down
7 changes: 5 additions & 2 deletions app/views/survey_requests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@
<tr>
<th>Survey Request ID</th>
<th>Title</th>
<th>Survey</th>
<th>Organizations Requested</th>
<th>Organizations Responded</th>
<th>Organizations Skipped</th>
<th>Waiting for Organizations</th>
<th>Date</th>
</tr>
</thead>

<tbody>
<% @survey_requests.each do |survey_request| %>
<%# TODO: Highlight when incomplete %>
<tr data-href="<%= survey_request_path(survey_request) %>">
<tr data-href="<%= survey_request_path(survey_request) %>" class="<%= survey_request.status_class %>">
<td><%= survey_request.id %></td>
<td><%= survey_request.title %></td>
<td><%= survey_request.survey.title %></td>
<td><%= survey_request.organizations_requested %></td>
<td><%= survey_request.organizations_responded %></td>
<td><%= survey_request.organizations_skipped %></td>
<td><%= survey_request.organizations_waiting %></td>
<td><%= survey_request.created_at.strftime("%-m/%-d/%Y") %></td>
</tr>
<% end %>
Expand Down
6 changes: 5 additions & 1 deletion app/views/survey_requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<tbody>
<% @survey_request.survey_organization_requests.each do |org_request| %>
<tr class="<%= org_request.status_class %>">
<td><%= org_request.organization.name %> <%= link_to '<i class="glyphicon glyphicon-link"></i>'.html_safe, organization_path(org_request.organization) %></td>
<td><%= org_request.organization.name %> <%= link_to '<i class="glyphicon glyphicon-link"></i>'.html_safe, organization_path(org_request.organization, redirect_to: "survey_request", redirect_id: @survey_request.id) %></td>
<td><%= org_request.status %></td>

<td>
Expand All @@ -33,4 +33,8 @@
</tr>
</tfoot>
</table>

<p>
<%= link_to "Back", survey_requests_path, class: "btn btn-default" %>
</p>
<% end %>

0 comments on commit cb1035c

Please sign in to comment.