Update course level routing

This commit is contained in:
Matt Lott 2015-09-24 17:12:18 -07:00
parent b4d59ced3e
commit d7d6694ee9
4 changed files with 49 additions and 22 deletions

View file

@ -23,9 +23,9 @@ module.exports = class CourseDetailsView extends RootView
'mouseenter .progress-level-cell': 'onMouseEnterPoint'
'mouseleave .progress-level-cell': 'onMouseLeavePoint'
constructor: (options, @courseID) ->
constructor: (options, @courseID, @courseInstanceID) ->
super options
@courseInstanceID = utils.getQueryVariable('ciid', false) or options.courseInstanceID
@courseInstanceID ?= utils.getQueryVariable('ciid', false) or options.courseInstanceID
@adminMode = me.isAdmin()
@memberSort = 'nameAsc'
@course = @supermodel.getModel(Course, @courseID) or new Course _id: @courseID
@ -90,7 +90,8 @@ module.exports = class CourseDetailsView extends RootView
loadCourseInstance: (courseInstanceID) ->
# console.log 'loadCourseInstance'
return if @courseInstance?
@courseInstance = @supermodel.getModel(CourseInstance, courseInstanceID) or new CourseInstance _id: courseInstanceID
@courseInstanceID = courseInstanceID
@courseInstance = @supermodel.getModel(CourseInstance, @courseInstanceID) or new CourseInstance _id: @courseInstanceID
@listenTo @courseInstance, 'sync', @onCourseInstanceSync
if @courseInstance.loaded
@onCourseInstanceSync()
@ -191,7 +192,7 @@ module.exports = class CourseDetailsView extends RootView
Backbone.Mediator.publish 'router:navigate', {
route: "/play/level/#{levelSlug}"
viewClass: 'views/play/level/PlayLevelView'
viewArgs: [{}, levelSlug]
viewArgs: [{courseID: @courseID, courseInstanceID: @courseInstanceID}, levelSlug]
}
onClickSaveSettings: (e) ->

View file

@ -28,6 +28,9 @@ module.exports = class ControlBarView extends CocoView
'click #control-bar-sign-up-button': 'onClickSignupButton'
constructor: (options) ->
@courseID = options.courseID
@courseInstanceID = options.courseInstanceID
@worldName = options.worldName
@session = options.session
@level = options.level
@ -88,13 +91,15 @@ module.exports = class ControlBarView extends CocoView
@homeLink += '/' + campaign
@homeViewArgs.push campaign
else if @level.get('type', true) in ['course']
@homeLink = '/courses/mock1'
@homeViewClass = 'views/courses/mock1/CourseDetailsView'
#campaign = @level.get 'campaign'
#@homeLink += '/' + campaign
#@homeViewArgs.push campaign
@homeLink += '/' + '0'
@homeViewArgs.push '0'
@homeLink = '/courses'
@homeViewClass = 'views/courses/CoursesView'
if @courseID
@homeLink += "/#{@courseID}"
@homeViewArgs.push @courseID
@homeViewClass = 'views/courses/CourseDetailsView'
if @courseInstanceID
@homeLink += "?ciid=#{@courseInstanceID}"
@homeViewArgs.push @courseInstanceID
else
@homeLink = '/'
@homeViewClass = 'views/HomeView'

View file

@ -94,6 +94,9 @@ module.exports = class PlayLevelView extends RootView
console.profile?() if PROFILE_ME
super options
@courseID = options.courseID
@courseInstanceID = options.courseInstanceID
@isEditorPreview = @getQueryVariable 'dev'
@sessionID = @getQueryVariable 'session'
@observing = @getQueryVariable 'observing'
@ -248,7 +251,7 @@ module.exports = class PlayLevelView extends RootView
@insertSubView new ChatView levelID: @levelID, sessionID: @session.id, session: @session
@insertSubView new ProblemAlertView session: @session, level: @level, supermodel: @supermodel
@insertSubView new DuelStatsView level: @level, session: @session, otherSession: @otherSession, supermodel: @supermodel, thangs: @world.thangs if @level.get('type') in ['hero-ladder', 'course-ladder']
@insertSubView @controlBar = new ControlBarView {worldName: utils.i18n(@level.attributes, 'name'), session: @session, level: @level, supermodel: @supermodel}
@insertSubView @controlBar = new ControlBarView {worldName: utils.i18n(@level.attributes, 'name'), session: @session, level: @level, supermodel: @supermodel, courseID: @courseID, courseInstanceID: @courseInstanceID}
#_.delay (=> Backbone.Mediator.publish('level:set-debug', debug: true)), 5000 if @isIPadApp() # if me.displayName() is 'Nick'
initVolume: ->
@ -444,7 +447,7 @@ module.exports = class PlayLevelView extends RootView
showVictory: ->
return if @level.hasLocalChanges() # Don't award achievements when beating level changed in level editor
@endHighlight()
options = {level: @level, supermodel: @supermodel, session: @session, hasReceivedMemoryWarning: @hasReceivedMemoryWarning}
options = {level: @level, supermodel: @supermodel, session: @session, hasReceivedMemoryWarning: @hasReceivedMemoryWarning, courseID: @courseID, courseInstanceID: @courseInstanceID}
ModalClass = if @level.get('type', true) in ['hero', 'hero-ladder', 'hero-coop', 'course', 'course-ladder'] then HeroVictoryModal else VictoryModal
victoryModal = new ModalClass(options)
@openModalView(victoryModal)

View file

@ -42,6 +42,9 @@ module.exports = class HeroVictoryModal extends ModalView
constructor: (options) ->
super(options)
@courseID = options.courseID
@courseInstanceID = options.courseInstanceID
@session = options.session
@level = options.level
@thangTypes = {}
@ -399,10 +402,14 @@ module.exports = class HeroVictoryModal extends ModalView
if @level.get('type', true) is 'course' and nextLevel = @level.get('nextLevel') and not returnToCourse
# need to do something more complicated to load its slug
console.log 'have @nextLevel', @nextLevel, 'from nextLevel', nextLevel
return "/play/level/#{@nextLevel.get('slug')}"
link = "/play/level/#{@nextLevel.get('slug')}"
else if @level.get('type', true) is 'course'
# TODO: figure out which course it is
return '/courses/mock1/0'
link = "/courses"
if @courseID
link += "/#{@courseID}"
if @courseInstanceID
link += "?ciid=#{@courseInstanceID}"
else
link = '/play'
nextCampaign = @getNextLevelCampaign()
link += '/' + nextCampaign
@ -418,11 +425,22 @@ module.exports = class HeroVictoryModal extends ModalView
_.merge options, extraOptions if extraOptions
if @level.get('type', true) is 'course' and @nextLevel and not options.returnToCourse
viewClass = require 'views/play/level/PlayLevelView'
if @courseID
options.courseID = @courseID
if @courseInstanceID
options.courseInstanceID = @courseInstanceID
viewArgs = [options, @nextLevel.get('slug')]
else if @level.get('type', true) is 'course'
options.studentMode = true
viewClass = require 'views/courses/mock1/CourseDetailsView'
viewArgs = [options, '0']
# TODO: shouldn't set viewClass and route in different places
viewClass = require 'views/courses/CoursesView'
viewArgs = [options]
if @courseID
viewClass = require 'views/courses/CourseDetailsView'
options.courseID = @courseID
viewArgs.push @courseID
if @courseInstanceID
options.courseInstanceID = @courseInstanceID
viewArgs.push @courseInstanceID
else
viewClass = require 'views/play/CampaignView'
viewArgs = [options, @getNextLevelCampaign()]