outcome results: persist tab selection to URL

fixes CNVS-10608

test plan:
  * open gradebook
  * select the learning mastery view
  * verify that you can switch views with your browser's
    back and forward buttons
  * refresh the page
  * verify that you are on the same view

Change-Id: Ia3657f7113cd9473ec9b3583d123eaf59c03d70f
Reviewed-on: https://gerrit.instructure.com/28845
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jon Willesen <jonw@instructure.com>
QA-Review: Steven Shepherd <sshepherd@instructure.com>
Product-Review: Braden Anderson <banderson@instructure.com>
This commit is contained in:
Braden Anderson 2014-01-17 15:33:19 -07:00
parent 94e536d80f
commit 68d504049e
6 changed files with 63 additions and 30 deletions

View File

@ -1,28 +1,46 @@
require [ require [
'jquery' 'jquery'
'Backbone'
'compiled/gradebook2/Gradebook' 'compiled/gradebook2/Gradebook'
'compiled/views/gradebook/NavigationPillView' 'compiled/views/gradebook/NavigationPillView'
'compiled/views/gradebook/OutcomeGradebookView' 'compiled/views/gradebook/OutcomeGradebookView'
], ($, Gradebook, NavigationPillView, OutcomeGradebookView) -> ], ($, Backbone, Gradebook, NavigationPillView, OutcomeGradebookView) ->
class GradebookRouter extends Backbone.Router
routes:
'': 'showGrades'
'outcomes': 'showOutcomes'
isLoaded = false initialize: ->
initGradebook = () -> new Gradebook(ENV.GRADEBOOK_OPTIONS) @isLoaded = false
initOutcomes = (gradebook) -> @views = {}
navigation = new NavigationPillView(el: $('.gradebook-navigation')) @views.gradebook = new Gradebook(ENV.GRADEBOOK_OPTIONS)
book = new OutcomeGradebookView( if ENV.GRADEBOOK_OPTIONS.outcome_gradebook_enabled
el: $('.outcome-gradebook-container'), @views['outcome-gradebook'] = @initOutcomes()
gradebook: gradebook)
book.render()
navigation.on 'pillchange', (viewName) -> initOutcomes: ->
book = new OutcomeGradebookView(
el: $('.outcome-gradebook-container'),
gradebook: @views.gradebook)
book.render()
@navigation = new NavigationPillView(el: $('.gradebook-navigation'))
@navigation.on 'pillchange', @handlePillChange
book
handlePillChange: (viewname) =>
route = if viewname == 'gradebook' then '' else 'outcomes'
@navigate(route, trigger: true)
showGrades: ->
@showView('gradebook')
showOutcomes: ->
@showView('outcome-gradebook')
showView: (viewName) ->
@navigation.setActiveView(viewName) if @navigation
$('.gradebook-container, .outcome-gradebook-container').addClass('hidden') $('.gradebook-container, .outcome-gradebook-container').addClass('hidden')
$(".#{viewName}-container").removeClass('hidden') $(".#{viewName}-container").removeClass('hidden')
loadOutcomes(book) if !isLoaded and viewName is 'outcome-gradebook' @views[viewName].onShow()
loadOutcomes = (book) -> @router = new GradebookRouter
isLoaded = true Backbone.history.start()
book.loadOutcomes()
$(document).ready ->
gradebook = initGradebook()
initOutcomes(gradebook) if ENV.GRADEBOOK_OPTIONS.outcome_gradebook_enabled

View File

@ -119,21 +119,24 @@ define [
gotAllStudents.resolve() gotAllStudents.resolve()
gotCustomColumns = @getCustomColumns() gotCustomColumns = @getCustomColumns()
$.when(gotCustomColumns, gotAllStudents).done @doSlickgridStuff @gotAllData = $.when(gotCustomColumns, gotAllStudents)
@allSubmissionsLoaded.done => @allSubmissionsLoaded.done =>
for c in @customColumns for c in @customColumns
url = @options.custom_column_data_url.replace /:id/, c.id url = @options.custom_column_data_url.replace /:id/, c.id
@getCustomColumnData(c.id) @getCustomColumnData(c.id)
@showCustomColumnDropdownOption()
onShow: ->
@spinner = new Spinner() @spinner = new Spinner()
$(@spinner.spin().el).css( $(@spinner.spin().el).css(
opacity: 0.5 opacity: 0.5
top: '55px' top: '55px'
left: '50%' left: '50%'
).addClass('use-css-transitions-for-show-hide').appendTo('#main') ).addClass('use-css-transitions-for-show-hide').appendTo('#main')
$('#gradebook-grid-wrapper').hide()
@showCustomColumnDropdownOption() @gotAllData.done @doSlickgridStuff
getCustomColumns: -> getCustomColumns: ->
# not going to support pagination because that would be crazy # not going to support pagination because that would be crazy
@ -664,7 +667,7 @@ define [
onGridInit: () -> onGridInit: () ->
tooltipTexts = {} tooltipTexts = {}
$(@spinner.el).remove() $(@spinner.el).remove()
$('#gradebook_wrapper').show() $('#gradebook-grid-wrapper').show()
@uid = @grid.getUID() @uid = @grid.getUID()
@$grid = grid = $('#gradebook_grid') @$grid = grid = $('#gradebook_grid')
.fillWindowWithMe({ .fillWindowWithMe({
@ -794,7 +797,7 @@ define [
updateCurrentSection: (section, author) => updateCurrentSection: (section, author) =>
@sectionToShow = section @sectionToShow = section
userSettings[if @sectionToShow then 'contextSet' else 'contextRemove']('grading_show_only_section', @sectionToShow) userSettings[if @sectionToShow then 'contextSet' else 'contextRemove']('grading_show_only_section', @sectionToShow)
@buildRows() @buildRows() if @grid
initHeader: => initHeader: =>
@drawSectionSelectButton() if @sections_enabled @drawSectionSelectButton() if @sections_enabled

View File

@ -14,3 +14,5 @@ define ['jquery', 'Backbone'], ($, {View}) ->
$(active).parent().addClass('active') $(active).parent().addClass('active')
@trigger('pillchange', $(active).data('id')) @trigger('pillchange', $(active).data('id'))
setActiveView: (viewName) ->
@setActiveTab(@$("[data-id=#{viewName}]"))

View File

@ -117,15 +117,15 @@ define [
# #
# Returns an object. # Returns an object.
toJSON: -> toJSON: ->
_.extend({}, @checkboxes, menu: @menu) _.extend({}, @checkboxes)
# Public: Render the view once all needed data is loaded. # Public: Render the view once all needed data is loaded.
# #
# Returns this. # Returns this.
render: -> render: ->
$.when(@gradebook.hasSections) $.when(@gradebook.hasSections)
.then(@_initMenu)
.then(=> super) .then(=> super)
.then(@_drawSectionMenu)
$.when(@hasOutcomes).then(@renderGrid) $.when(@hasOutcomes).then(@renderGrid)
this this
@ -149,10 +149,18 @@ define [
Grid.Events.init(@grid) Grid.Events.init(@grid)
@_attachEvents() @_attachEvents()
isLoaded: false
onShow: ->
@loadOutcomes() if !@isLoaded
@isLoaded = true
# Public: Load all outcome results from API. # Public: Load all outcome results from API.
# #
# Returns nothing. # Returns nothing.
loadOutcomes: () -> loadOutcomes: () ->
$.when(@gradebook.hasSections).then(@_loadOutcomes)
_loadOutcomes: =>
course = ENV.context_asset_string.split('_')[1] course = ENV.context_asset_string.split('_')[1]
@$('.outcome-gradebook-wrapper').disableWhileLoading(@hasOutcomes) @$('.outcome-gradebook-wrapper').disableWhileLoading(@hasOutcomes)
@_loadPage("/api/v1/courses/#{course}/outcome_rollups?per_page=100&include[]=outcomes&include[]=users") @_loadPage("/api/v1/courses/#{course}/outcome_rollups?per_page=100&include[]=outcomes&include[]=users")
@ -190,12 +198,13 @@ define [
# the menu needs to wait for relevant course sections to load. # the menu needs to wait for relevant course sections to load.
# #
# Returns nothing. # Returns nothing.
_initMenu: => _drawSectionMenu: =>
@menu = new SectionMenuView( @menu = new SectionMenuView(
sections: @gradebook.sectionList() sections: @gradebook.sectionList()
currentSection: @gradebook.sectionToShow currentSection: @gradebook.sectionToShow
className: 'outcome-gradebook-section-select' el: $('.section-button-placeholder'),
) )
@menu.render()
# Internal: Create an event listener function used to filter SlickGrid results. # Internal: Create an event listener function used to filter SlickGrid results.
# #

View File

@ -35,6 +35,7 @@ define [
attachEvents: -> attachEvents: ->
$.subscribe('currentSection/change', @onSectionChange) $.subscribe('currentSection/change', @onSectionChange)
@$('.section-select-menu').on('click', (e) -> e.preventDefault())
@$('.section-select-menu').on('menuselect', (event, ui) => @$('.section-select-menu').on('menuselect', (event, ui) =>
section = @$('[aria-checked=true] input[name=section_to_show_radio]').val() || undefined section = @$('[aria-checked=true] input[name=section_to_show_radio]').val() || undefined
$.publish('currentSection/change', [section, @cid]) $.publish('currentSection/change', [section, @cid])

View File

@ -10,7 +10,7 @@
js_bundle :gradebook2 js_bundle :gradebook2
%> %>
<div id="keyboard_navigation"></div> <div id="keyboard_navigation"></div>
<div id="gradebook_wrapper" class="use-css-transitions-for-show-hide" style="display:none;"> <div id="gradebook_wrapper">
<% if @context.feature_enabled?(:outcome_gradebook) %> <% if @context.feature_enabled?(:outcome_gradebook) %>
<div class="gradebook-header"> <div class="gradebook-header">
@ -31,7 +31,7 @@
</div> </div>
<% end %> <% end %>
<div class="gradebook-container"> <div class="gradebook-container hidden">
<div id="gradebook-toolbar" class="toolbar"> <div id="gradebook-toolbar" class="toolbar">
<% if !@context.feature_enabled?(:outcome_gradebook) %> <% if !@context.feature_enabled?(:outcome_gradebook) %>
<span class="section-button-placeholder"></span> <span class="section-button-placeholder"></span>
@ -64,7 +64,7 @@
<input type="text" class="search-query" placeholder="<%= placeholder %>" aria-label="<%= placeholder %>"> <input type="text" class="search-query" placeholder="<%= placeholder %>" aria-label="<%= placeholder %>">
</div> </div>
</div> </div>
<div id="gradebook-grid-wrapper"> <div id="gradebook-grid-wrapper" class="use-css-transitions-for-show-hide" style="display:none;">
<div id="gradebook_grid"></div> <div id="gradebook_grid"></div>
</div> </div>
<div style="display:none;"> <div style="display:none;">