Skip to content

Commit

Permalink
Update views
Browse files Browse the repository at this point in the history
+ precompile styles
+ Fix manager view questionnaire progress calculation
+ Update manager view data
+ Update answers view to represent a list of answers
  • Loading branch information
ciscoLegrand committed Oct 28, 2024
1 parent 9e2a61a commit 17ba34d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/assets/builds/oodle.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/models/oodle/user_questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ class UserQuestionnaire < ApplicationRecord
belongs_to :questionnaire, class_name: "Oodle::Questionnaire"

has_many :answers, through: :questionnaire
has_many :questions, through: :questionnaire

scope :completed, -> { where(completed: true, progress: 100) }
scope :incompleted, -> { where(completed: false).where("progress < ?", 100) }
scope :incompleted, -> { where("progress < ?", 100) }

def update_progress = update! progress: ((answers.count.to_f / questionnaire.questions.count) * 100)

Check failure on line 12 in app/models/oodle/user_questionnaire.rb

View workflow job for this annotation

GitHub Actions / lint

Lint/Syntax: unexpected token tEQL (Using Ruby 2.7 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)

Expand Down
52 changes: 18 additions & 34 deletions app/views/oodle/answers/_answer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
show_action = link_to("Show", answer, data: { turbo_frame: "_top" }, class: "btn btn-show btn-show-hover btn-show-focus transition-base")
manager_actions = [
link_to("Edit", edit_answer_path(answer), data: { turbo_frame: "_top" }, class: "btn btn-edit btn-edit-hover btn-edit-focus transition-base", aria: { label: "Edit answer" }),
button_to("Destroy", answer, 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 answer" })
]
back_button = link_to("Back", answers_path, class: "w-auto btn btn-back btn-back-hover btn-back-focus transition-base")

Expand All @@ -12,36 +11,21 @@ actions.concat(manager_actions) if Current.user.manager?
# actions.concat([back_button]) if action_name == "show"
%>

<%= render Oodle::CardComponent.new(
title: answer.user.email_address,
id: dom_id(answer),
actions: actions
) do %>

<section id="<%= dom_id(answer) %>" class=" rounded-lg relative px-8 py-6">
<p class="my-5 flex flex-col gap-4">
<strong>Questionnaire:</strong>
<%= answer.questionnaire.name %>
</p>

<p class="my-5 flex flex-col gap-4">
<strong class="label">Question: <%= answer.question.name%></strong>
<%= answer.question.description %>
</p>

<p class="my-5 flex gap-4">
<strong class="label">Response:</strong>
<%= answer.result['selected'] %>
</p>

<p class="my-5 flex gap-4">
<strong class="label">Score:</strong>
<%= answer.score %>
</p>

<p class="my-5 flex gap-4">
<strong class="label">Answered at:</strong>
<%= answer.answered_at.strftime("%d-%m-%y %H:%M") %>
</p>
</section>
<% end %>
<div class="grid grid-cols-9 gap-4 p-4 items-center text-sm hover:bg-gray-50">
<div class="text-blue-600 hover:underline">
<%= link_to answer.user.email_address, user_path(answer.user) %>
</div>
<div class="text-blue-600 hover:underline">
<%= link_to answer.questionnaire.name, questionnaire_path(answer.questionnaire) %>
</div>
<div class="col-span-2"><%= answer.question.description %></div>
<div class="text-right"><%= answer.result["selected"].is_a?(Array) ? answer.result["selected"].join(", ") : answer.result["selected"] %></div>
<div class="text-right"><%= answer.question.items.map(&:correct_value).uniq.join(", ") %></div>
<div class="text-right"><%= number_with_precision(answer.score, precision: 2) %></div>
<div class="text-right"><%= answer.answered_at.strftime("%d-%m-%y %H:%M") %></div>
<div class="flex justify-end space-x-2">
<% actions.each do |action| %>
<%= action %>
<% end %>
</div>
</div>
16 changes: 14 additions & 2 deletions app/views/oodle/answers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
<%= render "layouts/shared/pagy", pagy: @pagy if @pagy.present? %>
</div>

<div id="answers" class="w-full grid grid-cols-3 gap-4 ">
<%= render @answers%>
<div class="bg-white shadow-md rounded-lg overflow-hidden">
<div class="grid grid-cols-9 gap-4 p-4 bg-gray-100 font-semibold text-sm text-gray-700">
<div class="">Student</div>
<div>Questionnaire</div>
<div class="col-span-2">Question</div>
<div class="text-right">Response</div>
<div class="text-right">Correct Values</div>
<div class="text-right">Score</div>
<div class="text-right">Answered At</div>
<div class="text-right">Actions</div>
</div>
<div class="divide-y divide-gray-200">
<%= render partial: 'answer', collection: @answers, as: :answer %>
</div>
</div>
</section>
13 changes: 7 additions & 6 deletions app/views/oodle/dashboard/_manager.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
<% @students.each do |student| %>
<div class="bg-white shadow-lg rounded-lg p-6">
<h3 class="text-xl font-bold mb-2"><%= student.email_address %></h3>
<p class="text-gray-600">Total Progress: <%= student.user_questionnaires.sum(&:progress).round(2) %>%</p>
<% calculated_progress = student.user_questionnaires.count.positive? ? student.user_questionnaires.sum(&:progress) / student.user_questionnaires.count : 0%>
<p class="text-gray-600">Total Progress: <%= number_to_percentage(calculated_progress, precision: 2) %></p>
<div class="w-full bg-gray-200 rounded-full h-2.5 mt-2">
<div class="bg-green-500 h-2.5 rounded-full" style="width: <%= student.user_questionnaires.sum(&:progress).round(2) %>%"></div>
<div class="bg-green-500 h-2.5 rounded-full" style="width: <%= calculated_progress.round(2) %>%"></div>
</div>
<p class="text-gray-600">Completed Questionnaires: <%= student.user_questionnaires.where(completed: true).count %></p>
<p class="text-gray-600">Incomplete Questionnaires: <%= student.user_questionnaires.where(completed: false).count %></p>
<p class="text-gray-600">Total Score: <%= student.user_questionnaires.sum(&:score).round(2) %></p>
<p class="text-gray-600">Completed Questionnaires: <%= student.user_questionnaires.completed.count %></p>
<p class="text-gray-600">Incomplete Questionnaires: <%= student.user_questionnaires.incompleted.count %></p>
</div>
<% end %>
</div>
Expand All @@ -54,7 +54,8 @@
<div class="w-full bg-gray-200 rounded-full h-2.5 mt-2">
<div class="bg-yellow-500 h-2.5 rounded-full" style="width: <%= user_questionnaire.progress.round(2) %>%"></div>
</div>
<p class="text-gray-600">Total Score: <%= user_questionnaire.score %></p>
<p class="text-gray-600">Answers Score: <%= user_questionnaire.score %></p>
<p class="text-gray600">Total Score: <%= user_questionnaire.questions.sum(&:score).round(2) %></p>
<p class="text-gray-600"><%= user_questionnaire.completed? ? 'Completed' : 'In Progress' %></p>
</div>
<% end %>
Expand Down

0 comments on commit 17ba34d

Please sign in to comment.