Calculate the last time any of a teacher's students played

This commit is contained in:
Phoenix Eliot 2016-08-17 15:41:26 -07:00
parent 01affc2054
commit 6b6bd2f76d

View file

@ -5,6 +5,8 @@ Prepaid = require 'models/Prepaid'
StripeCoupons = require 'collections/StripeCoupons' StripeCoupons = require 'collections/StripeCoupons'
forms = require 'core/forms' forms = require 'core/forms'
Prepaids = require 'collections/Prepaids' Prepaids = require 'collections/Prepaids'
LevelSessions = require 'collections/LevelSessions'
Classrooms = require 'collections/Classrooms'
module.exports = class AdministerUserModal extends ModalView module.exports = class AdministerUserModal extends ModalView
id: 'administer-user-modal' id: 'administer-user-modal'
@ -23,8 +25,23 @@ module.exports = class AdministerUserModal extends ModalView
@supermodel.trackRequest @coupons.fetch({cache: false}) @supermodel.trackRequest @coupons.fetch({cache: false})
@prepaids = new Prepaids() @prepaids = new Prepaids()
@supermodel.trackRequest @prepaids.fetchByCreator(@userHandle) @supermodel.trackRequest @prepaids.fetchByCreator(@userHandle)
@classrooms = new Classrooms()
@supermodel.trackRequest(@classrooms.fetch({data:{ownerID: @user.id}})).then =>
@classrooms.each (classroom) =>
classroom.levelSessions = new LevelSessions()
@supermodel.trackRequests classroom.levelSessions.fetchForAllClassroomMembers(classroom)
onLoaded: -> onLoaded: ->
@allLevelSessions = new LevelSessions(_.reduce((@classrooms.map (c) -> c.levelSessions.models), (a,b) -> (a.concat(b))))
console.log @allLevelSessions
mostRecentSession = @allLevelSessions.max (session) ->
new Date(session.get('changed'))
console.log new Date(mostRecentSession.get('changed'))
console.log @allLevelSessions.filter (session) ->
changed = new Date(session.get('changed'))
if changed > new Date(mostRecentSession.get('changed'))
console.log changed
changed > new Date(mostRecentSession.get('changed'))
# TODO: Figure out a better way to expose this info, perhaps User methods? # TODO: Figure out a better way to expose this info, perhaps User methods?
stripe = @user.get('stripe') or {} stripe = @user.get('stripe') or {}
@free = stripe.free is true @free = stripe.free is true