mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Have CourseVictoryModal used for course-ladder levels
This commit is contained in:
parent
9d0ad7af44
commit
10ca59d10f
8 changed files with 67 additions and 4 deletions
|
@ -5,3 +5,10 @@ module.exports = class Course extends CocoModel
|
|||
@className: 'Course'
|
||||
@schema: schema
|
||||
urlRoot: '/db/course'
|
||||
|
||||
fetchForCourseInstance: (courseInstanceID, opts) ->
|
||||
options = {
|
||||
url: "/db/course_instance/#{courseInstanceID}/course"
|
||||
}
|
||||
_.extend options, opts
|
||||
@fetch options
|
||||
|
|
|
@ -42,8 +42,9 @@
|
|||
|
||||
.row
|
||||
.col-sm-5.col-sm-offset-2
|
||||
// TODO: Add this and rest of campaign functionality
|
||||
// button#continue-btn.btn.btn-illustrated.btn-default.btn-block.btn-lg.text-uppercase View Leaderboards
|
||||
// TODO: Add rest of campaign functionality
|
||||
if view.level.get('type') === 'course-ladder'
|
||||
button#ladder-btn.btn.btn-illustrated.btn-default.btn-block.btn-lg.text-uppercase Ladder
|
||||
.col-sm-5
|
||||
if !view.nextLevel.isNew()
|
||||
button#next-level-btn.btn.btn-illustrated.btn-primary.btn-block.btn-lg.text-uppercase(data-i18n='play_level.next_level')
|
||||
|
|
|
@ -26,8 +26,8 @@ module.exports = class LadderPlayModal extends ModalView
|
|||
|
||||
initialize: (options, @level, @session, @team) ->
|
||||
@otherTeam = if @team is 'ogres' then 'humans' else 'ogres'
|
||||
@startLoadingChallengersMaybe()
|
||||
@wizardType = ThangType.loadUniversalWizard()
|
||||
@startLoadingChallengersMaybe()
|
||||
@levelID = @level.get('slug') or @level.id
|
||||
@language = @session?.get('codeLanguage') ? me.get('aceConfig')?.language ? 'python'
|
||||
@languages = [
|
||||
|
|
|
@ -44,6 +44,11 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
@levelSessions = @supermodel.loadCollection(@levelSessions, 'sessions', {
|
||||
data: { project: 'state.complete level.original playtime changed' }
|
||||
}).model
|
||||
|
||||
if not @course
|
||||
@course = new Course()
|
||||
@supermodel.trackRequest @course.fetchForCourseInstance(@courseInstanceID)
|
||||
|
||||
window.tracker?.trackEvent 'Play Level Victory Modal Loaded', category: 'Students', levelSlug: @level.get('slug'), ['Mixpanel']
|
||||
|
||||
onResourceLoadFailed: (e) ->
|
||||
|
@ -53,6 +58,7 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
|
||||
onLoaded: ->
|
||||
super()
|
||||
@courseID ?= @course.id
|
||||
@views = []
|
||||
|
||||
@levelSessions?.remove(@session)
|
||||
|
@ -67,6 +73,7 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
|
||||
progressView.once 'done', @onDone, @
|
||||
progressView.once 'next-level', @onNextLevel, @
|
||||
progressView.once 'ladder', @onLadder, @
|
||||
for view in @views
|
||||
view.on 'continue', @onViewContinue, @
|
||||
@views.push(progressView)
|
||||
|
@ -104,3 +111,15 @@ module.exports = class CourseVictoryModal extends ModalView
|
|||
else
|
||||
link = "/courses/#{@courseID}/#{@courseInstanceID}"
|
||||
application.router.navigate(link, {trigger: true})
|
||||
|
||||
onLadder: ->
|
||||
# Preserve the supermodel as we navigate back to the ladder.
|
||||
viewArgs = [{supermodel: if @options.hasReceivedMemoryWarning then null else @supermodel}, @level.get('slug')]
|
||||
ladderURL = "/play/ladder/#{@level.get('slug') || @level.id}"
|
||||
if leagueID = (@courseInstanceID or @getQueryVariable 'league')
|
||||
leagueType = if @level.get('type') is 'course-ladder' then 'course' else 'clan'
|
||||
viewArgs.push leagueType
|
||||
viewArgs.push leagueID
|
||||
ladderURL += "/#{leagueType}/#{leagueID}"
|
||||
ladderURL += '#my-matches'
|
||||
Backbone.Mediator.publish 'router:navigate', route: ladderURL, viewClass: 'views/ladder/LadderView', viewArgs: viewArgs
|
||||
|
|
|
@ -10,6 +10,7 @@ module.exports = class ProgressView extends CocoView
|
|||
events:
|
||||
'click #done-btn': 'onClickDoneButton'
|
||||
'click #next-level-btn': 'onClickNextLevelButton'
|
||||
'click #ladder-btn': 'onClickLadderButton'
|
||||
|
||||
initialize: (options) ->
|
||||
@level = options.level
|
||||
|
@ -27,3 +28,6 @@ module.exports = class ProgressView extends CocoView
|
|||
|
||||
onClickNextLevelButton: ->
|
||||
@trigger 'next-level'
|
||||
|
||||
onClickLadderButton: ->
|
||||
@trigger 'ladder'
|
||||
|
|
|
@ -140,6 +140,18 @@ module.exports =
|
|||
res.status(200).send(classroom)
|
||||
|
||||
|
||||
fetchCourse: wrap (req, res) ->
|
||||
courseInstance = yield database.getDocFromHandle(req, CourseInstance)
|
||||
if not courseInstance
|
||||
throw new errors.NotFound('Course Instance not found.')
|
||||
|
||||
course = yield Course.findById(courseInstance.get('courseID')).select(parse.getProjectFromReq(req))
|
||||
if not course
|
||||
throw new errors.NotFound('Course not found.')
|
||||
|
||||
res.status(200).send(course.toObject({req: req}))
|
||||
|
||||
|
||||
fetchRecent: wrap (req, res) ->
|
||||
query = {$and: [{name: {$ne: 'Single Player'}}, {hourOfCode: {$ne: true}}]}
|
||||
query["$and"].push(_id: {$gte: objectIdFromTimestamp(req.body.startDay + "T00:00:00.000Z")}) if req.body.startDay?
|
||||
|
|
|
@ -88,7 +88,8 @@ module.exports.setup = (app) ->
|
|||
app.get('/db/course_instance/:handle/levels/:levelOriginal/sessions/:sessionID/next', mw.courseInstances.fetchNextLevel)
|
||||
app.post('/db/course_instance/:handle/members', mw.auth.checkLoggedIn(), mw.courseInstances.addMembers)
|
||||
app.get('/db/course_instance/:handle/classroom', mw.auth.checkLoggedIn(), mw.courseInstances.fetchClassroom)
|
||||
|
||||
app.get('/db/course_instance/:handle/course', mw.auth.checkLoggedIn(), mw.courseInstances.fetchCourse)
|
||||
|
||||
app.put('/db/user/:handle', mw.users.resetEmailVerifiedFlag)
|
||||
app.delete('/db/user/:handle', mw.users.removeFromClassrooms)
|
||||
app.get('/db/user', mw.users.fetchByGPlusID, mw.users.fetchByFacebookID)
|
||||
|
|
|
@ -375,6 +375,25 @@ describe 'GET /db/course_instance/:handle/classroom', ->
|
|||
expect(res.statusCode).toBe(403)
|
||||
done()
|
||||
|
||||
describe 'GET /db/course_instance/:handle/course', ->
|
||||
|
||||
beforeEach utils.wrap (done) ->
|
||||
yield utils.clearModels [User, CourseInstance, Classroom]
|
||||
@course = new Course({})
|
||||
yield @course.save()
|
||||
@courseInstance = new CourseInstance({courseID: @course._id})
|
||||
yield @courseInstance.save()
|
||||
@url = getURL("/db/course_instance/#{@courseInstance.id}/course")
|
||||
done()
|
||||
|
||||
it 'returns the course instance\'s referenced course', utils.wrap (done) ->
|
||||
user = yield utils.initUser()
|
||||
yield utils.loginUser user
|
||||
[res, body] = yield request.getAsync(@url, {json: true})
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body._id).toBe(@course.id)
|
||||
done()
|
||||
|
||||
describe 'POST /db/course_instance/-/recent', ->
|
||||
|
||||
url = getURL('/db/course_instance/-/recent')
|
||||
|
|
Loading…
Reference in a new issue