Skip to content

Commit

Permalink
Show survey answers and allow to print them
Browse files Browse the repository at this point in the history
  • Loading branch information
smellsblue committed Jun 27, 2023
1 parent c8fc72c commit 49ee75a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ def sync
order = current_user.sync_order(params)
redirect_to edit_order_path(order)
end

def survey_answers
@order = Order.find(params[:id])
raise PermissionError unless current_user.can_view_survey_answers?(@order)
end
end
4 changes: 4 additions & 0 deletions app/models/concerns/users/survey_manipulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ def can_create_surveys?
def can_delete_surveys?
super_admin?
end

def can_view_survey_answers?(order)
super_admin?
end
end
end
1 change: 1 addition & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Order < ApplicationRecord
has_many :order_program_details, autosave: true
has_many :items, through: :order_details
has_many :tracking_details
has_many :survey_answers

include OrderStatus

Expand Down
4 changes: 4 additions & 0 deletions app/models/survey_answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ class SurveyAnswer < ApplicationRecord
belongs_to :order, optional: true
belongs_to :creator, class_name: "User", optional: true
belongs_to :last_updated_by, class_name: "User", optional: true

def answers
survey_revision.to_definition.deserialize_answers(answer_data)
end
end
12 changes: 12 additions & 0 deletions app/views/orders/_order_survey_answers.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% if current_user.can_view_survey_answers?(order) %>
<% if order.survey_answers.present? %>
<% if local_assigns[:print] != false %>
<%= link_to "Print Survey Answers", survey_answers_order_path(order), class: "btn btn-default" %>
<% end %>
<% order.survey_answers.each do |answer| %>
<h3><%= answer.survey_revision.survey.title %></h3>
<%= render partial: "surveys/survey_answers", locals: { survey: answer.survey_revision.survey, revision: answer.survey_revision, answers: answer.answers } %>
<% end %>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions app/views/orders/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<% else %>
<%= render partial: "editable_order_table" %>
<% end %>
<%= render partial: "order_survey_answers", locals: { order: @order } %>
<%= render partial: "order_buttons", locals: { order: @order } %>
<% end %>
</div>
Expand Down
10 changes: 10 additions & 0 deletions app/views/orders/survey_answers.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% content_for :title, "Print Survey Answers for Order ##{@order.id}" %>
<% content_for :content do %>
<div class="hidden-print">
<%= link_to "Return to Order", edit_order_path(@order), class: "btn btn-primary" %>
</div>

<h2 class="visible-print-block">Survey answers for Order #<%= @order.id %></h2>
<%= render partial: "order_survey_answers", locals: { order: @order, print: false } %>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

member do
post :sync
get :survey_answers
end
end

Expand Down

0 comments on commit 49ee75a

Please sign in to comment.