Skip to content

Commit

Permalink
load all result pages in outcome gradebook
Browse files Browse the repository at this point in the history
fixes CNVS-10631

test plan:
  * create a course with > 100 users;
  * navigate to that page's outcome gradebook and
    verify that all users are displayed.

Change-Id: Id38c8ff1bcdfb26adabfd68d8884074b70f83193
Reviewed-on: https://gerrit.instructure.com/28930
Tested-by: Jenkins <[email protected]>
Reviewed-by: Jon Willesen <[email protected]>
QA-Review: Steven Shepherd <[email protected]>
Product-Review: Zach Pendleton <[email protected]>
  • Loading branch information
zachpendleton committed Jan 21, 2014
1 parent af69289 commit f7b3711
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
6 changes: 1 addition & 5 deletions app/coffeescripts/bundles/gradebook2.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ require [

loadOutcomes = (book) ->
isLoaded = true
courseID = ENV.context_asset_string.split('_')[1]
url = "/api/v1/courses/#{courseID}/outcome_rollups?per_page=50"
dfd = $.getJSON(url)
$('.outcome-gradebook-wrapper').disableWhileLoading(dfd)
dfd.then((response) -> book.loadOutcomes(response))
book.loadOutcomes()

$(document).ready ->
gradebook = initGradebook()
Expand Down
48 changes: 42 additions & 6 deletions app/coffeescripts/views/gradebook/OutcomeGradebookView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ define [
view.on('togglestate', @_createFilter(name)) for name, view of @checkboxes
$.subscribe('currentSection/change', Grid.Events.sectionChangeFunction(@grid))

# Internal: Listen for events on grid.
#
# Returns nothing.
_attachGridEvents: ->
@grid.onHeaderRowCellRendered.subscribe(Grid.Events.headerRowCellRendered)
@grid.onHeaderCellRendered.subscribe(Grid.Events.headerCellRendered)
@grid.onSort.subscribe(Grid.Events.sort)

# Public: Create object to be passed to the view.
#
# Returns an object.
Expand Down Expand Up @@ -88,19 +96,47 @@ define [
rows,
columns,
Grid.options)
@grid.onHeaderRowCellRendered.subscribe(Grid.Events.headerRowCellRendered)
@grid.onHeaderCellRendered.subscribe(Grid.Events.headerCellRendered)
@_attachGridEvents()
@grid.init()
Grid.Events.init(@grid)
@_attachEvents()

# Public: Pass outcomes from outcome rollup API to the view.
# Public: Load all outcome results from API.
#
# Returns nothing.
loadOutcomes: () ->
course = ENV.context_asset_string.split('_')[1]
@$('.outcome-gradebook-wrapper').disableWhileLoading(@hasOutcomes)
@_loadPage("/api/v1/courses/#{course}/outcome_rollups?per_page=100")

# Internal: Load a page of outcome results from the given URL.
#
# url - The URL to load results from.
# outcomes - An existing response from the API.
#
# Returns nothing.
_loadPage: (url, outcomes) ->
dfd = $.getJSON(url)
dfd.then (response, status, xhr) =>
outcomes = @_mergeResponses(outcomes, response)
if response.meta.pagination.next
@_loadPage(response.meta.pagination.next, outcomes)
else
@hasOutcomes.resolve(outcomes)

# Internal: Merge two API responses into one.
#
# outcomeResponse - The JSON response from Canvas.
# a - The first API response received.
# b - The second API response received.
#
# Returns nothing.
loadOutcomes: (outcomeResponse) ->
@hasOutcomes.resolve(outcomeResponse)
_mergeResponses: (a, b) ->
return b unless a
response = {}
response.meta = _.extend({}, a.meta, b.meta)
response.linked = { outcomes: a.linked.outcomes, users: a.linked.users.concat(b.linked.users) }
response.rollups = a.rollups.concat(b.rollups)
response

# Internal: Initialize the child SectionMenuView. This happens here because
# the menu needs to wait for relevant course sections to load.
Expand Down
1 change: 1 addition & 0 deletions app/controllers/outcome_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def require_users
@users = @section.students
end
@users ||= users_for_outcome_context
@users = @users.order(:id)
end

# Internal: Gets a list of users that should have results returned based on
Expand Down

0 comments on commit f7b3711

Please sign in to comment.