Fix classroom handling of sessions with no state yet

This commit is contained in:
Nick Winter 2015-12-04 11:59:51 -08:00
parent 4778cf5535
commit c36bed8103
3 changed files with 11 additions and 11 deletions

View file

@ -1,4 +1,4 @@
- var completed = session && session.get('state').complete;
- var completed = session && session.get('state') && session.get('state').complete;
h3 #{i}. #{level.name.replace('Course: ', '')}
if session
p

View file

@ -90,7 +90,7 @@ block content
- var session = sessionMap[levelID];
a(href=view.getLevelURL(level, course, courseInstance, session))
- var content = view.levelPopoverContent(level, session, i);
if session && session.get('state').complete
if session && session.get('state') && session.get('state').complete
.progress-bar.progress-bar-success(style=css, data-content=content, data-toggle='popover')= i
else if session
.progress-bar.progress-bar-warning(style=css, data-content=content, data-toggle='popover')= i

View file

@ -19,7 +19,7 @@ module.exports = class ClassroomView extends RootView
id: 'classroom-view'
template: template
teacherMode: false
events:
'click #edit-class-details-link': 'onClickEditClassDetailsLink'
'click #activate-licenses-btn': 'onClickActivateLicensesButton'
@ -57,7 +57,7 @@ module.exports = class ClassroomView extends RootView
@listenToOnce sessions, 'sync', (sessions) ->
@sessions.add(sessions.slice())
sessions.courseInstance.sessionsByUser = sessions.groupBy('creator')
# generate course instance JIT, in the meantime have models w/out equivalents in the db
for course in @courses.models
query = {courseID: course.id, classroomID: @classroom.id}
@ -83,7 +83,7 @@ module.exports = class ClassroomView extends RootView
campaign = @campaigns.get(campaignID)
courseInstance.sessions.campaign = campaign
super()
afterRender: ->
@$('[data-toggle="popover"]').popover({
html: true
@ -131,7 +131,7 @@ module.exports = class ClassroomView extends RootView
classStats: ->
stats = {}
playtime = 0
total = 0
for session in @sessions.models
@ -140,8 +140,8 @@ module.exports = class ClassroomView extends RootView
total += 1
stats.averagePlaytime = if playtime and total then moment.duration(playtime / total, "seconds").humanize() else 0
stats.totalPlaytime = if playtime then moment.duration(playtime, "seconds").humanize() else 0
completeSessions = @sessions.filter (s) -> s.get('state').complete
completeSessions = @sessions.filter (s) -> s.get('state')?.complete
stats.averageLevelsComplete = if @users.size() then (_.size(completeSessions) / @users.size()).toFixed(1) else 'N/A'
stats.totalLevelsComplete = _.size(completeSessions)
return stats
@ -158,7 +158,7 @@ module.exports = class ClassroomView extends RootView
onCourseInstanceCreated = =>
courseInstance.addMember(userID)
@listenToOnce courseInstance, 'sync', @render
if courseInstance.isNew()
# adding the first student to this course, so generate the course instance for it
courseInstance.save(null, {validate: false})
@ -175,7 +175,7 @@ module.exports = class ClassroomView extends RootView
})
@openModalView(modal)
modal.once 'remove-student', @onStudentRemoved, @
onStudentRemoved: (e) ->
@users.remove(e.user)
@render()
@ -193,4 +193,4 @@ module.exports = class ClassroomView extends RootView
getLevelURL: (level, course, courseInstance, session) ->
return null unless @teacherMode and _.all(arguments)
"/play/level/#{level.slug}?course=#{course.id}&course-instance=#{courseInstance.id}&session=#{session.id}&observing=true"
"/play/level/#{level.slug}?course=#{course.id}&course-instance=#{courseInstance.id}&session=#{session.id}&observing=true"