MCPcopy Create free account
hub / github.com/codecombat/codecombat / assignCourse

Method assignCourse

app/views/courses/TeacherClassView.js:760–887  ·  view source on GitHub ↗
(courseID, members)

Source from the content-addressed store, hash-verified

758 }
759
760 assignCourse (courseID, members) {
761 if (!this.classroom.hasWritePermission({ showNoty: true })) { return } // May be viewing page as admin
762 let courseInstance = null
763 let numberEnrolled = 0
764 let remainingSpots = 0
765
766 return Promise.resolve()
767 // Find or make the necessary course instances
768 .then(() => {
769 courseInstance = this.courseInstances.findWhere({ courseID, classroomID: this.classroom.id })
770 if (!courseInstance) {
771 courseInstance = new CourseInstance({
772 courseID,
773 classroomID: this.classroom.id,
774 ownerID: this.classroom.get('ownerID'),
775 aceConfig: {},
776 })
777 courseInstance.notyErrors = false // handling manually
778 this.courseInstances.add(courseInstance)
779 return courseInstance.save()
780 }
781 }).then(() => {
782 // Find the prepaids and users we're acting on (for both starter and full license cases)
783 let prepaid
784 const availablePrepaids = this.prepaids.filter(prepaid => (prepaid.status() === 'available') && prepaid.includesCourse(courseID))
785 const unenrolledStudents = _(members)
786 .map(userID => this.students.get(userID))
787 .filter(user => !user.isEnrolled() || !user.prepaidIncludesCourse(courseID))
788 .value()
789 const totalSpotsAvailable = _.reduce(((() => {
790 const result = []
791 for (prepaid of Array.from(availablePrepaids)) {
792 result.push(prepaid.openSpots())
793 }
794 return result
795 })()), (val, total) => val + total) || 0
796
797 const canAssignCourses = totalSpotsAvailable >= _.size(unenrolledStudents)
798 if (!canAssignCourses) {
799 // These ones just matter for display
800 const availableFullLicenses = this.prepaids.filter(prepaid => (prepaid.status() === 'available') && (prepaid.get('type') === 'course') && !prepaid.get('includedCourseIDs'))
801 const numStudentsWithoutFullLicenses = _(members)
802 .map(userID => this.students.get(userID))
803 .filter(user => (user.prepaidType('includedCourseIDs') !== 'course') || !user.isEnrolled())
804 .size()
805 const numFullLicensesAvailable = _.reduce(((() => {
806 const result1 = []
807 for (prepaid of Array.from(availableFullLicenses)) {
808 result1.push(prepaid.openSpots())
809 }
810 return result1
811 })()), (val, total) => val + total) || 0
812 const modal = new CoursesNotAssignedModal({
813 selected: members.length,
814 numStudentsWithoutFullLicenses,
815 numFullLicensesAvailable,
816 courseID
817 })

Callers 3

onClickBulkAssignMethod · 0.95

Calls 15

fetchStudentsMethod · 0.95
hasWritePermissionMethod · 0.80
filterMethod · 0.80
statusMethod · 0.80
includesCourseMethod · 0.80
isEnrolledMethod · 0.80
prepaidIncludesCourseMethod · 0.80
openSpotsMethod · 0.80
prepaidTypeMethod · 0.80
isOwnerMethod · 0.80
redeemMethod · 0.80
fetchByCreatorMethod · 0.80

Tested by

no test coverage detected