Skip to content

Commit

Permalink
Added in what I beleive were the necessary files from the previous im…
Browse files Browse the repository at this point in the history
…plementations various models,views and controllers were added or modified based on the previous teams pull request - Erik Lopez-Godinez
  • Loading branch information
ErikLG360 committed Dec 2, 2023
1 parent d31c43b commit e28a857
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/controllers/grades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,17 @@ def save_grade_and_comment_for_submission
@team = participant.team
@team.grade_for_submission = params[:grade_for_submission]
@team.comment_for_submission = params[:comment_for_submission]
# E2237 - create a grading history entry for this assignment
# save the grade, comment, receiver, and instructor
# this should be updated to Rails 5 convention at some point
# but it works for now
begin
GradingHistory.create(instructor_id: session[:user].id,
assignment_id: participant.assignment.id,
grading_type: "Submission",
grade_receiver_id: @team.id,
grade: @team.grade_for_submission,
comment: @team.comment_for_submission)
@team.save
flash[:success] = 'Grade and comment for submission successfully saved.'
rescue StandardError
Expand Down
44 changes: 44 additions & 0 deletions app/controllers/grading_histories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class GradingHistoriesController < ApplicationController
include AuthorizationHelper
before_action :set_grading_history, only: %i[show]

# Checks if user is allowed to view a grading history
def action_allowed?
# admins and superadmins are always allowed
return true if current_user_has_admin_privileges?
# populate assignment fields
assignment_for_history(params[:grade_type])
# if not admin/superadmin, check permissions
if @assignment.instructor_id == current_user.id
true
elsif TaMapping.exists?(ta_id: current_user.id, course_id: @assignment.course_id) &&
(TaMapping.where(course_id: @assignment.course_id).include? TaMapping.where(ta_id: current_user.id, course_id: @assignment.course_id).first)
true
elsif @assignment.course_id && Course.find(@assignment.course_id).instructor_id == current_user.id
true
end
end

# populate the assignment fields according to type
def assignment_for_history(type)
# for a submission, the receiver is an AssignmentTeam
# use this AssignmentTeam to find the assignment
if type.eql? "Submission"
assignment_team = AssignmentTeam.find(params[:grade_receiver_id])
@assignment = Assignment.find(assignment_team.parent_id)
end
# for a review, the receiver is an AssignmentParticipant
# use this AssignmentParticipant to find the assignment
if type.eql? "Review"
participant_id = params[:participant_id]
grade_receiver = AssignmentParticipant.find(participant_id)
@assignment = Assignment.find(grade_receiver.parent_id)
end
end

# return all grading history entries for the assignment
# entries are returned in chronological order
def index
@grading_histories = GradingHistory.where(grade_receiver_id: params[:grade_receiver_id], grading_type: params[:grade_type]).reverse_order
end
end
10 changes: 10 additions & 0 deletions app/controllers/review_mapping_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,17 @@ def save_grade_and_comment_for_reviewer
review_grade.attributes = review_mapping_params
review_grade.review_graded_at = Time.now
review_grade.reviewer_id = session[:user].id
# E2237 create a grading history entry for this review
# save the grade, comment, receiver, and instructor
# this should be updated to Rails 5 convention at some point
# but it works for now
begin
GradingHistory.create(instructor_id: session[:user].id,
assignment_id: params[:assignment_id],
grading_type: "Review",
grade_receiver_id: Participant.find(params[:participant_id]).user_id,
grade: params[:grade_for_reviewer],
comment: params[:comment_for_reviewer])
review_grade.save!
flash[:success] = 'Grade and comment for reviewer successfully saved.'
rescue StandardError
Expand Down
4 changes: 4 additions & 0 deletions app/models/grading_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class GradingHistory < ActiveRecord::Base
belongs_to :instructor, inverse_of: :instructor_id
belongs_to :assignment, inverse_of: :assignment_id
end
4 changes: 4 additions & 0 deletions app/models/review_grading_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ReviewGradingHistory < GradingHistory
attr_protected
belongs_to :grade_receiver, class_name: 'Participant', inverse_of: :grade_receiver_id
end
4 changes: 4 additions & 0 deletions app/models/submission_grading_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class SubmissionGradingHistory < GradingHistory
attr_protected
belongs_to :grade_receiver, class_name: 'Team', inverse_of: :grade_receiver_id
end
2 changes: 2 additions & 0 deletions app/views/assignments/list_submissions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
<td width="10%">

<%= link_to "History", submission_records_path(team_id: team.id) %>
<!--E2237 Added Link for the Grading History for a submission-->
<%= link_to "Grading History", grading_histories_path(grade_receiver_id: team.id, grade_type: "Submission") %>

</td>
</tr>
Expand Down
10 changes: 10 additions & 0 deletions app/views/grading_histories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
= form_for @grading_history do |f|
- if @grading_history.errors.any?
#error_explanation
%h2= "#{pluralize(@grading_history.errors.count, "error")} prohibited this grading_history from being saved:"
%ul
- @grading_history.errors.full_messages.each do |message|
%li= message

.actions
= f.submit 'Save'
7 changes: 7 additions & 0 deletions app/views/grading_histories/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%h1 Editing grading_history

= render 'form'

= link_to 'Show', @grading_history
\|
= link_to 'Back', grading_histories_path
38 changes: 38 additions & 0 deletions app/views/grading_histories/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<% record = @grading_histories[0]
if record == nil
receiver = ""
assignment = ""
else
if record.grading_type == "Submission"
receiver = "of " + Team.where(id: record.grade_receiver_id).pluck(:name).first
assignment = "for the submission " + Assignment.where(id: record.assignment_id).pluck(:name).first
else
receiver = "of " + User.where(id: record.grade_receiver_id).pluck(:fullname).first
assignment = "for review in " + Assignment.where(id: record.assignment_id).pluck(:name).first
end

end
%>
<h1 class="center">Grade History <%= receiver %> <%= assignment %></h1>

<table style="border-collapse:collapse; table-layout:fixed; width:1500px;">
<thead>
<tr>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Instructor</th>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Grade</th>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Comment</th>
<th style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;">Graded At</th>
</tr>

<!--This is the main view of the table. This will add table with either hyperlink or the content nased on the operation. -->
<tbody>
<% @grading_histories.each do |record| %>
<tr>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= User.where(id: record.instructor_id).pluck(:fullname).first %></td>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= record.grade %></td>
<td style="padding:10px; border:solid 1.5px black; width:60px; word-wrap:break-word;"><%= record.comment %></td>
<td style="padding:10px; border:solid 1.5px black; width:50px; word-wrap:break-word;"><%= record.created_at %></td>
</tr>
<% end %>
</tbody>
</table>
5 changes: 5 additions & 0 deletions app/views/grading_histories/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%h1 New grading_history

= render 'form'

= link_to 'Back', grading_histories_path
6 changes: 6 additions & 0 deletions app/views/grading_histories/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%p#notice= notice


= link_to 'Edit', edit_grading_history_path(@grading_history)
\|
= link_to 'Back', grading_histories_path
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Expertiza::Application.routes.draw do
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
#E2383 added path for grading histories
resources :grading_histories, only: [:index]

resources :admin, only: [] do
collection do
Expand Down

0 comments on commit e28a857

Please sign in to comment.