show warning in gb1 for invalid assignment groups

closes CNVS-1924

Test plan:
  * set up one or more assignment groups that have no points possible
  * go to gradebook1
  * you should see similar warnings to the ones that appear in gb2

Change-Id: Icf11684e020a3eff4e654ebf73ee9ad2b9c159b1
Reviewed-on: https://gerrit.instructure.com/17069
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Myller de Araujo <myller@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
This commit is contained in:
Cameron Matheson 2013-01-23 01:30:49 -07:00
parent 4de8992575
commit 62e4d84dd8
7 changed files with 63 additions and 77 deletions

View File

@ -799,14 +799,14 @@ define [
if invalidAssignmentGroups.length > 0
groupNames = (ag.name for ag in invalidAssignmentGroups)
@totalGradeWarning = I18n.t 'invalid_assignment_groups_warning'
, "Score does not include %{groups} because %{pronoun_has} no
points possible"
, groups: $.toSentence(groupNames)
, pronoun_has: if invalidAssignmentGroups.length == 1
I18n.t('it_has', 'it has')
else
I18n.t('they_have', 'they have')
@totalGradeWarning = I18n.t 'invalid_assignment_groups_warning',
one: "Score does not include %{groups} because it has
no points possible"
other: "Score does not include %{groups} because they have
no points possible"
,
groups: $.toSentence(groupNames)
count: groupNames.length
else
# no assignments have points possible

View File

@ -191,6 +191,7 @@ class GradebooksController < ApplicationController
@context.enrollments.sort_by{|e| [e.state_sortable, e.rank_sortable] }.each{ |e| @enrollments_hash[e.user_id] << e }
@students = @context.students_visible_to(@current_user).order_by_sortable_name.uniq
js_env :assignment_groups => assignment_groups_json
set_gradebook_warnings(@groups, @just_assignments)
if params[:view] == "simple"
@headers = false
render :action => "show_simple"
@ -425,7 +426,7 @@ class GradebooksController < ApplicationController
lambda{ |group| percentage[group.group_weight] }) :
lambda{ |group| nil }
groups = groups.map{ |group|
groups = groups.map { |group|
OpenObject.build('assignment',
:id => 'group-' + group.id.to_s,
:rules => group.rules,
@ -437,6 +438,7 @@ class GradebooksController < ApplicationController
:group_weight => group.group_weight,
:asset_string => "group_total_#{group.id}")
}
groups << OpenObject.build('assignment',
:id => 'final-grade',
:title => t('titles.total', 'Total'),
@ -448,6 +450,44 @@ class GradebooksController < ApplicationController
groups
end
def set_gradebook_warnings(groups, assignments)
@assignments_in_bad_groups = Set.new
if @context.group_weighting_scheme == "percent"
assignments_by_group = assignments.group_by(&:assignment_group_id)
bad_groups = groups.select do |group|
group_assignments = assignments_by_group[group.id] || []
points_in_group = group_assignments.map(&:points_possible).compact.sum
points_in_group.zero?
end
bad_group_ids = bad_groups.map(&:id)
bad_assignment_ids = assignments_by_group.
slice(*bad_group_ids).
values.
flatten
@assignments_in_bad_groups.replace bad_assignment_ids
warning = t('invalid_assignment_groups_warning',
{:one => "Score does not include %{groups} because " \
"it has no points possible",
:other => "Score does not include %{groups} because " \
"they have no points possible"},
:groups => bad_groups.map(&:name).to_sentence,
:count => bad_groups.size)
else
if assignments.all? { |a| (a.points_possible || 0).zero? }
warning = t(:no_assignments_have_points_warning,
"Can't compute score until an assignment " \
"has points possible")
end
end
js_env :total_grade_warning => warning if warning
end
private :set_gradebook_warnings
def submissions_by_assignment(submissions)
submissions.inject({}) do |hash, sub|
hash[sub.assignment_id] ||= []

View File

@ -6,6 +6,9 @@
<%= image_tag 'blank.png', :class => "assignment_dropdown" %>
</a>
<% else %>
<% if @assignments_in_bad_groups.include? assignment %>
<i class="icon-warning" title="<%= t(:zero_point_assignment, "Assignments in this group have no points possible and cannot be included in grade calculation") %>"></i>
<% end %>
<%= link_to(image_tag("sound_mute.png"), "#", :class => "mute_icon", :title => t(:teacher_muted_title, "Assignment is muted")) if assignment.muted? %>
<a href="<%= context_url(@context, :context_url) %>/assignments/<%= assignment.id %>" class="assignment_link assignment_title"><%= assignment.title %></a>
<a href="<%= context_url(@context, :context_url) %>/gradebook/speed_grader?assignment_id=<%= assignment.id %>" class="grade_assignment_link"></a>

View File

@ -72,8 +72,7 @@
<%= @renders[student.asset_string] ||= render(:partial => 'student', :object => student, :locals => { :course => @context }) %>
</div>
</td>
<% @assignments.each_with_index do |assignment, idx|
%>
<% @assignments.each_with_index do |assignment, idx| %>
<td class="student_assignment <%= assignment.special_class %>">
-
</td>

View File

@ -1164,6 +1164,16 @@ define([
}).find(".cancel_button").click(function() {
$curve_grade_dialog.dialog('close');
});
if (ENV.total_grade_warning) {
$('.assignment_final-grade').not('.assignment_header').each(function() {
$('<i/>', {
'class': 'icon-warning',
title: ENV.total_grade_warning
}).prependTo(this);
});
}
}, 1500);
$('#gradebook_options').live('click', function(event) {

View File

@ -1,30 +0,0 @@
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/gradebooks/_assignment" do
it "should render" do
course_with_student
view_context
render :partial => "gradebooks/assignment", :object => @course.assignments.create!(:title => "some assignment")
response.should_not be_nil
end
end

View File

@ -1,36 +0,0 @@
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/gradebooks/_assignments" do
it "should render" do
course_with_student
view_context
a = @course.assignments.create!(:title => "some assignment")
assigns[:assignments] = [a]
assigns[:students] = [@user]
assigns[:submissions] = []
assigns[:submissions_hash] = {}
render :partial => "gradebooks/assignments"
response.should_not be_nil
end
end