mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-23 11:27:21 -04:00
Partial work on /courses view when signed in
This commit is contained in:
parent
5aff591a8b
commit
a98d0b1b2a
4 changed files with 71 additions and 4 deletions
app
server/courses
|
@ -11,4 +11,14 @@
|
|||
|
||||
#begin-hoc-area
|
||||
width: 50%
|
||||
margin: 0 auto
|
||||
margin: 0 auto
|
||||
|
||||
hr
|
||||
border-top: 1px solid lightgrey
|
||||
margin: 5px 0
|
||||
|
||||
h2
|
||||
margin-top: 5px
|
||||
|
||||
.course-instance-entry
|
||||
padding-left: 40px
|
|
@ -4,10 +4,11 @@ block content
|
|||
.pull-right
|
||||
a(href="/teachers") Teachers, click here!
|
||||
|
||||
h1.text-center Adventurers, welcome to Courses!
|
||||
|
||||
#main-content
|
||||
if me.isAnonymous()
|
||||
|
||||
h1.text-center Adventurers, welcome to Courses!
|
||||
|
||||
.text-center
|
||||
p
|
||||
h3 Ready to play?
|
||||
|
@ -23,8 +24,25 @@ block content
|
|||
li while loops to solve pesky puzzles
|
||||
li strings & variables to customize actions
|
||||
li how to defeat an ogre (important life skills!)
|
||||
|
||||
else
|
||||
|
||||
h1.text-center Welcome to your Courses page!
|
||||
|
||||
if view.hocCourseInstance
|
||||
h2 Saved Games
|
||||
hr
|
||||
|
||||
.course-instance-entry
|
||||
h2
|
||||
span.spr Hour of Code: Course 1
|
||||
span.spr= (view.hocCourseInstance.get('aceConfig') || {}).language === 'python' ? 'Python' : 'JavaScript'
|
||||
small
|
||||
a#change-language-link change language
|
||||
|
||||
#begin-hoc-area.hide
|
||||
h2.text-center(data-i18n="common.loading")
|
||||
.progress.progress-striped.active
|
||||
.progress-bar(style="width: 100%")
|
||||
.progress-bar(style="width: 100%")
|
||||
|
||||
mixin course-instance-entry(courseInstance, course, levels)
|
|
@ -5,6 +5,10 @@ template = require 'templates/courses/courses-view'
|
|||
StudentLogInModal = require 'views/courses/StudentLogInModal'
|
||||
StudentSignUpModal = require 'views/courses/StudentSignUpModal'
|
||||
CourseInstance = require 'models/CourseInstance'
|
||||
CocoCollection = require 'collections/CocoCollection'
|
||||
Course = require 'models/Course'
|
||||
Classroom = require 'models/Classroom'
|
||||
LevelSession = require 'models/LevelSession'
|
||||
|
||||
module.exports = class CoursesView extends RootView
|
||||
id: 'courses-view'
|
||||
|
@ -14,6 +18,23 @@ module.exports = class CoursesView extends RootView
|
|||
'click #log-in-btn': 'onClickLogInButton'
|
||||
'click #start-new-game-btn': 'onClickStartNewGameButton'
|
||||
|
||||
initialize: ->
|
||||
@courseInstances = new CocoCollection([], { url: "/db/user/#{me.id}/course_instances", model: CourseInstance})
|
||||
@courseInstances.comparator = (ci) -> return ci.get('classroomID') + ci.get('courseID')
|
||||
@supermodel.loadCollection(@courseInstances, 'course_instances')
|
||||
@classrooms = new CocoCollection([], { url: "/db/classroom", model: Classroom })
|
||||
@supermodel.loadCollection(@classrooms, 'classrooms', { data: {memberID: me.id} })
|
||||
@courses = new CocoCollection([], { url: "/db/course", model: Course})
|
||||
@supermodel.loadCollection(@courses, 'courses')
|
||||
|
||||
onLoaded: ->
|
||||
@hocCourseInstance = @courseInstances.findWhere({hourOfCode: true})
|
||||
if @hocCourseInstance
|
||||
@courseInstances.remove(@hocCourseInstance)
|
||||
@sessions = new CocoCollection([], { url: @hocCourseInstance.url() + '/my-course-level-sessions', model: LevelSession })
|
||||
@supermodel.loadCollection(@sessions, 'sessions')
|
||||
super()
|
||||
|
||||
onClickStartNewGameButton: ->
|
||||
@openSignUpModal()
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler
|
|||
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'
|
||||
return @getMyCourseLevelSessionsAPI(req, res, args[0]) if args[1] is 'my-course-level-sessions'
|
||||
super arguments...
|
||||
|
||||
createHOCAPI: (req, res) ->
|
||||
|
@ -130,6 +131,23 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler
|
|||
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, cleandocs)
|
||||
|
||||
getMyCourseLevelSessionsAPI: (req, res, courseInstanceID) ->
|
||||
CourseInstance.findById courseInstanceID, (err, courseInstance) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless courseInstance
|
||||
Course.findById courseInstance.get('courseID'), (err, course) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless course
|
||||
Campaign.findById course.get('campaignID'), (err, campaign) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
return @sendNotFoundError(res) unless campaign
|
||||
levelIDs = (levelID for levelID, level of campaign.get('levels') when not _.contains(level.type, 'ladder'))
|
||||
query = {$and: [{creator: req.user.id}, {'level.original': {$in: levelIDs}}]}
|
||||
LevelSession.find query, (err, documents) =>
|
||||
return @sendDatabaseError(res, err) if err?
|
||||
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
|
||||
@sendSuccess(res, cleandocs)
|
||||
|
||||
getMembersAPI: (req, res, courseInstanceID) ->
|
||||
CourseInstance.findById courseInstanceID, (err, courseInstance) =>
|
||||
return @sendDatabaseError(res, err) if err
|
||||
|
|
Loading…
Reference in a new issue