diff --git a/app/controllers/gradebooks_controller.rb b/app/controllers/gradebooks_controller.rb index 38eba05330e..84afcc06da9 100644 --- a/app/controllers/gradebooks_controller.rb +++ b/app/controllers/gradebooks_controller.rb @@ -137,7 +137,7 @@ class GradebooksController < ApplicationController student_enrollment.find_score(course_score: true) end - js_hash[:effective_final_grade] = total_score.effective_final_grade if total_score.overridden? + js_hash[:effective_final_score] = total_score.effective_final_score if total_score.overridden? end js_env(js_hash) diff --git a/app/jsx/grading/GradeSummary.js b/app/jsx/grading/GradeSummary.js index 1ce82caca83..ee72e75e2bf 100644 --- a/app/jsx/grading/GradeSummary.js +++ b/app/jsx/grading/GradeSummary.js @@ -361,11 +361,26 @@ function calculateTotals (calculatedGrades, currentOrFinal, groupWeightingScheme const scoreAsPercent = calculateGrade(finalScore, finalPossible) let finalGrade + let letterGrade let teaserText - if (!gradeChanged && ENV.grading_scheme && ENV.effective_final_grade) { - finalGrade = formatPercentGrade(gradeToScoreLowerBound(ENV.effective_final_grade, ENV.grading_scheme)) + if (gradingSchemeEnabled()) { + const scoreToUse = overrideScorePresent() ? + ENV.effective_final_score : + calculatePercentGrade(finalScore, finalPossible) + + letterGrade = scoreToGrade(scoreToUse, ENV.grading_scheme) + $('.final_grade .letter_grade').text(letterGrade) + } + + if (!gradeChanged && overrideScorePresent()) { teaserText = scoreAsPoints + + if (gradingSchemeEnabled()) { + finalGrade = formatPercentGrade(gradeToScoreLowerBound(letterGrade, ENV.grading_scheme)) + } else { + finalGrade = formatPercentGrade(ENV.effective_final_score) + } } else if (showTotalGradeAsPoints && groupWeightingScheme !== 'percent') { finalGrade = scoreAsPoints teaserText = scoreAsPercent @@ -391,15 +406,21 @@ function calculateTotals (calculatedGrades, currentOrFinal, groupWeightingScheme $.screenReaderFlashMessageExclusive(msg) } - if (ENV.grading_scheme) { - $('.final_letter_grade .grade').text( - ENV.effective_final_grade || scoreToGrade(calculatePercentGrade(finalScore, finalPossible), ENV.grading_scheme) - ) - } - $('.revert_all_scores').showIf($('#grades_summary .revert_score_link').length > 0) } +// This element is only rendered by the erb if the course has enabled grading +// schemes. We can't rely on only checking for the presence of +// ENV.grading_scheme as that, in this case, always returns Canvas's default +// grading scheme even if grading schemes are not enabled. +function gradingSchemeEnabled() { + return $('.final_grade .letter_grade').length > 0 && ENV.grading_scheme +} + +function overrideScorePresent() { + return ENV.effective_final_score != null +} + function updateStudentGrades () { const droppedMessage = I18n.t('This assignment is dropped and will not be considered in the total calculation') const ignoreUngradedSubmissions = $('#only_consider_graded_assignments').attr('checked') diff --git a/app/views/gradebooks/grade_summary.html.erb b/app/views/gradebooks/grade_summary.html.erb index 39bccf6f336..8104d829e51 100644 --- a/app/views/gradebooks/grade_summary.html.erb +++ b/app/views/gradebooks/grade_summary.html.erb @@ -36,9 +36,7 @@
<%= before_label(:total, "Total") %> <% if @context.grading_standard_enabled? %> - - (-) - + () <% end %>
<% end %> diff --git a/spec/controllers/gradebooks_controller_spec.rb b/spec/controllers/gradebooks_controller_spec.rb index 534556640ed..945ae00ec0d 100644 --- a/spec/controllers/gradebooks_controller_spec.rb +++ b/spec/controllers/gradebooks_controller_spec.rb @@ -232,27 +232,27 @@ describe GradebooksController do @student_enrollment.scores.find_by(course_score: true).update!(override_score: 99) end - it "includes the effective final grade in the ENV" do + it "includes the effective final score in the ENV" do user_session(@teacher) get :grade_summary, params: { course_id: @course.id, id: @student.id } - expect(assigns[:js_env][:effective_final_grade]).to eq "A" + expect(assigns[:js_env][:effective_final_score]).to eq 99 end - it "does not include the effective final grade in the ENV if the feature is disabled" do + it "does not include the effective final score in the ENV if the feature is disabled" do @course.disable_feature!(:final_grades_override) user_session(@teacher) get :grade_summary, params: { course_id: @course.id, id: @student.id } - expect(assigns[:js_env].key?(:effective_final_grade)).to be false + expect(assigns[:js_env].key?(:effective_final_score)).to be false end - it "does not include the effective final grade in the ENV if there is no override score" do + it "does not include the effective final score in the ENV if there is no override score" do @student_enrollment.scores.find_by(course_score: true).update!(override_score: nil) user_session(@teacher) get :grade_summary, params: { course_id: @course.id, id: @student.id } - expect(assigns[:js_env].key?(:effective_final_grade)).to be false + expect(assigns[:js_env].key?(:effective_final_score)).to be false end - it "takes the effective final grade for the grading period, if present" do + it "takes the effective final score for the grading period, if present" do grading_period_group = @course.grading_period_groups.create! grading_period = grading_period_group.grading_periods.create!( title: "a grading period", @@ -262,13 +262,13 @@ describe GradebooksController do @student_enrollment.scores.find_by(grading_period: grading_period).update!(override_score: 84) user_session(@teacher) get :grade_summary, params: { course_id: @course.id, id: @student.id } - expect(assigns[:js_env][:effective_final_grade]).to eq "B" + expect(assigns[:js_env][:effective_final_score]).to eq 84 end - it "takes the effective final grade for the course score, if viewing all grading periods" do + it "takes the effective final score for the course score, if viewing all grading periods" do user_session(@teacher) get :grade_summary, params: { course_id: @course.id, id: @student.id, grading_period_id: 0 } - expect(assigns[:js_env][:effective_final_grade]).to eq "A" + expect(assigns[:js_env][:effective_final_score]).to eq 99 end end diff --git a/spec/javascripts/jsx/grading/GradeSummarySpec.js b/spec/javascripts/jsx/grading/GradeSummarySpec.js index 37b610e3141..b1f86c68a40 100644 --- a/spec/javascripts/jsx/grading/GradeSummarySpec.js +++ b/spec/javascripts/jsx/grading/GradeSummarySpec.js @@ -92,11 +92,9 @@ function setPageHtmlFixture() {
- ( - + ) -