Initial courses object model

This commit is contained in:
Matt Lott 2015-08-29 07:15:35 -07:00
parent 10e33dab4a
commit 8de00767b3
13 changed files with 178 additions and 1 deletions

View file

@ -58,7 +58,7 @@ module.exports = class CocoRouter extends Backbone.Router
'contribute/diplomat': go('contribute/DiplomatView')
'contribute/scribe': go('contribute/ScribeView')
'courses': go('courses/mock1/CoursesView')
'courses': go('courses/CoursesView')
'courses/mock1': go('courses/mock1/CoursesView')
'courses/mock1/enroll/:courseID': go('courses/mock1/CourseEnrollView')
'courses/mock1/:courseID': go('courses/mock1/CourseDetailsView')

7
app/models/Course.coffee Normal file
View file

@ -0,0 +1,7 @@
CocoModel = require './CocoModel'
schema = require 'schemas/models/course.schema'
module.exports = class Course extends CocoModel
@className: 'Course'
@schema: schema
urlRoot: '/db/course'

View file

@ -0,0 +1,7 @@
CocoModel = require './CocoModel'
schema = require 'schemas/models/course_instance.schema'
module.exports = class CourseInstance extends CocoModel
@className: 'CourseInstance'
@schema: schema
urlRoot: '/db/course_instance'

View file

@ -0,0 +1,14 @@
c = require './../schemas'
CourseSchema = c.object {title: 'Course', required: ['name']}
c.extendNamedProperties CourseSchema # name first
_.extend CourseSchema.properties,
campaignID: c.objectId()
concepts: c.array {title: 'Programming Concepts', uniqueItems: true}, c.concept
description: {type: 'string'}
screenshot: c.url {title: 'URL', description: 'Link to course screenshot.'}
c.extendBasicProperties CourseSchema, 'Course'
module.exports = CourseSchema

View file

@ -0,0 +1,14 @@
c = require './../schemas'
CourseInstanceSchema = c.object {title: 'Course Instance'}
c.extendNamedProperties CourseInstanceSchema # name first
_.extend CourseInstanceSchema.properties,
description: {type: 'string'}
members: c.array {title: 'Members'}, c.objectId()
ownerID: c.objectId()
prepaidID: c.objectId()
c.extendBasicProperties CourseInstanceSchema, 'CourseInstance'
module.exports = CourseInstanceSchema

View file

@ -0,0 +1,26 @@
extends /templates/base
block content
//- DO NOT localize / i18n
div(style='border-bottom: 1px solid black')
span *UNDER CONSTRUCTION, please send feedback to
a.spl(href='mailto:team@codecombat.com') team@codecombat.com
h1(style='text-align: center;') Courses
.container-fluid
.row(style='font-size: 20px;')
.col-md-3
.col-md-3 Name
.col-md-3 Description
.col-md-3 Concepts
each course in courses
.row(style='border-top: 1px solid gray; padding: 10px;')
.col-md-3
img(src="#{course.get('screenshot')}", style="width: 100%;")
.col-md-3
p= course.get('name')
a(href="/editor/campaign/#{course.get('campaignID')}") Campaign (levels)
.col-md-3= course.get('description')
.col-md-3= course.get('concepts').join(' ')

View file

@ -0,0 +1,18 @@
RootView = require 'views/core/RootView'
template = require 'templates/courses/courses'
CocoCollection = require 'collections/CocoCollection'
Course = require 'models/Course'
module.exports = class CoursesView extends RootView
id: 'courses-view'
template: template
constructor: (options) ->
super options
@courses = new CocoCollection([], { url: "/db/course", model: Course})
@supermodel.loadCollection(@courses, 'courses')
getRenderData: ->
context = super()
context.courses = @courses.models ? []
context

View file

@ -0,0 +1,27 @@
// Update course data
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
// NOTE: uses name as unique identifier, so changing the name will insert a new course
var documents =
[
{
name: "Introduction to Computer Science",
slug: "introduction-to-computer-science",
campaignID: ObjectId("55b29efd1cd6abe8ce07db0d"),
concepts: ['basic_syntax', 'arguments', 'while_loops', 'strings', 'variables'],
description: "Learn basic syntax, while loops, and the CodeCombat environment.",
screenshot: "/images/pages/courses/101_info.png"
}
];
for (var i = 0; i < documents.length; i++) {
var doc = documents[i];
db.courses.update({name: doc.name}, doc, {upsert: true});
}
function log(str) {
print(new Date().toISOString() + " " + str);
}

View file

@ -8,6 +8,8 @@ module.exports.handlers =
'article': 'articles/article_handler'
'campaign': 'campaigns/campaign_handler'
'clan': 'clans/clan_handler'
'course': 'courses/course_handler'
'course_instance': 'courses/course_instance_handler'
'level': 'levels/level_handler'
'level_component': 'levels/components/level_component_handler'
'level_feedback': 'levels/feedbacks/level_feedback_handler'

View file

@ -0,0 +1,16 @@
mongoose = require 'mongoose'
config = require '../../server_config'
plugins = require '../plugins/plugins'
jsonSchema = require '../../app/schemas/models/course.schema'
CourseSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
CourseSchema.plugin plugins.NamedPlugin
CourseSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'description']}
CourseSchema.statics.privateProperties = []
CourseSchema.statics.editableProperties = []
CourseSchema.statics.jsonSchema = jsonSchema
module.exports = Course = mongoose.model 'course', CourseSchema, 'courses'

View file

@ -0,0 +1,20 @@
mongoose = require 'mongoose'
config = require '../../server_config'
plugins = require '../plugins/plugins'
jsonSchema = require '../../app/schemas/models/course_instance.schema'
CourseInstanceSchema = new mongoose.Schema {}, {strict: false, minimize: false, read:config.mongo.readpref}
CourseInstanceSchema.plugin plugins.NamedPlugin
CourseInstanceSchema.plugin plugins.SearchablePlugin, {searchable: ['name', 'description']}
CourseInstanceSchema.statics.privateProperties = []
CourseInstanceSchema.statics.editableProperties = [
'description'
'members'
'name'
]
CourseInstanceSchema.statics.jsonSchema = jsonSchema
module.exports = CourseInstance = mongoose.model 'course.instance', CourseInstanceSchema, 'course.instances'

View file

@ -0,0 +1,13 @@
mongoose = require 'mongoose'
Handler = require '../commons/Handler'
Course = require './Course'
CourseHandler = class CourseHandler extends Handler
modelClass: Course
jsonSchema: require '../../app/schemas/models/course.schema'
allowedMethods: ['GET']
hasAccess: (req) ->
req.method in @allowedMethods or req.user?.isAdmin()
module.exports = new CourseHandler()

View file

@ -0,0 +1,13 @@
mongoose = require 'mongoose'
Handler = require '../commons/Handler'
CourseInstance = require './CourseInstance'
CourseInstanceHandler = class CourseInstanceHandler extends Handler
modelClass: CourseInstance
jsonSchema: require '../../app/schemas/models/course_instance.schema'
allowedMethods: ['GET', 'POST', 'PUT', 'DELETE']
hasAccess: (req) ->
req.method is 'GET' or req.user?.isAdmin()
module.exports = new CourseInstanceHandler()