mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-28 01:55:38 -05:00
Fix course instance generation for classrooms
This commit is contained in:
parent
d51f42b2ec
commit
90ac6baa67
3 changed files with 52 additions and 6 deletions
|
@ -53,7 +53,7 @@ block content
|
|||
.progress
|
||||
.progress-bar(style='width:'+stats.levels.pctDone)
|
||||
else if paidFor
|
||||
button.enable-btn.btn.btn-info.btn-sm(data-user-id=user.id, data-course-instance-id=courseInstance.id) Enable
|
||||
button.enable-btn.btn.btn-info.btn-sm(data-user-id=user.id, data-course-instance-cid=courseInstance.cid) Enable
|
||||
|
||||
if !paidFor
|
||||
.text-center
|
||||
|
|
|
@ -50,10 +50,22 @@ module.exports = class ClassroomView extends RootView
|
|||
@supermodel.loadCollection(sessions, 'sessions')
|
||||
courseInstance.sessions = sessions
|
||||
sessions.courseInstance = courseInstance
|
||||
courseInstance.sessionsByUser = {}
|
||||
@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}
|
||||
courseInstance = @courseInstances.findWhere(query)
|
||||
if not courseInstance
|
||||
courseInstance = new CourseInstance(query)
|
||||
@courseInstances.add(courseInstance)
|
||||
courseInstance.sessions = new CocoCollection([], {model: LevelSession})
|
||||
sessions.courseInstance = courseInstance
|
||||
courseInstance.sessionsByUser = {}
|
||||
|
||||
onLoaded: ->
|
||||
userSessions = @sessions.groupBy('creator')
|
||||
for user in @users.models
|
||||
|
@ -105,11 +117,20 @@ module.exports = class ClassroomView extends RootView
|
|||
@openModalView(modal)
|
||||
|
||||
onClickEnableButton: (e) ->
|
||||
courseInstance = @courseInstances.get($(e.target).data('course-instance-id'))
|
||||
courseInstance = @courseInstances.get($(e.target).data('course-instance-cid'))
|
||||
userID = $(e.target).data('user-id')
|
||||
courseInstance.addMember(userID)
|
||||
$(e.target).attr('disabled', true)
|
||||
@listenToOnce courseInstance, 'sync', @render
|
||||
|
||||
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})
|
||||
courseInstance.once 'sync', onCourseInstanceCreated
|
||||
else
|
||||
onCourseInstanceCreated()
|
||||
|
||||
onClickRemoveStudentLink: (e) ->
|
||||
user = @users.get($(e.target).closest('a').data('user-id'))
|
||||
|
|
|
@ -60,7 +60,9 @@ module.exports = class TeacherCoursesView extends RootView
|
|||
# TODO: how to get new classroom from modal?
|
||||
@classrooms.add(modal.classroom)
|
||||
# TODO: will this definitely fire after modal saves new classroom?
|
||||
@listenToOnce modal.classroom, 'sync', @render
|
||||
@listenToOnce modal.classroom, 'sync', ->
|
||||
@addFreeCourseInstances()
|
||||
@render()
|
||||
|
||||
onClickEditClassroomSmall: (e) ->
|
||||
classroomID = $(e.target).data('classroom-id')
|
||||
|
@ -68,3 +70,26 @@ module.exports = class TeacherCoursesView extends RootView
|
|||
modal = new ClassroomSettingsModal({classroom: classroom})
|
||||
@openModalView(modal)
|
||||
@listenToOnce modal, 'hide', @render
|
||||
|
||||
onLoaded: ->
|
||||
super()
|
||||
@addFreeCourseInstances()
|
||||
|
||||
addFreeCourseInstances: ->
|
||||
# so that when students join the classroom, they can automatically get free courses
|
||||
# non-free courses are generated when the teacher first adds a student to them
|
||||
for classroom in @classrooms.models
|
||||
for course in @courses.models
|
||||
continue if not course.get('free')
|
||||
courseInstance = @courseInstances.findWhere({classroomID: classroom.id, courseID: course.id})
|
||||
if not courseInstance
|
||||
courseInstance = new CourseInstance({
|
||||
classroomID: classroom.id
|
||||
courseID: course.id
|
||||
})
|
||||
# TODO: figure out a better way to get around triggering validation errors for properties
|
||||
# that the server will end up filling in, like an empty members array, ownerID
|
||||
courseInstance.save(null, {validate: false})
|
||||
@courseInstances.add(courseInstance)
|
||||
@listenToOnce courseInstance, 'sync', @addFreeCourseInstances
|
||||
return
|
Loading…
Reference in a new issue