mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Fixed tutorial modal for nonexistent tutorials
This commit is contained in:
parent
42bf2996af
commit
a796d88967
2 changed files with 37 additions and 7 deletions
|
@ -11,6 +11,7 @@ module.exports = class LadderPlayModal extends View
|
||||||
closeButton: true
|
closeButton: true
|
||||||
startsLoading: true
|
startsLoading: true
|
||||||
@shownTutorialButton: false
|
@shownTutorialButton: false
|
||||||
|
tutorialLevelExists: null
|
||||||
|
|
||||||
events:
|
events:
|
||||||
'click #skip-tutorial-button': 'hideTutorialButtons'
|
'click #skip-tutorial-button': 'hideTutorialButtons'
|
||||||
|
@ -21,7 +22,7 @@ module.exports = class LadderPlayModal extends View
|
||||||
@otherTeam = if team is 'ogres' then 'humans' else 'ogres'
|
@otherTeam = if team is 'ogres' then 'humans' else 'ogres'
|
||||||
@startLoadingChallengersMaybe()
|
@startLoadingChallengersMaybe()
|
||||||
@wizardType = ThangType.loadUniversalWizard()
|
@wizardType = ThangType.loadUniversalWizard()
|
||||||
|
|
||||||
# PART 1: Load challengers from the db unless some are in the matches
|
# PART 1: Load challengers from the db unless some are in the matches
|
||||||
|
|
||||||
startLoadingChallengersMaybe: ->
|
startLoadingChallengersMaybe: ->
|
||||||
|
@ -58,9 +59,11 @@ module.exports = class LadderPlayModal extends View
|
||||||
# PART 4: Render
|
# PART 4: Render
|
||||||
|
|
||||||
finishRendering: ->
|
finishRendering: ->
|
||||||
@startsLoading = false
|
@checkTutorialLevelExists (exists) =>
|
||||||
@render()
|
@tutorialLevelExists = exists
|
||||||
@maybeShowTutorialButtons()
|
@startsLoading = false
|
||||||
|
@render()
|
||||||
|
@maybeShowTutorialButtons()
|
||||||
|
|
||||||
getRenderData: ->
|
getRenderData: ->
|
||||||
ctx = super()
|
ctx = super()
|
||||||
|
@ -94,7 +97,7 @@ module.exports = class LadderPlayModal extends View
|
||||||
ctx
|
ctx
|
||||||
|
|
||||||
maybeShowTutorialButtons: ->
|
maybeShowTutorialButtons: ->
|
||||||
return if @session or LadderPlayModal.shownTutorialButton
|
return if @session or LadderPlayModal.shownTutorialButton or not @tutorialLevelExists
|
||||||
@$el.find('#normal-view').addClass('secret')
|
@$el.find('#normal-view').addClass('secret')
|
||||||
@$el.find('.modal-header').addClass('secret')
|
@$el.find('.modal-header').addClass('secret')
|
||||||
@$el.find('#noob-view').removeClass('secret')
|
@$el.find('#noob-view').removeClass('secret')
|
||||||
|
@ -105,6 +108,17 @@ module.exports = class LadderPlayModal extends View
|
||||||
@$el.find('.modal-header').removeClass('secret')
|
@$el.find('.modal-header').removeClass('secret')
|
||||||
@$el.find('#noob-view').addClass('secret')
|
@$el.find('#noob-view').addClass('secret')
|
||||||
|
|
||||||
|
checkTutorialLevelExists: (cb) ->
|
||||||
|
levelID = @level.get('slug') or @level.id
|
||||||
|
tutorialLevelID = "#{levelID}-tutorial"
|
||||||
|
success = => cb true
|
||||||
|
failure = => cb false
|
||||||
|
$.ajax
|
||||||
|
type: "GET"
|
||||||
|
url: "/db/level/#{tutorialLevelID}/exists"
|
||||||
|
success: success
|
||||||
|
error: failure
|
||||||
|
|
||||||
# Choosing challengers
|
# Choosing challengers
|
||||||
|
|
||||||
getChallengers: ->
|
getChallengers: ->
|
||||||
|
|
|
@ -37,7 +37,7 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
return @getLeaderboardFacebookFriends(req, res, args[0]) if args[1] is 'leaderboard_facebook_friends'
|
return @getLeaderboardFacebookFriends(req, res, args[0]) if args[1] is 'leaderboard_facebook_friends'
|
||||||
return @getLeaderboardGPlusFriends(req, res, args[0]) if args[1] is 'leaderboard_gplus_friends'
|
return @getLeaderboardGPlusFriends(req, res, args[0]) if args[1] is 'leaderboard_gplus_friends'
|
||||||
return @getHistogramData(req, res, args[0]) if args[1] is 'histogram_data'
|
return @getHistogramData(req, res, args[0]) if args[1] is 'histogram_data'
|
||||||
|
return @checkExistence(req, res, args[0]) if args[1] is 'exists'
|
||||||
return @sendNotFoundError(res)
|
return @sendNotFoundError(res)
|
||||||
|
|
||||||
fetchLevelByIDAndHandleErrors: (id, req, res, callback) ->
|
fetchLevelByIDAndHandleErrors: (id, req, res, callback) ->
|
||||||
|
@ -130,7 +130,23 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
if err? then return @sendDatabaseError res, err
|
if err? then return @sendDatabaseError res, err
|
||||||
valueArray = _.pluck data, "totalScore"
|
valueArray = _.pluck data, "totalScore"
|
||||||
@sendSuccess res, valueArray
|
@sendSuccess res, valueArray
|
||||||
|
|
||||||
|
checkExistence: (req, res, slugOrID) ->
|
||||||
|
findParameters = {}
|
||||||
|
if Handler.isID slugOrID
|
||||||
|
findParameters["_id"] = slugOrID
|
||||||
|
else
|
||||||
|
findParameters["slug"] = slugOrID
|
||||||
|
selectString = 'original version.major permissions'
|
||||||
|
query = Level.findOne(findParameters)
|
||||||
|
.select(selectString)
|
||||||
|
.lean()
|
||||||
|
|
||||||
|
query.exec (err, level) =>
|
||||||
|
return @sendDatabaseError(res, err) if err
|
||||||
|
return @sendNotFoundError(res) unless level?
|
||||||
|
res.send({"exists":true})
|
||||||
|
res.end()
|
||||||
|
|
||||||
getLeaderboard: (req, res, id) ->
|
getLeaderboard: (req, res, id) ->
|
||||||
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)
|
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)
|
||||||
|
|
Loading…
Reference in a new issue