mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Fix TeacherClassView sometimes not loading
This was a race condition where the view would trigger a render before courses loaded, and the template required them when it had some of its other resources.
This commit is contained in:
parent
33b614911c
commit
891d0fe12f
3 changed files with 32 additions and 9 deletions
|
@ -368,6 +368,7 @@ mixin copyCodes
|
||||||
|
|
||||||
mixin bulkAssignControls
|
mixin bulkAssignControls
|
||||||
.bulk-assign-controls.form-inline
|
.bulk-assign-controls.form-inline
|
||||||
|
- console.log('state errors', state.get('errors'))
|
||||||
.no-students-selected.small-details(class=state.get('errors').assigningToNobody ? 'visible' : '')
|
.no-students-selected.small-details(class=state.get('errors').assigningToNobody ? 'visible' : '')
|
||||||
span(data-i18n='teacher.no_students_selected')
|
span(data-i18n='teacher.no_students_selected')
|
||||||
.cant-assign-to-unenrolled.small-details(class=state.get('errors').assigningToUnenrolled ? 'visible' : '')
|
.cant-assign-to-unenrolled.small-details(class=state.get('errors').assigningToUnenrolled ? 'visible' : '')
|
||||||
|
@ -378,6 +379,7 @@ mixin bulkAssignControls
|
||||||
select.bulk-course-select.form-control
|
select.bulk-course-select.form-control
|
||||||
each trimCourse in _.rest(view.classroom.get('courses'))
|
each trimCourse in _.rest(view.classroom.get('courses'))
|
||||||
- var course = view.courses.get(trimCourse._id)
|
- var course = view.courses.get(trimCourse._id)
|
||||||
|
- console.log('???', course)
|
||||||
option(value=course.id selected=(course===state.get('selectedCourse')))
|
option(value=course.id selected=(course===state.get('selectedCourse')))
|
||||||
= course.get('name')
|
= course.get('name')
|
||||||
button.btn.btn-primary-alt.assign-to-selected-students
|
button.btn.btn-primary-alt.assign-to-selected-students
|
||||||
|
|
|
@ -71,6 +71,10 @@ module.exports = class TeacherClassView extends RootView
|
||||||
@singleStudentLevelProgressDotTemplate = require 'templates/teachers/hovers/progress-dot-single-student-level'
|
@singleStudentLevelProgressDotTemplate = require 'templates/teachers/hovers/progress-dot-single-student-level'
|
||||||
@allStudentsLevelProgressDotTemplate = require 'templates/teachers/hovers/progress-dot-all-students-single-level'
|
@allStudentsLevelProgressDotTemplate = require 'templates/teachers/hovers/progress-dot-all-students-single-level'
|
||||||
|
|
||||||
|
@debouncedRender = _.debounce ->
|
||||||
|
console.log 'we debounced', @
|
||||||
|
@render()
|
||||||
|
|
||||||
@state = new State(@getInitialState())
|
@state = new State(@getInitialState())
|
||||||
@updateHash @state.get('activeTab') # TODO: Don't push to URL history (maybe don't use url fragment for default tab)
|
@updateHash @state.get('activeTab') # TODO: Don't push to URL history (maybe don't use url fragment for default tab)
|
||||||
|
|
||||||
|
@ -121,10 +125,13 @@ module.exports = class TeacherClassView extends RootView
|
||||||
|
|
||||||
attachMediatorEvents: () ->
|
attachMediatorEvents: () ->
|
||||||
@listenTo @state, 'sync change', ->
|
@listenTo @state, 'sync change', ->
|
||||||
|
console.log '...'
|
||||||
if _.isEmpty(_.omit(@state.changed, 'searchTerm'))
|
if _.isEmpty(_.omit(@state.changed, 'searchTerm'))
|
||||||
@renderSelectors('#enrollment-status-table')
|
console.log 'render selectors...'
|
||||||
|
# @renderSelectors('#enrollment-status-table')
|
||||||
else
|
else
|
||||||
@render()
|
console.log 'render...'
|
||||||
|
# @render()
|
||||||
# Model/Collection events
|
# Model/Collection events
|
||||||
@listenTo @classroom, 'sync change update', ->
|
@listenTo @classroom, 'sync change update', ->
|
||||||
classCode = @classroom.get('codeCamel') or @classroom.get('code')
|
classCode = @classroom.get('codeCamel') or @classroom.get('code')
|
||||||
|
@ -137,7 +144,6 @@ module.exports = class TeacherClassView extends RootView
|
||||||
@state.set selectedCourse: @courses.first() unless @state.get('selectedCourse')
|
@state.set selectedCourse: @courses.first() unless @state.get('selectedCourse')
|
||||||
@listenTo @courseInstances, 'sync change update', ->
|
@listenTo @courseInstances, 'sync change update', ->
|
||||||
@setCourseMembers()
|
@setCourseMembers()
|
||||||
@render() # TODO: use state
|
|
||||||
@listenTo @courseInstances, 'add-members', ->
|
@listenTo @courseInstances, 'add-members', ->
|
||||||
noty text: $.i18n.t('teacher.assigned'), layout: 'center', type: 'information', killer: true, timeout: 5000
|
noty text: $.i18n.t('teacher.assigned'), layout: 'center', type: 'information', killer: true, timeout: 5000
|
||||||
@listenTo @students, 'sync change update add remove reset', ->
|
@listenTo @students, 'sync change update add remove reset', ->
|
||||||
|
@ -149,7 +155,6 @@ module.exports = class TeacherClassView extends RootView
|
||||||
@state.set students: @students
|
@state.set students: @students
|
||||||
@listenTo @students, 'sort', ->
|
@listenTo @students, 'sort', ->
|
||||||
@state.set students: @students
|
@state.set students: @students
|
||||||
@render()
|
|
||||||
@listenTo @, 'course-select:change', ({ selectedCourse }) ->
|
@listenTo @, 'course-select:change', ({ selectedCourse }) ->
|
||||||
@state.set selectedCourse: selectedCourse
|
@state.set selectedCourse: selectedCourse
|
||||||
|
|
||||||
|
@ -162,6 +167,17 @@ module.exports = class TeacherClassView extends RootView
|
||||||
onLoaded: ->
|
onLoaded: ->
|
||||||
@removeDeletedStudents() # TODO: Move this to mediator listeners? For both classroom and students?
|
@removeDeletedStudents() # TODO: Move this to mediator listeners? For both classroom and students?
|
||||||
@calculateProgressAndLevels()
|
@calculateProgressAndLevels()
|
||||||
|
|
||||||
|
# render callback setup
|
||||||
|
@listenTo @courseInstances, 'sync change update', @debouncedRender
|
||||||
|
console.log 'attaching'
|
||||||
|
@listenTo @state, 'sync change', ->
|
||||||
|
console.log 'we good'
|
||||||
|
if _.isEmpty(_.omit(@state.changed, 'searchTerm'))
|
||||||
|
@renderSelectors('#enrollment-status-table')
|
||||||
|
else
|
||||||
|
@debouncedRender()
|
||||||
|
@listenTo @students, 'sort', @debouncedRender
|
||||||
super()
|
super()
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
|
|
|
@ -75,24 +75,29 @@ describe 'TeacherClassView', ->
|
||||||
# it "shows the classroom's join code"
|
# it "shows the classroom's join code"
|
||||||
|
|
||||||
describe 'the Students tab', ->
|
describe 'the Students tab', ->
|
||||||
beforeEach ->
|
beforeEach (done) ->
|
||||||
@view.state.set('activeTab', '#students-tab')
|
@view.state.set('activeTab', '#students-tab')
|
||||||
|
_.defer(done)
|
||||||
|
|
||||||
# it 'shows all of the students'
|
# it 'shows all of the students'
|
||||||
# it 'sorts correctly by Name'
|
# it 'sorts correctly by Name'
|
||||||
# it 'sorts correctly by Progress'
|
# it 'sorts correctly by Progress'
|
||||||
|
|
||||||
describe 'bulk-assign controls', ->
|
describe 'bulk-assign controls', ->
|
||||||
it 'shows alert when assigning course 2 to unenrolled students', ->
|
it 'shows alert when assigning course 2 to unenrolled students', (done) ->
|
||||||
expect(@view.$('.cant-assign-to-unenrolled').hasClass('visible')).toBe(false)
|
expect(@view.$('.cant-assign-to-unenrolled').hasClass('visible')).toBe(false)
|
||||||
@view.$('.student-row .checkbox-flat').click()
|
@view.$('.student-row .checkbox-flat').click()
|
||||||
@view.$('.assign-to-selected-students').click()
|
@view.$('.assign-to-selected-students').click()
|
||||||
expect(@view.$('.cant-assign-to-unenrolled').hasClass('visible')).toBe(true)
|
_.defer =>
|
||||||
|
expect(@view.$('.cant-assign-to-unenrolled').hasClass('visible')).toBe(true)
|
||||||
|
done()
|
||||||
|
|
||||||
it 'shows alert when assigning but no students are selected', ->
|
it 'shows alert when assigning but no students are selected', (done) ->
|
||||||
expect(@view.$('.no-students-selected').hasClass('visible')).toBe(false)
|
expect(@view.$('.no-students-selected').hasClass('visible')).toBe(false)
|
||||||
@view.$('.assign-to-selected-students').click()
|
@view.$('.assign-to-selected-students').click()
|
||||||
expect(@view.$('.no-students-selected').hasClass('visible')).toBe(true)
|
_.defer =>
|
||||||
|
expect(@view.$('.no-students-selected').hasClass('visible')).toBe(true)
|
||||||
|
done()
|
||||||
|
|
||||||
# describe 'the Course Progress tab', ->
|
# describe 'the Course Progress tab', ->
|
||||||
# it 'shows the correct Course Overview progress'
|
# it 'shows the correct Course Overview progress'
|
||||||
|
|
Loading…
Reference in a new issue