mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Initial setup of the hoc page
This commit is contained in:
parent
39a60f1cb7
commit
c8a47818c2
4 changed files with 64 additions and 37 deletions
|
@ -17,6 +17,7 @@ _.extend CourseInstanceSchema.properties,
|
|||
prepaidID: c.objectId() # deprecated
|
||||
aceConfig:
|
||||
language: {type: 'string', 'enum': ['python', 'javascript']}
|
||||
hourOfCode: { type: 'boolean' }
|
||||
|
||||
c.extendBasicProperties CourseInstanceSchema, 'CourseInstance'
|
||||
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
extends /templates/base
|
||||
|
||||
block content
|
||||
p Hour of Code
|
||||
h1.text-center Welcome to CodeCombat's Hour of Code!
|
||||
br
|
||||
.container-fluid
|
||||
.row
|
||||
.col-md-6.text-center
|
||||
button#student-btn.btn.btn-lg.btn-success(data-i18n="courses.students_click")
|
||||
.col-md-6.text-center
|
||||
button#teacher-btn.btn.btn-lg.btn-default(data-i18n="courses.teachers_click")
|
|
@ -11,45 +11,43 @@ utils = require 'core/utils'
|
|||
module.exports = class HourOfCodeView extends RootView
|
||||
id: 'hour-of-code-view'
|
||||
template: template
|
||||
|
||||
events:
|
||||
'click #student-btn': 'onClickStudentButton'
|
||||
|
||||
constructor: (options) ->
|
||||
super(options)
|
||||
# @setUpHourOfCode()
|
||||
#
|
||||
# setUpHourOfCode: ->
|
||||
# # If we are coming in at /hoc, then we show the landing page.
|
||||
# # If we have ?hoc=true (for the step after the landing page), then we show any HoC-specific instructions.
|
||||
# # If we haven't tracked this player as an hourOfCode player yet, and it's a new account, we do that now.
|
||||
# @hocLandingPage = Backbone.history.getFragment()?.indexOf('hoc') >= 0
|
||||
# @hocMode = utils.getQueryVariable('hoc', false)
|
||||
# elapsed = new Date() - new Date(me.get('dateCreated'))
|
||||
# if not me.get('hourOfCode') and (@hocLandingPage or @hocMode) and elapsed < 5 * 60 * 1000
|
||||
# me.set('hourOfCode', true)
|
||||
# me.patch()
|
||||
# $('body').append($('<img src="https://code.org/api/hour/begin_codecombat.png" style="visibility: hidden;">'))
|
||||
# application.tracker?.trackEvent 'Hour of Code Begin'
|
||||
# if me.get('hourOfCode') and elapsed < 24 * 60 * 60 * 1000
|
||||
# @hocMode = true # If they really just arrived, make sure we're still in hocMode even if they lost ?hoc=true.
|
||||
#
|
||||
# onClickHOCStudentContinue: (e) ->
|
||||
# $('.continue-dialog').modal('hide')
|
||||
# if e
|
||||
# courseID = $(e.target).data('course-id')
|
||||
# else
|
||||
# courseID = '560f1a9f22961295f9427742'
|
||||
#
|
||||
# @state = 'enrolling'
|
||||
# @stateMessage = undefined
|
||||
# @render?()
|
||||
#
|
||||
# # TODO: Copied from CourseEnrollView
|
||||
#
|
||||
# data =
|
||||
# name: 'Single Player'
|
||||
# seats: 9999
|
||||
# courseID: courseID
|
||||
# hourOfCode: true
|
||||
# jqxhr = $.post('/db/course_instance/-/create', data)
|
||||
@setUpHourOfCode()
|
||||
|
||||
setUpHourOfCode: ->
|
||||
# If we are coming in at /hoc, then we show the landing page.
|
||||
# If we have ?hoc=true (for the step after the landing page), then we show any HoC-specific instructions.
|
||||
# If we haven't tracked this player as an hourOfCode player yet, and it's a new account, we do that now.
|
||||
@hocLandingPage = true
|
||||
@hocMode = true
|
||||
elapsed = new Date() - new Date(me.get('dateCreated'))
|
||||
if not me.get('hourOfCode') and (@hocLandingPage or @hocMode) and elapsed < 5 * 60 * 1000
|
||||
me.set('hourOfCode', true)
|
||||
me.patch()
|
||||
$('body').append($('<img src="https://code.org/api/hour/begin_codecombat.png" style="visibility: hidden;">'))
|
||||
application.tracker?.trackEvent 'Hour of Code Begin'
|
||||
|
||||
onClickStudentButton: ->
|
||||
@state = 'enrolling'
|
||||
@stateMessage = undefined
|
||||
@render?()
|
||||
|
||||
$.ajax({
|
||||
method: 'POST'
|
||||
url: '/db/course_instance/-/create-for-hoc'
|
||||
context: @
|
||||
success: (data) ->
|
||||
app.router.navigate("/courses/#{data.courseID}/#{data._id}", {
|
||||
trigger: true
|
||||
})
|
||||
})
|
||||
|
||||
# jqxhr = $.post()
|
||||
# jqxhr.done (data, textStatus, jqXHR) =>
|
||||
# application.tracker?.trackEvent 'Finished HoC student course creation', {courseID: courseID}
|
||||
# # TODO: handle fetch errors
|
||||
|
|
|
@ -32,12 +32,33 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler
|
|||
|
||||
getByRelationship: (req, res, args...) ->
|
||||
relationship = args[1]
|
||||
return @createHOCAPI(req, res) if relationship is 'create-for-hoc'
|
||||
return @getLevelSessionsAPI(req, res, args[0]) if args[1] is 'level_sessions'
|
||||
return @addMember(req, res, args[0]) if req.method is 'POST' and args[1] is 'members'
|
||||
return @getMembersAPI(req, res, args[0]) if args[1] is 'members'
|
||||
return @inviteStudents(req, res, args[0]) if relationship is 'invite_students'
|
||||
return @redeemPrepaidCodeAPI(req, res) if args[1] is 'redeem_prepaid'
|
||||
super arguments...
|
||||
|
||||
createHOCAPI: (req, res) ->
|
||||
return @sendUnauthorizedError(res) if not req.user?
|
||||
courseID = mongoose.Types.ObjectId('560f1a9f22961295f9427742')
|
||||
CourseInstance.findOne { courseID: courseID, ownerID: req.user.get('_id'), hourOfCode: true }, (err, courseInstance) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
if courseInstance
|
||||
console.log 'already made a course instance'
|
||||
return @sendSuccess(res, courseInstance) if courseInstance
|
||||
console.log 'making a new course instance'
|
||||
courseInstance = new CourseInstance({
|
||||
courseID: courseID
|
||||
members: [req.user.get('_id')]
|
||||
name: 'Single Player'
|
||||
ownerID: req.user.get('_id')
|
||||
aceConfig: { language: 'python' }
|
||||
})
|
||||
courseInstance.save (err, courseInstance) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
@sendCreated(res, courseInstance)
|
||||
|
||||
addMember: (req, res, courseInstanceID) ->
|
||||
userID = req.body.userID
|
||||
|
|
Loading…
Reference in a new issue