-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from fhmurakami/feat/report
It introduces a new feature to generate reports that compile the answers from a group of participants for a specific set of equations, providing a comprehensive overview of their responses
- Loading branch information
Showing
31 changed files
with
622 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
class ReportsController < ApplicationController | ||
before_action :set_report, only: %i[ show destroy ] | ||
|
||
# GET /reports or /reports.json | ||
def index | ||
@reports = current_admin.reports | ||
end | ||
|
||
# GET /reports/1 or /reports/1.json | ||
def show | ||
if @report.nil? | ||
@reports = current_admin.reports | ||
flash.now[:alert] = I18n.t("reports.errors.not_found") | ||
render :index | ||
end | ||
end | ||
|
||
# DELETE /reports/1 or /reports/1.json | ||
def destroy | ||
@report.destroy! | ||
|
||
respond_to do |format| | ||
format.html { redirect_to reports_path, status: :see_other, notice: I18n.t("reports.destroyed") } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_report | ||
@report = Report.find_by_id(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def report_params | ||
params.require(:report).permit(:user_admin_id, :collection_id, :grouping_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Report < ApplicationRecord | ||
belongs_to :user_admin, class_name: "User::Admin", foreign_key: "user_admin_id" | ||
belongs_to :collection | ||
belongs_to :grouping | ||
|
||
has_many :participants, class_name: "User::Participant", | ||
foreign_key: :user_participant_id, through: :grouping | ||
has_many :rounds | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
class Round < ApplicationRecord | ||
belongs_to :collection | ||
belongs_to :participant, class_name: "User::Participant", foreign_key: "user_participant_id" | ||
belongs_to :report, optional: true | ||
|
||
has_many :answers | ||
|
||
validates :user_participant_id, uniqueness: { scope: :collection_id } | ||
validate :rounds_length | ||
|
||
private | ||
|
||
def rounds_length | ||
report = Report.find_by(collection: collection) | ||
grouping = report&.grouping | ||
|
||
if report && grouping | ||
rounds = report&.rounds | ||
participants = grouping&.participants | ||
|
||
if rounds && participants | ||
return true if rounds.length <= participants.length | ||
|
||
errors.add( | ||
:base, | ||
:too_many_rounds, | ||
grouping: grouping.name, | ||
count: grouping.participants.length | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Report::CreateService | ||
def initialize(user_admin, collection, grouping) | ||
@user_admin = user_admin | ||
@collection = collection | ||
@grouping = grouping | ||
end | ||
|
||
def self.call(user_admin:, collection:, grouping:) | ||
new(user_admin, collection, grouping).call | ||
end | ||
|
||
def call | ||
create_report | ||
end | ||
|
||
def create_report | ||
@report = Report.find_or_create_by( | ||
user_admin: @user_admin, | ||
collection: @collection, | ||
grouping: @grouping | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<div id="<%= dom_id report %>"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th colspan="10"> | ||
<strong><%= report.grouping.name %></strong> | ||
</th> | ||
</tr> | ||
<tr> | ||
<th><strong><%= t("activerecord.models.collection") %></strong></th> | ||
<th colspan="9" class="pr-9"><%= report.collection.name %></th> | ||
</tr> | ||
</thead> | ||
<% report.rounds.each do |round| %> | ||
<thead> | ||
<tr> | ||
<th><strong><%= t("activerecord.models.user/participant") %></strong></th> | ||
<th colspan="9" class="pr-9"><%= round.participant.full_name %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<th rowspan="<%= round.collection.equations.size + 1 %>"> | ||
<strong><%= t("activerecord.models.equation").pluralize %></strong> | ||
</th> | ||
<th><%= t("activerecord.attributes.equation.position_a") %></th> | ||
<th><%= t("activerecord.attributes.equation.operator") %></th> | ||
<th><%= t("activerecord.attributes.equation.position_b") %></th> | ||
<th><%= t("activerecord.attributes.equation.position_c") %></th> | ||
<th><%= t("activerecord.attributes.equation.unknown_position") %></th> | ||
<th rowspan="<%= round.collection.equations.size + 1 %>"> | ||
<strong><%= t("activerecord.models.answer").pluralize %></strong> | ||
</th> | ||
<th><%= t("activerecord.attributes.answer.answer_value") %></th> | ||
<th><%= t("activerecord.attributes.answer.correct_answer") %></th> | ||
<th><%= t("activerecord.attributes.answer.time") %></th> | ||
</tr> | ||
<% round.answers.each do |answer| %> | ||
<tr> | ||
<td><%= answer.equation.position_a %></td> | ||
<td><%= answer.equation.operator %></td> | ||
<td><%= answer.equation.position_b %></td> | ||
<td><%= answer.equation.position_c %></td> | ||
<td><%= answer.equation.unknown_position %></td> | ||
<td><%= answer.answer_value %></td> | ||
<td><%= answer.correct_answer ? "✔️" : "❌" %></td> | ||
<td><%= answer.formatted_time %></td> | ||
</tr> | ||
<% end %> | ||
<% end %> | ||
</tbody> | ||
<tfoot></tfoot> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
json.extract! report, :id, :user_admin_id, :user_participant_id, :collection_id, :grouping_id, :created_at, :updated_at | ||
json.url report_url(report, format: :json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% content_for :title, t("activerecord.models.report").pluralize %> | ||
<main class="background"> | ||
<section class="blur"> | ||
<%= render "shared/header" %> | ||
<h2><%= t("activerecord.models.report").pluralize %></h2> | ||
<div class="reports"> | ||
<div id="reports"> | ||
<% @reports.each do |report| %> | ||
<div class="card report"> | ||
<%= render report %> | ||
<%= link_to t("reports.show"), report %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<%= link_to t("home.back"), root_path, class: "btn mustard btn-text-black" %> | ||
</div> | ||
</section> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.array! @reports, partial: "reports/report", as: :report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<main class="background"> | ||
<section class="blur"> | ||
<%= render "shared/header" %> | ||
<div class="panel report"> | ||
<%= render @report %> | ||
<div class="actions"> | ||
<%= link_to t("reports.back"), reports_path %> | ||
<%= button_to t("reports.delete"), @report, class: "btn crimson", method: :delete, data: { turbo_method: :delete } %> | ||
</div> | ||
</div> | ||
</section> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
json.partial! "reports/report", report: @report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.