Skip to content

Commit

Permalink
Update questionnaires views conditionally by role
Browse files Browse the repository at this point in the history
- Update manager questionnaire views
- Update student quesitonnaire views
- Render answer form for each question in a questionnaire for a student
  • Loading branch information
ciscoLegrand committed Oct 23, 2024
1 parent c5b1369 commit 750fd22
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 20 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 @@ -7,7 +7,7 @@ def index
if Current.user.manager?
@students = Current.user.students.pluck(:id, :email_address)
@answers = Answer.where(user_id: @students[0])
elsif Current.user.studend? || Current.user.user?
elsif Current.user.student? || Current.user.user?
@answers = Current.user.answers
else
@answers = Answer.all
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/oodle/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<%= link_to "Items", oodle.items_path, class: "font-bold #{'nav-link-active' if request.url.include?('items')}" %>
<%= link_to "Answers", oodle.answers_path, class: "font-bold #{'nav-link-active' if request.url.include?('answers')}" %>
<% else %>
<%= link_to "Questionnaires", oodle.questionnaires_path, class: "font-bold #{'nav-link-active' if request.url.include?('questionnaires')}" %>
<%= link_to "My Questionnaires", oodle.questionnaires_path(sorted: 'open'), class: "font-bold #{'nav-link-active' if request.url.include?('questionnaires')}" %>
<%#= link_to "My questionnaires", oodle.user_path(Current.user), class: "font-bold" %>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/oodle/answers/_answer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ back_button = link_to("Back", answers_path, class: "w-auto btn btn-back btn-back
actions = []
actions = [show_action] unless action_name == "show"
actions.concat(manager_actions) if Current.user.manager?
actions.concat([back_button]) if action_name == "show"
# actions.concat([back_button]) if action_name == "show"
%>

<%= render Oodle::CardComponent.new(
Expand Down
7 changes: 1 addition & 6 deletions app/views/oodle/answers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
</ul>
</div>
<% end %>

<h1 class="text-xl font-bold">
<%= question.description %>
</h1>


<div class="my-5 flex flex-col gap-4">
<% if question.free_text? %>
<%= form.text_area :result, rows: 10, class: "w-full" %>
Expand All @@ -37,6 +33,5 @@
<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 %>
2 changes: 0 additions & 2 deletions app/views/oodle/items/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<p style="color: green"><%= notice %></p>

<%= render @item %>
46 changes: 39 additions & 7 deletions app/views/oodle/questionnaires/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
<div class="flex flex-col gap-4 my-4">
<%= render @questionnaire %>

<% if Current.user.manager? %>
<div class="flex flex-col gap-4 my-4">
<%= render @questionnaire %>

<div class="flex flex-col gap-4">
<h1 class="text-xl">Questions: <%= @questionnaire.questions.count %></h1>
<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 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>
</div>
<% else %>
<div class="grid grid-cols-4 gap-4 relative">
<div class="col-span-1 sticky top-0">
<%= render @questionnaire %>
</div>
<div class="col-span-3 flex flex-col gap-6">
<% @questionnaire.questions.each do |q| %>
<% @answer = Current.user
.answers
.find_by(questionnaire_id: params[:id],question_id: q.id) %>
<% if @answer.present? %>
<%= render @answer %>
<% else %>
<%= render Oodle::CardComponent.new(
title: q.description,
id: dom_id(q),
actions: []
) do %>
<%= render "oodle/answers/form",
answer: Oodle::Answer.new,
questionnaire: @questionnaire,
question: q %>
<% end %>

<% end %>
<% end %>
</div>
</div>
<% end %>

5 changes: 3 additions & 2 deletions app/views/oodle/questions/_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ manager_actions = [
link_to("Edit", edit_question_path(question), data: { turbo_frame: "_top" }, class: "btn btn-edit btn-edit-hover btn-edit-focus transition-base", aria: { label: "Edit question" }),
button_to("Destroy", question, method: :delete, data: { turbo_confirm: "Are you sure?", turbo_frame: "_top" }, class: "btn btn-delete btn-delete-hover btn-delete-focus transition-base", aria: { label: "Delete question" })
]
student_actions = [link_to("Answered", new_answer_path(questionnaire_id: params[:id], question_id: question.id), data: { turbo_frame: "_top" }, class: "btn btn-show btn-show-hover btn-show-focus transition-base")]
back_button = link_to("Back", questions_path, class: "w-auto btn btn-back btn-back-hover btn-back-focus transition-base")

actions = []
actions = [show_action] unless action_name == "show"
actions.concat(manager_actions) if Current.user.manager?
Current.user.manager? ? actions.concat(manager_actions) : actions.concat(student_actions)
actions.concat([back_button]) if action_name == "show"
%>

Expand All @@ -18,7 +19,7 @@ actions.concat([back_button]) if action_name == "show"
actions: actions
) do %>

<section id="<%= dom_id(question) %>" class=" rounded-lg relative px-8 py-6">
<section id="<%= dom_id(question) %>" class=" rounded-lg relative px-8 py-6 <%= Current.user.answers.find_by(questionnaire_id: params[:id],question_id: question.id).present? ? "bg-blue-100" : "" %>">
<p class="my-5 flex flex-col gap-4">
<strong class="label">Description:</strong>
<%= question.description %>
Expand Down

0 comments on commit 750fd22

Please sign in to comment.