Merge branch 'master' into production

This commit is contained in:
Matt Lott 2016-08-12 08:50:11 -07:00
commit b27104bc1f
9 changed files with 40 additions and 11 deletions

View file

@ -1253,6 +1253,7 @@
joining: "Joining class" joining: "Joining class"
course_complete: "Course Complete" course_complete: "Course Complete"
play_arena: "Play Arena" play_arena: "Play Arena"
view_project: "View Project"
start: "Start" start: "Start"
last_level: "Last Level" last_level: "Last Level"
welcome_to_hoc: "Adventurers, welcome to our Hour of Code!" welcome_to_hoc: "Adventurers, welcome to our Hour of Code!"

View file

@ -98,10 +98,19 @@ module.exports = class Classroom extends CocoModel
levels = new Levels(course.levels) levels = new Levels(course.levels)
return levels.find (l) -> l.isLadder() return levels.find (l) -> l.isLadder()
getProjectLevel: (courseID) ->
Levels = require 'collections/Levels'
courses = @get('courses')
course = _.findWhere(courses, {_id: courseID})
return unless course
levels = new Levels(course.levels)
return levels.find (l) -> l.isProject()
statsForSessions: (sessions, courseID) -> statsForSessions: (sessions, courseID) ->
return null unless sessions return null unless sessions
sessions = sessions.models or sessions sessions = sessions.models or sessions
arena = @getLadderLevel(courseID) arena = @getLadderLevel(courseID)
project = @getProjectLevel(courseID)
courseLevels = @getLevels({courseID: courseID, withoutLadderLevels: true}) courseLevels = @getLevels({courseID: courseID, withoutLadderLevels: true})
levelSessionMap = {} levelSessionMap = {}
levelSessionMap[session.get('level').original] = session for session in sessions levelSessionMap[session.get('level').original] = session for session in sessions
@ -151,6 +160,7 @@ module.exports = class Classroom extends CocoModel
next: nextLevel next: nextLevel
first: courseLevels.first() first: courseLevels.first()
arena: arena arena: arena
project: project
playtime: playtime playtime: playtime
stats stats

View file

@ -263,6 +263,9 @@ module.exports = class Level extends CocoModel
isLadder: -> isLadder: ->
return @get('type')?.indexOf('ladder') > -1 return @get('type')?.indexOf('ladder') > -1
isProject: ->
return @get('shareable') is 'project'
isType: (types...) -> isType: (types...) ->
return @get('type', true) in types return @get('type', true) in types

View file

@ -110,10 +110,15 @@ mixin course-instance-body(courseInstance, classroom)
.pull-right .pull-right
if stats.levels.done if stats.levels.done
- var arenaLevel = stats.levels.arena; - var arenaLevel = stats.levels.arena;
- var projectLevel = stats.levels.project;
if arenaLevel if arenaLevel
- var arenaURL = "/play/ladder/"+arenaLevel.get('slug')+"/course/"+courseInstance.id; - var arenaURL = "/play/ladder/"+arenaLevel.get('slug')+"/course/"+courseInstance.id;
a.play-btn.btn.btn-burgandy.btn-lg.m-b-1(data-href=arenaURL, data-level-slug=arenaLevel.get('slug'), data-event-action="Students Play Arena") a.play-btn.btn.btn-burgandy.btn-lg.m-b-1(data-href=arenaURL, data-level-slug=arenaLevel.get('slug'), data-event-action="Students Play Arena")
span(data-i18n="courses.play_arena") span(data-i18n="courses.play_arena")
else if projectLevel
- var projectURL = "/play/level/"+projectLevel.get('slug')+"?course="+course.id+"&course-instance="+courseInstance.id;
a.play-btn.btn.btn-burgandy.btn-lg.m-b-1(data-href=projectURL, data-level-slug=projectLevel.get('slug'), data-event-action="Students Play Project")
span(data-i18n="courses.view_project")
else else
a.btn.btn-default.btn-lg.m-b-1(disabled=true, data-i18n="courses.course_complete") a.btn.btn-default.btn-lg.m-b-1(disabled=true, data-i18n="courses.course_complete")
else if stats.levels.next != stats.levels.first else if stats.levels.next != stats.levels.first

View file

@ -63,7 +63,7 @@ var courses =
name: "CS: Game Development 1", name: "CS: Game Development 1",
slug: "game-dev-1", slug: "game-dev-1",
campaignID: ObjectId("5789236960deed1f00ec2ab8"), campaignID: ObjectId("5789236960deed1f00ec2ab8"),
description: "Learn to create your owns games which you can share with your friends.", description: "Learn to create your own games which you can share with your friends.",
duration: NumberInt(1), duration: NumberInt(1),
free: false, free: false,
releasePhase: 'beta' releasePhase: 'beta'

View file

@ -24,10 +24,15 @@ module.exports =
campaign = yield Campaign.findById course.get('campaignID') campaign = yield Campaign.findById course.get('campaignID')
throw new errors.NotFound('Campaign not found.') unless campaign throw new errors.NotFound('Campaign not found.') unless campaign
levelOriginals = (mongoose.Types.ObjectId(levelID) for levelID of campaign.get('levels')) # TODO: why does campaign.get('levels') return opposite order from direct db query?
sortedLevelIDs = _.keys campaign.get('levels')
sortedLevelIDs.reverse()
levelOriginals = (mongoose.Types.ObjectId(levelID) for levelID in sortedLevelIDs)
query = { original: { $in: levelOriginals }, slug: { $exists: true }} query = { original: { $in: levelOriginals }, slug: { $exists: true }}
select = {documentation: 1, intro: 1, name: 1, slug: 1, thangs: 1} select = {documentation: 1, intro: 1, name: 1, original: 1, slug: 1, thangs: 1}
levels = yield Level.find(query).select(select).lean() levels = yield Level.find(query).select(select).lean()
levels.sort((a, b) -> sortedLevelIDs.indexOf(a.original + '') - sortedLevelIDs.indexOf(b.original + ''))
res.status(200).send(levels) res.status(200).send(levels)
fetchNextLevel: wrap (req, res) -> fetchNextLevel: wrap (req, res) ->

View file

@ -12,7 +12,6 @@ Level = require '../../../server/models/Level'
LevelSession = require '../../../server/models/LevelSession' LevelSession = require '../../../server/models/LevelSession'
Prepaid = require '../../../server/models/Prepaid' Prepaid = require '../../../server/models/Prepaid'
request = require '../request' request = require '../request'
moment = require 'moment'
courseFixture = { courseFixture = {
name: 'Unnamed course' name: 'Unnamed course'
@ -424,18 +423,19 @@ describe 'POST /db/course_instance/-/recent', ->
done() done()
it 'returns course instances within a specified range', utils.wrap (done) -> it 'returns course instances within a specified range', utils.wrap (done) ->
startDay = moment().subtract(1, 'day').format('YYYY-MM-DD') startDay = utils.createDay(-1)
endDay = moment().add(1, 'day').format('YYYY-MM-DD') endDay = utils.createDay(1)
[res, body] = yield request.postAsync(url, { json: { startDay, endDay } }) [res, body] = yield request.postAsync(url, { json: { startDay, endDay } })
expect(res.body.courseInstances.length).toBe(1) expect(res.body.courseInstances.length).toBe(1)
startDay = moment().add(1, 'day').format('YYYY-MM-DD') startDay = utils.createDay(1)
endDay = moment().add(2, 'day').format('YYYY-MM-DD') endDay = utils.createDay(2)
[res, body] = yield request.postAsync(url, { json: { startDay, endDay } }) [res, body] = yield request.postAsync(url, { json: { startDay, endDay } })
console.log startDay, endDay, res.body.courseInstances.length
expect(res.body.courseInstances.length).toBe(0) expect(res.body.courseInstances.length).toBe(0)
startDay = moment().subtract(2, 'day').format('YYYY-MM-DD') startDay = utils.createDay(-2)
endDay = moment().subtract(1, 'day').format('YYYY-MM-DD') endDay = utils.createDay(-1)
[res, body] = yield request.postAsync(url, { json: { startDay, endDay } }) [res, body] = yield request.postAsync(url, { json: { startDay, endDay } })
expect(res.body.courseInstances.length).toBe(0) expect(res.body.courseInstances.length).toBe(0)

View file

@ -150,8 +150,8 @@ describe 'GET /db/course/:handle/level-solutions', ->
paredLevelB = _.pick(res.body, 'name', 'original', 'type') paredLevelB = _.pick(res.body, 'name', 'original', 'type')
campaignJSONA = { name: 'Campaign A', levels: {} } campaignJSONA = { name: 'Campaign A', levels: {} }
campaignJSONA.levels[paredLevelA.original] = paredLevelA
campaignJSONA.levels[paredLevelB.original] = paredLevelB campaignJSONA.levels[paredLevelB.original] = paredLevelB
campaignJSONA.levels[paredLevelA.original] = paredLevelA
[res, body] = yield request.postAsync({uri: getURL('/db/campaign'), json: campaignJSONA}) [res, body] = yield request.postAsync({uri: getURL('/db/campaign'), json: campaignJSONA})
@campaignA = yield Campaign.findById(res.body._id) @campaignA = yield Campaign.findById(res.body._id)

View file

@ -206,3 +206,8 @@ module.exports = mw =
return done(err) if err return done(err) if err
expect(res.statusCode).toBe(201) expect(res.statusCode).toBe(201)
TrialRequest.findById(res.body._id).exec done TrialRequest.findById(res.body._id).exec done
createDay: (offset) ->
day = new Date()
day.setUTCDate(day.getUTCDate() + offset)
day.toISOString().substring(0, 10)