From e91a15338ef859830843272e4cd106c6329cd2c1 Mon Sep 17 00:00:00 2001 From: Phoenix Eliot Date: Thu, 11 Aug 2016 16:38:14 -0700 Subject: [PATCH] Add View Project buttons to /courses --- app/locale/en.coffee | 1 + app/models/Classroom.coffee | 10 ++++++++++ app/models/Level.coffee | 3 +++ app/templates/courses/courses-view.jade | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/app/locale/en.coffee b/app/locale/en.coffee index d2095a23e..f64795613 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -1253,6 +1253,7 @@ joining: "Joining class" course_complete: "Course Complete" play_arena: "Play Arena" + view_project: "View Project" start: "Start" last_level: "Last Level" welcome_to_hoc: "Adventurers, welcome to our Hour of Code!" diff --git a/app/models/Classroom.coffee b/app/models/Classroom.coffee index 1047ea78a..982bd5f94 100644 --- a/app/models/Classroom.coffee +++ b/app/models/Classroom.coffee @@ -98,10 +98,19 @@ module.exports = class Classroom extends CocoModel levels = new Levels(course.levels) return levels.find (l) -> l.isLadder() + getProjectLevel: (courseID) -> + Levels = require 'collections/Levels' + courses = @get('courses') + course = _.findWhere(courses, {_id: courseID}) + return unless course + levels = new Levels(course.levels) + return levels.find (l) -> l.isProject() + statsForSessions: (sessions, courseID) -> return null unless sessions sessions = sessions.models or sessions arena = @getLadderLevel(courseID) + project = @getProjectLevel(courseID) courseLevels = @getLevels({courseID: courseID, withoutLadderLevels: true}) levelSessionMap = {} levelSessionMap[session.get('level').original] = session for session in sessions @@ -151,6 +160,7 @@ module.exports = class Classroom extends CocoModel next: nextLevel first: courseLevels.first() arena: arena + project: project playtime: playtime stats diff --git a/app/models/Level.coffee b/app/models/Level.coffee index 998e40c2c..38731be81 100644 --- a/app/models/Level.coffee +++ b/app/models/Level.coffee @@ -263,6 +263,9 @@ module.exports = class Level extends CocoModel isLadder: -> return @get('type')?.indexOf('ladder') > -1 + isProject: -> + return @get('shareable') is 'project' + isType: (types...) -> return @get('type', true) in types diff --git a/app/templates/courses/courses-view.jade b/app/templates/courses/courses-view.jade index 69e5265b5..19597c3c1 100644 --- a/app/templates/courses/courses-view.jade +++ b/app/templates/courses/courses-view.jade @@ -110,10 +110,15 @@ mixin course-instance-body(courseInstance, classroom) .pull-right if stats.levels.done - var arenaLevel = stats.levels.arena; + - var projectLevel = stats.levels.project; if arenaLevel - var arenaURL = "/play/ladder/"+arenaLevel.get('slug')+"/course/"+courseInstance.id; a.play-btn.btn.btn-burgandy.btn-lg.m-b-1(data-href=arenaURL, data-level-slug=arenaLevel.get('slug'), data-event-action="Students Play Arena") span(data-i18n="courses.play_arena") + else if projectLevel + - var projectURL = "/play/level/"+projectLevel.get('slug')+"?course="+course.id+"&course-instance="+courseInstance.id; + a.play-btn.btn.btn-burgandy.btn-lg.m-b-1(data-href=projectURL, data-level-slug=projectLevel.get('slug'), data-event-action="Students Play Project") + span(data-i18n="courses.view_project") else a.btn.btn-default.btn-lg.m-b-1(disabled=true, data-i18n="courses.course_complete") else if stats.levels.next != stats.levels.first