mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-25 06:52:21 -05:00
8223122a6b
This updates TeacherClassView and ActivateLicensesModal to use the new state-based rendering system, making it much snappier and less clunky feeling, and improving data consistency. Features also included in this: - Hover details for progress dots in TeacherClassView - ActivateLicensesModal has an "All Students" option and better handling when you switch classrooms in the dropdown - Unenrolled/Unassigned students are shown separately in Course Progress and can be enrolled/assigned from there. Add Back to Classes button on demo-request submitted view Delete temporary patch file Show unenrolled students separately in Course Progress (incomplete) Migrate TeacherClassView to use orchestrator-style events, add unassigned students section, replace bootstrap tabs with state-based tabs Convert missed instance variables to be in @state Fix merge errors (in progress) Convert a bunch of stuff to use state and events (removing student needs fixing) Fix up modal interactions, some bugs Switch state to be a Model, sync up course dropdowns Convert student sorting to use state model Add hover tooltips to TeacherClassView Students tab Don't keep tooltip open when you mouse into it Add dateFirstCompleted and Course Progress tooltips Course Overview progress tooltips Refactor ActivateLicensesModal Refactors: Uses state object for view state Passes back the updated users in 'redeem-users' event instead of modifying given collection Features: Add 'All Students' dropdown option Don't forget checked students if you change classroom from dropdown, but only enroll the ones visible when you click "Enroll (n) Students" Separate enrolled students; improve style Rearrange error text Disable enroll-students button when none are selected Remove console.logs Move style-flat variables to another file This prevents .style-flat from being copied in multiple times to the resulting CSS. Show Unarchive button when on the page for an archived class Move text to en.coffee Only sort students on first classroom sync Fix merge error Handle sessions missing completion date in view logic instead of migration script Listen to classroom sync more than once in case it gets unarchived
122 lines
4.5 KiB
CoffeeScript
122 lines
4.5 KiB
CoffeeScript
RootView = require 'views/core/RootView'
|
|
template = require 'templates/courses/teacher-classes-view'
|
|
Classroom = require 'models/Classroom'
|
|
Classrooms = require 'collections/Classrooms'
|
|
Courses = require 'collections/Courses'
|
|
Campaign = require 'models/Campaign'
|
|
Campaigns = require 'collections/Campaigns'
|
|
LevelSessions = require 'collections/LevelSessions'
|
|
CourseInstance = require 'models/CourseInstance'
|
|
CourseInstances = require 'collections/CourseInstances'
|
|
ClassroomSettingsModal = require 'views/courses/ClassroomSettingsModal'
|
|
InviteToClassroomModal = require 'views/courses/InviteToClassroomModal'
|
|
User = require 'models/User'
|
|
utils = require 'core/utils'
|
|
helper = require 'lib/coursesHelper'
|
|
|
|
module.exports = class TeacherClassesView extends RootView
|
|
id: 'teacher-classes-view'
|
|
template: template
|
|
|
|
events:
|
|
'click .edit-classroom': 'onClickEditClassroom'
|
|
'click .archive-classroom': 'onClickArchiveClassroom'
|
|
'click .unarchive-classroom': 'onClickUnarchiveClassroom'
|
|
'click .add-students-btn': 'onClickAddStudentsButton'
|
|
'click .create-classroom-btn': 'onClickCreateClassroomButton'
|
|
|
|
initialize: (options) ->
|
|
super(options)
|
|
@classrooms = new Classrooms()
|
|
@classrooms.fetchMine()
|
|
@supermodel.trackCollection(@classrooms)
|
|
@listenTo @classrooms, 'sync', ->
|
|
for classroom in @classrooms.models
|
|
classroom.sessions = new LevelSessions()
|
|
jqxhrs = classroom.sessions.fetchForAllClassroomMembers(classroom)
|
|
if jqxhrs.length > 0
|
|
@supermodel.trackCollection(classroom.sessions)
|
|
|
|
@courses = new Courses()
|
|
@courses.fetch()
|
|
@supermodel.trackCollection(@courses)
|
|
|
|
@courseInstances = new CourseInstances()
|
|
@courseInstances.fetchByOwner(me.id)
|
|
@supermodel.trackCollection(@courseInstances)
|
|
@progressDotTemplate = require 'templates/teachers/hovers/progress-dot-whole-course'
|
|
|
|
# Level Sessions loaded after onLoaded to prevent race condition in calculateDots
|
|
|
|
afterRender: ->
|
|
super()
|
|
$('.progress-dot').each (i, el) ->
|
|
dot = $(el)
|
|
dot.tooltip({
|
|
html: true
|
|
container: dot
|
|
})
|
|
|
|
onLoaded: ->
|
|
helper.calculateDots(@classrooms, @courses, @courseInstances)
|
|
super()
|
|
|
|
onClickEditClassroom: (e) ->
|
|
classroomID = $(e.target).data('classroom-id')
|
|
classroom = @classrooms.get(classroomID)
|
|
modal = new ClassroomSettingsModal({ classroom: classroom })
|
|
@openModalView(modal)
|
|
@listenToOnce modal, 'hide', @render
|
|
|
|
onClickCreateClassroomButton: (e) ->
|
|
classroom = new Classroom({ ownerID: me.id })
|
|
modal = new ClassroomSettingsModal({ classroom: classroom })
|
|
@openModalView(modal)
|
|
@listenToOnce modal.classroom, 'sync', ->
|
|
@classrooms.add(modal.classroom)
|
|
@addFreeCourseInstances()
|
|
@render()
|
|
|
|
onClickAddStudentsButton: (e) ->
|
|
classroomID = $(e.currentTarget).data('classroom-id')
|
|
classroom = @classrooms.get(classroomID)
|
|
modal = new InviteToClassroomModal({ classroom: classroom })
|
|
@openModalView(modal)
|
|
@listenToOnce modal, 'hide', @render
|
|
|
|
onClickArchiveClassroom: (e) ->
|
|
classroomID = $(e.currentTarget).data('classroom-id')
|
|
classroom = @classrooms.get(classroomID)
|
|
classroom.set('archived', true)
|
|
classroom.save {}, {
|
|
success: =>
|
|
@render()
|
|
}
|
|
|
|
onClickUnarchiveClassroom: (e) ->
|
|
classroomID = $(e.currentTarget).data('classroom-id')
|
|
classroom = @classrooms.get(classroomID)
|
|
classroom.set('archived', false)
|
|
classroom.save {}, {
|
|
success: =>
|
|
@render()
|
|
}
|
|
|
|
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
|