overdue assignments in student date view

fixes CNVS-8261

test plan
 - as a teacher create assignments due in the past
 - as a student go to the assignments index page
 - make sure there is a section for overdue assignments

Change-Id: Id839a8b8c5e6fc070a2c94283d919ee33454a39b
Reviewed-on: https://gerrit.instructure.com/25141
Reviewed-by: Simon Williams <simon@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Caleb Guanzon <cguanzon@instructure.com>
Product-Review: Cameron Sutter <csutter@instructure.com>
This commit is contained in:
Cameron Sutter 2013-10-08 23:07:00 -06:00
parent ebe876954c
commit 11981501c2
6 changed files with 184 additions and 12 deletions

View File

@ -68,3 +68,5 @@ define [
# manually trigger a change so the UI can update appropriately.
assignment.set 'submission', null
assignment.trigger 'change:submission'
@trigger 'change:submissions'

View File

@ -102,6 +102,25 @@ define [
else if _.include submissionTypes, 'external_tool' then 'external_tool'
else 'online'
expectsSubmission: =>
submissionTypes = @_submissionTypes()
submissionTypes.length > 0 && !_.include(submissionTypes, "") && !_.include(submissionTypes, 'none') && !_.include(submissionTypes, 'not_graded') && !_.include(submissionTypes, 'on_paper') && !_.include(submissionTypes, 'external_tool')
allowedToSubmit: =>
submissionTypes = @_submissionTypes()
@expectsSubmission() && !@get('locked_for_user') && !_.include(submissionTypes, 'online_quiz') && !_.include(submissionTypes, 'attendance')
isGraded: =>
submission = @get('submission') || new Backbone.Model {}
!submission.get('notYetGraded')?
hasSubmission: =>
submission = @get('submission') || new Backbone.Model {}
!!submission.get('submission_type')
withoutGradedSubmission: =>
!@get('submission')? || (!@hasSubmission() && !@isGraded())
acceptsOnlineUpload: =>
!! _.include @_submissionTypes(), 'online_upload'

View File

@ -26,7 +26,7 @@ define [
@initializeCache()
@course.on 'change', @initializeCache
@course.on 'change', @render
@assignmentGroups.once 'reset', @initializeDateGroups
@assignmentGroups.once 'change:submissions', @initializeDateGroups
@.on 'changed:showBy', @setAssignmentGroups
@.on 'changed:showBy', @render
@ -41,15 +41,23 @@ define [
assignments = _.flatten(@assignmentGroups.map (ag) -> ag.get('assignments').models)
dated = _.select assignments, (a) -> a.dueAt()?
undated = _.difference assignments, dated
past = _.chain(dated)
.select((a) -> (new Date()) > Date.parse(a.dueAt()))
.sortBy((a) -> (new Date()) - Date.parse(a.dueAt()))
.value()
upcoming = _.chain(dated)
.difference(past)
.sortBy((a) -> Date.parse(a.dueAt()))
.value()
past = []
overdue = []
upcoming = []
_.each(dated, (a) ->
if new Date() > Date.parse(a.dueAt())
if a.expectsSubmission() && a.allowedToSubmit() && a.withoutGradedSubmission()
overdue.push a
else
past.push a
else
upcoming.push a
)
past = _.sortBy(past, (a) -> (new Date()) - Date.parse(a.dueAt()))
upcoming = _.sortBy(upcoming, (a) -> Date.parse(a.dueAt()))
overdue = _.sortBy(overdue, (a) -> Date.parse(a.dueAt()))
@groupedByAG = @assignmentGroups.models
@groupedByDate = [

View File

@ -227,6 +227,83 @@ define [
assignment.set 'submission_types', [ 'online_upload' ]
deepEqual assignment.submissionType(), 'online'
module "Assignment#expectsSubmission"
test "returns false if assignment submission type is not online", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission_types': [ 'external_tool', 'on_paper' ]
deepEqual assignment.expectsSubmission(), false
test "returns true if an assignment submission type is online", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission_types': [ 'online' ]
deepEqual assignment.expectsSubmission(), true
module "Assignment#allowedToSubmit"
test "returns false if assignment is locked", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission_types': [ 'online' ]
assignment.set 'locked_for_user': true
deepEqual assignment.allowedToSubmit(), false
test "returns true if an assignment is not locked", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission_types': [ 'online' ]
assignment.set 'locked_for_user': false
deepEqual assignment.allowedToSubmit(), true
test "returns false if a submission is not expected", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission_types': [ 'external_tool', 'on_paper', 'attendance' ]
deepEqual assignment.allowedToSubmit(), false
module "Assignment#isGraded"
test "returns true if notYetGraded is null", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': new Backbone.Model {'notYetGraded': null}
deepEqual assignment.isGraded(), true
test "returns false if notYetGraded is true", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': new Backbone.Model {'notYetGraded': true}
deepEqual assignment.isGraded(), false
module "Assignment#hasSubmission"
test "returns false if submission is null", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': null
deepEqual assignment.hasSubmission(), false
test "returns true if submission has a submission type", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': new Backbone.Model {'submission_type': 'online'}
deepEqual assignment.hasSubmission(), true
module "Assignment#withoutGradedSubmission"
test "returns false if there is a submission", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': new Backbone.Model {'submission_type': 'online'}
deepEqual assignment.withoutGradedSubmission(), false
test "returns true if there is no submission", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': null
deepEqual assignment.withoutGradedSubmission(), true
test "returns true if there is a submission, but no grade", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': new Backbone.Model {'notYetGraded': true}
deepEqual assignment.withoutGradedSubmission(), true
test "returns false if there is a submission and a grade", ->
assignment = new Assignment name: 'foo'
assignment.set 'submission': new Backbone.Model {'grade': 305}
deepEqual assignment.withoutGradedSubmission(), false
module "Assignment#acceptsOnlineUpload"
test "returns true if record submission types includes online_upload", ->
@ -238,7 +315,7 @@ define [
assignment = new Assignment name: 'foo'
assignment.set 'submission_types', []
deepEqual assignment.acceptsOnlineUpload(), false
module "Assignment#acceptsOnlineURL"
test "returns true if assignment allows online url", ->

View File

@ -1,14 +1,13 @@
define [
'Backbone'
'compiled/models/AssignmentGroup'
'compiled/models/Assignment'
'compiled/models/Course'
'compiled/collections/AssignmentGroupCollection'
'compiled/views/assignments/AssignmentGroupListView'
'compiled/views/assignments/IndexView'
'jquery'
'helpers/jquery.simulate'
], (Backbone, AssignmentGroup, Assignment, Course, AssignmentGroupCollection, AssignmentGroupListView, IndexView, $) ->
], (Backbone, AssignmentGroup, Course, AssignmentGroupCollection, AssignmentGroupListView, IndexView, $) ->
fixtures = $('#fixtures')

View File

@ -0,0 +1,67 @@
define [
'underscore'
'Backbone'
'compiled/models/AssignmentGroup'
'compiled/models/Assignment'
'compiled/models/Course'
'compiled/collections/AssignmentGroupCollection'
'compiled/views/assignments/AssignmentGroupListView'
'compiled/views/assignments/IndexView'
'compiled/views/assignments/ToggleShowByView'
'jquery'
], (_, Backbone, AssignmentGroup, Assignment, Course, AssignmentGroupCollection, AssignmentGroupListView, IndexView, ToggleShowByView, $) ->
COURSE_SUBMISSIONS_URL = "/courses/1/submissions"
module 'ToggleShowByView',
setup: ->
window.ENV =
PERMISSIONS:
manage: false
@course = new Course {id: 1}
@server = sinon.fakeServer.create()
@pastDate = new Date("2013-08-20 11:13:00")
today = new Date()
@futureDate = new Date()
@futureDate.setDate(today.getDate() + 3)
@assignments = [
{id: 1, name: 'Past Assignments', due_at: @pastDate, submission_types: ['online']},
{id: 2, name: 'Past Assignments', due_at: @pastDate, submission_types: ['on_paper']},
{id: 3, name: 'Upcoming Assignments', due_at: @futureDate},
{id: 4, name: 'Past Assignments', due_at: @pastDate, submission_types: ['online']},
{id: 5, name: 'Overdue Assignments', due_at: @pastDate, submission_types: ['online']},
{id: 6, name: 'Undated Assignments'}
]
@group = new AssignmentGroup assignments: @assignments
@collection = new AssignmentGroupCollection [@group],
courseSubmissionsURL: COURSE_SUBMISSIONS_URL,
course: @course
@showByView = new ToggleShowByView
course: @course
assignmentGroups: @collection
teardown: ->
@server.restore()
test 'should sort assignments correctly', ->
submissions = [
{id: 1, assignment_id: 1, grade: 305},
{id: 2, assignment_id: 4}
]
@server.respondWith "GET", "#{COURSE_SUBMISSIONS_URL}?per_page=50", [
200,
{ "Content-Type": "application/json" },
JSON.stringify(submissions),
]
@collection.getGrades()
@server.respond()
equal @collection.length, 4
@collection.each (group) ->
assignments = group.get('assignments').models
_.each assignments, (as) ->
equal group.name(), as.name()