mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -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
|
||||
startsLoading: true
|
||||
@shownTutorialButton: false
|
||||
tutorialLevelExists: null
|
||||
|
||||
events:
|
||||
'click #skip-tutorial-button': 'hideTutorialButtons'
|
||||
|
@ -21,7 +22,7 @@ module.exports = class LadderPlayModal extends View
|
|||
@otherTeam = if team is 'ogres' then 'humans' else 'ogres'
|
||||
@startLoadingChallengersMaybe()
|
||||
@wizardType = ThangType.loadUniversalWizard()
|
||||
|
||||
|
||||
# PART 1: Load challengers from the db unless some are in the matches
|
||||
|
||||
startLoadingChallengersMaybe: ->
|
||||
|
@ -58,9 +59,11 @@ module.exports = class LadderPlayModal extends View
|
|||
# PART 4: Render
|
||||
|
||||
finishRendering: ->
|
||||
@startsLoading = false
|
||||
@render()
|
||||
@maybeShowTutorialButtons()
|
||||
@checkTutorialLevelExists (exists) =>
|
||||
@tutorialLevelExists = exists
|
||||
@startsLoading = false
|
||||
@render()
|
||||
@maybeShowTutorialButtons()
|
||||
|
||||
getRenderData: ->
|
||||
ctx = super()
|
||||
|
@ -94,7 +97,7 @@ module.exports = class LadderPlayModal extends View
|
|||
ctx
|
||||
|
||||
maybeShowTutorialButtons: ->
|
||||
return if @session or LadderPlayModal.shownTutorialButton
|
||||
return if @session or LadderPlayModal.shownTutorialButton or not @tutorialLevelExists
|
||||
@$el.find('#normal-view').addClass('secret')
|
||||
@$el.find('.modal-header').addClass('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('#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
|
||||
|
||||
getChallengers: ->
|
||||
|
|
|
@ -37,7 +37,7 @@ LevelHandler = class LevelHandler extends Handler
|
|||
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 @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)
|
||||
|
||||
fetchLevelByIDAndHandleErrors: (id, req, res, callback) ->
|
||||
|
@ -130,7 +130,23 @@ LevelHandler = class LevelHandler extends Handler
|
|||
if err? then return @sendDatabaseError res, err
|
||||
valueArray = _.pluck data, "totalScore"
|
||||
@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) ->
|
||||
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)
|
||||
|
|
Loading…
Reference in a new issue