Skip to content

Commit

Permalink
Style views and redirect to questionnaire when answers is created.
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoLegrand committed Oct 21, 2024
1 parent be0fb3d commit 1b2becb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/controllers/oodle/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def create

respond_to do |format|
if @answer.save
format.html { redirect_to @answer, notice: "Answer was successfully created." }
format.html { redirect_to questionnaire_path(@answer.questionnaire.id), notice: "Answer was successfully created." }
format.json { render :show, status: :created, location: @answer }
else
format.html { render :new }
Expand Down
5 changes: 3 additions & 2 deletions app/views/oodle/answers/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= form_with(model: [answer], local: true, class: "contents") do |form| %>
<%= form_with(model: [answer], local: true, class: "container mx-auto px-4") do |form| %>
<% if answer.errors.any? %>
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
<h2><%= pluralize(answer.errors.count, "error") %> prohibited this answer from being saved:</h2>
Expand All @@ -14,7 +14,7 @@
<%= question.description %>
</h1>

<div class="my-5">
<div class="my-5 flex flex-col gap-4">
<% if question.free_text? %>
<%= form.text_area :result, rows: 10, class: "w-full" %>
<% else %>
Expand All @@ -37,5 +37,6 @@
<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
<%= form.submit 'Next', commit: :next, class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
<%= link_to "Back to questionnaire", questionnaire_path(@questionnaire.id), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
</div>
<% end %>
8 changes: 4 additions & 4 deletions app/views/oodle/answers/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% content_for :title, "New answer" %>

<h1>New answer</h1>
<%= render "form", answer: @answer, question: @question, questionnaire: @questionnaire %>

<%= link_to "Back to questionnaire", questionnaire_path(@questionnaire.id), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<div class="w-1/3 mx-auto flex flex-col justify-center gap-4">
<h1 class="text-3xl font-semibold text-gray-800">Answer</h1>
<%= render "form", answer: @answer, question: @question, questionnaire: @questionnaire %>
</div>
10 changes: 0 additions & 10 deletions app/views/oodle/questionnaires/_questionnaire.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,3 @@
<%= button_to "Mark as completed", mark_as_completed_answer_path(params[:id]), method: :post, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" if questionnaire.available? && !@user_questionnaire.completed? %>
<% end %>
<% end %>

<% if action_name == "show" %>

<h1 class="text-xl">Questions: <%= @questionnaire.questions.count %></h1>

<div id="questions" class="min-w-full">
<%= render partial: "oodle/questions/question", collection: @questionnaire.questions, as: :question %>
</div>

<% end %>
6 changes: 0 additions & 6 deletions app/views/oodle/questionnaires/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
<h1>New questionnaire</h1>

<%= render "form", questionnaire: @questionnaire %>

<br>

<div>
<%= link_to "Back to questionnaires", questionnaires_path %>
</div>
13 changes: 11 additions & 2 deletions app/views/oodle/questionnaires/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<p style="color: green"><%= notice %></p>
<div class="flex flex-col gap-4 my-4">
<p style="color: green"><%= notice %></p>

<%= render @questionnaire %>
<%= render @questionnaire %>

<div class="flex flex-col gap-4">
<h1 class="text-xl">Questions: <%= @questionnaire.questions.count %></h1>

<div id="questions" class="min-w-full grid grid-cols-3 gap-4">
<%= render partial: "oodle/questions/question", collection: @questionnaire.questions, as: :question %>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/oodle/questions/_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<%= question.score %>
</p>

<%= link_to "Show", question, class: "px-3 py-1.5 border border-blue-500 text-blue-500 hover:bg-blue-200 hover:text-blue-700 rounded-md font-medium" %>
<%= link_to "Show", question, class: "px-3 py-1.5 border border-blue-500 text-blue-500 hover:bg-blue-200 hover:text-blue-700 rounded-md font-medium" if Current.user.manager?%>

<% if action_name == "show" && Current.user.user? %>
<% if action_name == "show" && Current.user.user? && Current.user.answers.find_by(question_id: question.id).nil? %>
<%= link_to "Answer this question", new_answer_path({ user_id: Current.user.id, questionnaire_id: @questionnaire.id, question_id: question.id}), data: { turbo_frame: '_top'}, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
<% end %>

Expand Down

0 comments on commit 1b2becb

Please sign in to comment.