mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Add explanatory copy to TeacherCoursesView
This commit is contained in:
parent
3fb85463fa
commit
6ac659b571
4 changed files with 44 additions and 6 deletions
23
app/collections/Prepaids.coffee
Normal file
23
app/collections/Prepaids.coffee
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
CocoCollection = require 'collections/CocoCollection'
|
||||||
|
Prepaid = require 'models/Prepaid'
|
||||||
|
|
||||||
|
sum = (numbers) -> _.reduce(numbers, (a, b) -> a + b)
|
||||||
|
|
||||||
|
module.exports = class Prepaids extends CocoCollection
|
||||||
|
model: Prepaid
|
||||||
|
|
||||||
|
url: "/db/prepaid"
|
||||||
|
|
||||||
|
totalMaxRedeemers: ->
|
||||||
|
sum((prepaid.get('maxRedeemers') for prepaid in @models)) or 0
|
||||||
|
|
||||||
|
totalRedeemers: ->
|
||||||
|
sum((_.size(prepaid.get('redeemers')) for prepaid in @models)) or 0
|
||||||
|
|
||||||
|
totalAvailable: -> Math.max(@totalMaxRedeemers() - @totalRedeemers(), 0)
|
||||||
|
|
||||||
|
fetchByCreator: (creatorID, opts) ->
|
||||||
|
opts ?= {}
|
||||||
|
opts.data ?= {}
|
||||||
|
opts.data.creator = creatorID
|
||||||
|
@fetch opts
|
|
@ -54,6 +54,17 @@ block content
|
||||||
|
|
||||||
br
|
br
|
||||||
.section-header Available Courses
|
.section-header Available Courses
|
||||||
|
|
||||||
|
p.text-center
|
||||||
|
strong.spr Unused enrollments available:
|
||||||
|
strong.spr= view.prepaids.totalAvailable()
|
||||||
|
a.btn.btn-success.btn(href="/courses/purchase") Purchase Enrollments
|
||||||
|
|
||||||
|
p
|
||||||
|
| All students get access to Introduction to Computer Science for free.
|
||||||
|
| One enrollment per student is required to assign them to paid CodeCombat courses.
|
||||||
|
| A single student does not need multiple enrollments to access all paid courses.
|
||||||
|
|
||||||
.container-fluid
|
.container-fluid
|
||||||
- var courses = view.courses.models;
|
- var courses = view.courses.models;
|
||||||
- var i = 0;
|
- var i = 0;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
ModalView = require 'views/core/ModalView'
|
ModalView = require 'views/core/ModalView'
|
||||||
template = require 'templates/courses/activate-licenses-modal'
|
template = require 'templates/courses/activate-licenses-modal'
|
||||||
CocoCollection = require 'collections/CocoCollection'
|
CocoCollection = require 'collections/CocoCollection'
|
||||||
Prepaid = require 'models/Prepaid'
|
Prepaids = require 'collections/Prepaids'
|
||||||
User = require 'models/User'
|
User = require 'models/User'
|
||||||
|
|
||||||
module.exports = class ActivateLicensesModal extends ModalView
|
module.exports = class ActivateLicensesModal extends ModalView
|
||||||
|
@ -16,12 +16,10 @@ module.exports = class ActivateLicensesModal extends ModalView
|
||||||
@classroom = options.classroom
|
@classroom = options.classroom
|
||||||
@users = options.users
|
@users = options.users
|
||||||
@user = options.user
|
@user = options.user
|
||||||
@prepaids = new CocoCollection([], { url: "/db/prepaid", model: Prepaid })
|
@prepaids = new Prepaids()
|
||||||
sum = (numbers) -> _.reduce(numbers, (a, b) -> a + b)
|
|
||||||
@prepaids.totalMaxRedeemers = -> sum((prepaid.get('maxRedeemers') for prepaid in @models)) or 0
|
|
||||||
@prepaids.totalRedeemers = -> sum((_.size(prepaid.get('redeemers')) for prepaid in @models)) or 0
|
|
||||||
@prepaids.comparator = '_id'
|
@prepaids.comparator = '_id'
|
||||||
@supermodel.loadCollection(@prepaids, 'prepaids', {data: {creator: me.id}})
|
@prepaids.fetchByCreator(me.id)
|
||||||
|
@supermodel.loadCollection(@prepaids, 'prepaids')
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
super()
|
super()
|
||||||
|
|
|
@ -10,6 +10,7 @@ CourseInstance = require 'models/CourseInstance'
|
||||||
RootView = require 'views/core/RootView'
|
RootView = require 'views/core/RootView'
|
||||||
template = require 'templates/courses/teacher-courses-view'
|
template = require 'templates/courses/teacher-courses-view'
|
||||||
ClassroomSettingsModal = require 'views/courses/ClassroomSettingsModal'
|
ClassroomSettingsModal = require 'views/courses/ClassroomSettingsModal'
|
||||||
|
Prepaids = require 'collections/Prepaids'
|
||||||
|
|
||||||
module.exports = class TeacherCoursesView extends RootView
|
module.exports = class TeacherCoursesView extends RootView
|
||||||
id: 'teacher-courses-view'
|
id: 'teacher-courses-view'
|
||||||
|
@ -32,6 +33,11 @@ module.exports = class TeacherCoursesView extends RootView
|
||||||
@courseInstances.comparator = 'courseID'
|
@courseInstances.comparator = 'courseID'
|
||||||
@courseInstances.sliceWithMembers = -> return @filter (courseInstance) -> _.size(courseInstance.get('members')) and courseInstance.get('classroomID')
|
@courseInstances.sliceWithMembers = -> return @filter (courseInstance) -> _.size(courseInstance.get('members')) and courseInstance.get('classroomID')
|
||||||
@supermodel.loadCollection(@courseInstances, 'course_instances', {data: {ownerID: me.id}})
|
@supermodel.loadCollection(@courseInstances, 'course_instances', {data: {ownerID: me.id}})
|
||||||
|
@prepaids = new Prepaids()
|
||||||
|
@prepaids.comparator = '_id'
|
||||||
|
if not me.isAnonymous()
|
||||||
|
@prepaids.fetchByCreator(me.id)
|
||||||
|
@supermodel.loadCollection(@prepaids, 'prepaids') # just registers
|
||||||
@members = new CocoCollection([], { model: User })
|
@members = new CocoCollection([], { model: User })
|
||||||
@listenTo @members, 'sync', @render
|
@listenTo @members, 'sync', @render
|
||||||
@
|
@
|
||||||
|
|
Loading…
Reference in a new issue