From 8de00767b3d1f06216eb5b646f7ccb7430faa33b Mon Sep 17 00:00:00 2001 From: Matt Lott Date: Sat, 29 Aug 2015 07:15:35 -0700 Subject: [PATCH] Initial courses object model --- app/core/Router.coffee | 2 +- app/models/Course.coffee | 7 +++++ app/models/CourseInstance.coffee | 7 +++++ app/schemas/models/course.schema.coffee | 14 ++++++++++ .../models/course_instance.schema.coffee | 14 ++++++++++ app/templates/courses/courses.jade | 26 ++++++++++++++++++ app/views/courses/CoursesView.coffee | 18 +++++++++++++ scripts/mongodb/updateCourses.js | 27 +++++++++++++++++++ server/commons/mapping.coffee | 2 ++ server/courses/Course.coffee | 16 +++++++++++ server/courses/CourseInstance.coffee | 20 ++++++++++++++ server/courses/course_handler.coffee | 13 +++++++++ server/courses/course_instance_handler.coffee | 13 +++++++++ 13 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 app/models/Course.coffee create mode 100644 app/models/CourseInstance.coffee create mode 100644 app/schemas/models/course.schema.coffee create mode 100644 app/schemas/models/course_instance.schema.coffee create mode 100644 app/templates/courses/courses.jade create mode 100644 app/views/courses/CoursesView.coffee create mode 100644 scripts/mongodb/updateCourses.js create mode 100644 server/courses/Course.coffee create mode 100644 server/courses/CourseInstance.coffee create mode 100644 server/courses/course_handler.coffee create mode 100644 server/courses/course_instance_handler.coffee diff --git a/app/core/Router.coffee b/app/core/Router.coffee index 07e917923..cd19541a1 100644 --- a/app/core/Router.coffee +++ b/app/core/Router.coffee @@ -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') diff --git a/app/models/Course.coffee b/app/models/Course.coffee new file mode 100644 index 000000000..7cd6ee20c --- /dev/null +++ b/app/models/Course.coffee @@ -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' diff --git a/app/models/CourseInstance.coffee b/app/models/CourseInstance.coffee new file mode 100644 index 000000000..9c1c8f6e7 --- /dev/null +++ b/app/models/CourseInstance.coffee @@ -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' diff --git a/app/schemas/models/course.schema.coffee b/app/schemas/models/course.schema.coffee new file mode 100644 index 000000000..00257de15 --- /dev/null +++ b/app/schemas/models/course.schema.coffee @@ -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 diff --git a/app/schemas/models/course_instance.schema.coffee b/app/schemas/models/course_instance.schema.coffee new file mode 100644 index 000000000..6b2eaeb44 --- /dev/null +++ b/app/schemas/models/course_instance.schema.coffee @@ -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 diff --git a/app/templates/courses/courses.jade b/app/templates/courses/courses.jade new file mode 100644 index 000000000..8b19bf898 --- /dev/null +++ b/app/templates/courses/courses.jade @@ -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(' ') diff --git a/app/views/courses/CoursesView.coffee b/app/views/courses/CoursesView.coffee new file mode 100644 index 000000000..aea87e7fe --- /dev/null +++ b/app/views/courses/CoursesView.coffee @@ -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 diff --git a/scripts/mongodb/updateCourses.js b/scripts/mongodb/updateCourses.js new file mode 100644 index 000000000..b5a856605 --- /dev/null +++ b/scripts/mongodb/updateCourses.js @@ -0,0 +1,27 @@ +// Update course data + +// Usage: +// mongo
:/