Fix course buttons and level links in /courses

This commit is contained in:
Scott Erickson 2015-11-29 15:25:59 -05:00
parent ea0c274a3c
commit 47acfc93d0
3 changed files with 33 additions and 21 deletions
app
styles/courses
templates/courses
views/courses

View file

@ -1,7 +1,7 @@
#courses-view
#site-content-area
padding-left: 150px
padding-right: 150px
padding-left: 250px
padding-right: 250px
h1
margin-bottom: 30px
@ -29,4 +29,3 @@
.course-instance-entry
padding-left: 40px
padding-right: 200px

View file

@ -80,8 +80,7 @@ block content
h3
span.spr= course.get('name')
small
// TODO: where do we show list of levels?
a(href="/courses/classrooms/"+classroom.id) view levels
a(href="/courses/"+courseInstance.get('courseID')+'/'+courseInstance.id+'#levels') view levels
+course-instance-body(courseInstance)
.clearfix
@ -113,16 +112,20 @@ mixin course-instance-body(courseInstance)
- var course = view.courses.get(courseInstance.get('courseID'));
- var campaign = view.campaigns.get(course.get('campaignID'));
- var levels = campaign.levelsCollection();
if courseInstance.sessions.allDone()
- var complete = view.isCampaignComplete(campaign, courseInstance.sessions);
if complete
.text-success
span.glyphicon.glyphicon-ok
span.spl Course Complete!
.pull-right
if courseInstance.sessions.allDone()
- var arenaLevel = sessions.findWhere({ type: 'course-ladder' });
- var arenaURL = "/play/ladder/"+arenaLevel.get('slug')+"/course/"+courseInstance.id;
a.btn.btn-warning.btn-lg(href=arenaURL)
| Play Arena
if complete
- var arenaLevel = levels.findWhere({ type: 'course-ladder' });
if arenaLevel
- var arenaURL = "/play/ladder/"+arenaLevel.get('slug')+"/course/"+courseInstance.id;
a.btn.btn-warning.btn-lg(href=arenaURL)
| Play Arena
else
a.btn.btn-default.btn-lg(disabled=true) Course Complete
else if courseInstance.sessions.size()
- var lastSession = courseInstance.sessions.last();
- var lastLevel = levels.findWhere({original: lastSession.get('level').original});

View file

@ -28,6 +28,7 @@ module.exports = class CoursesView extends RootView
initialize: ->
@courseInstances = new CocoCollection([], { url: "/db/user/#{me.id}/course_instances", model: CourseInstance})
@courseInstances.comparator = (ci) -> return ci.get('classroomID') + ci.get('courseID')
@listenToOnce @courseInstances, 'sync', @onCourseInstancesLoaded
@supermodel.loadCollection(@courseInstances, 'course_instances')
@classrooms = new CocoCollection([], { url: "/db/classroom", model: Classroom })
@supermodel.loadCollection(@classrooms, 'classrooms', { data: {memberID: me.id} })
@ -36,21 +37,30 @@ module.exports = class CoursesView extends RootView
@campaigns = new CocoCollection([], { url: "/db/campaign", model: Campaign })
@supermodel.loadCollection(@campaigns, 'campaigns', { data: { type: 'course' }})
onLoaded: ->
onCourseInstancesLoaded: ->
map = {}
for courseInstance in @courseInstances.models
# TODO: fetch sessions for given course instance
# TODO: make sure we only fetch one per courseID
courseInstance.sessions = new CocoCollection([], { url: '???', model: LevelSession })
courseInstance.sessions.allDone = ->
# TODO: should return if all non-arena courses are complete
courseID = courseInstance.get('courseID')
if map[courseID]
courseInstance.sessions = map[courseID]
continue
map[courseID] = courseInstance.sessions = new CocoCollection([], {
url: courseInstance.url() + '/my-course-level-sessions',
model: LevelSession
})
courseInstance.sessions.comparator = 'changed'
@supermodel.loadCollection(courseInstance.sessions, 'sessions')
@hocCourseInstance = @courseInstances.findWhere({hourOfCode: true})
if @hocCourseInstance
@courseInstances.remove(@hocCourseInstance)
@sessions = new CocoCollection([], { url: @hocCourseInstance.url() + '/my-course-level-sessions', model: LevelSession })
@sessions.comparator = 'changed'
@supermodel.loadCollection(@sessions, 'sessions')
super()
isCampaignComplete: (campaign, sessions) ->
levels = _.values(campaign.get('levels'))
levels = (level for level in levels when not _.contains(level.type, 'ladder'))
levelOriginals = _.pluck(levels, 'original')
sessionOriginals = (session.get('level').original for session in sessions.models)
return _.size(_.difference(levelOriginals, sessionOriginals)) is 0
onClickStartNewGameButton: ->
@openSignUpModal()