mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
debugging: ladder_view doesn't show loading bar.
This commit is contained in:
parent
360e594f3d
commit
fe96289bf6
3 changed files with 81 additions and 7 deletions
|
@ -164,6 +164,7 @@ module.exports = class SuperModel extends Backbone.Model
|
|||
@num += r.value
|
||||
@progress = @num / @denom
|
||||
|
||||
console.debug 'gintau', 'updateProgress', @progress, @num, @denom
|
||||
@trigger('superModel:updateProgress', @progress)
|
||||
@trigger('loaded-all') if @finished()
|
||||
|
||||
|
@ -190,6 +191,7 @@ class Resource extends Backbone.Model
|
|||
@dependencies.push(depRes)
|
||||
|
||||
markLoaded: ->
|
||||
console.debug 'gintau', 'markLoaded', @
|
||||
@trigger('resource:loaded', @) if not @isLoaded
|
||||
@isLoaded = true
|
||||
@isLoading = false
|
||||
|
@ -232,6 +234,15 @@ class ModelResource extends Resource
|
|||
onLoadDependenciesSuccess: =>
|
||||
@model.fetch(@fetchOptions)
|
||||
|
||||
###
|
||||
setTimeout(=>
|
||||
if @isLoading
|
||||
@markLoaded()
|
||||
@loadDeferred.resolve(@)
|
||||
console.debug 'gintau', 'load-timeout'
|
||||
, 5000)
|
||||
###
|
||||
|
||||
@listenToOnce(@model, 'sync', ->
|
||||
@markLoaded()
|
||||
@loadDeferred.resolve(@)
|
||||
|
|
|
@ -88,8 +88,10 @@ module.exports = class CocoView extends Backbone.View
|
|||
@$el.html @template(@getRenderData())
|
||||
|
||||
if not @supermodel.finished()
|
||||
console.debug 'gintau', 'cocoview-showLoading', @
|
||||
@showLoading()
|
||||
else
|
||||
console.debug 'gintau', 'cocoview-hideLoading', @
|
||||
@hideLoading()
|
||||
|
||||
@afterRender()
|
||||
|
@ -180,6 +182,7 @@ module.exports = class CocoView extends Backbone.View
|
|||
# Loading RootViews
|
||||
|
||||
showLoading: ($el=@$el) ->
|
||||
console.debug 'gintau', 'showLoading', $el
|
||||
$el.find('>').addClass('hidden')
|
||||
$el.append loadingScreenTemplate()
|
||||
@_lastLoading = $el
|
||||
|
|
|
@ -10,6 +10,9 @@ application = require 'application'
|
|||
LadderTabView = require './ladder/ladder_tab'
|
||||
MyMatchesTabView = require './ladder/my_matches_tab'
|
||||
LadderPlayModal = require './ladder/play_modal'
|
||||
SimulatorsLeaderboardCollection = require 'collections/SimulatorsLeaderboardCollection'
|
||||
CocoClass = require 'lib/CocoClass'
|
||||
|
||||
|
||||
HIGHEST_SCORE = 1000000
|
||||
|
||||
|
@ -37,12 +40,16 @@ module.exports = class LadderView extends RootView
|
|||
constructor: (options, @levelID) ->
|
||||
super(options)
|
||||
@level = new Level(_id:@levelID)
|
||||
levelRes = @supermodel.addModelResource(@level, 'level')
|
||||
levelRes.load()
|
||||
@levelRes = @supermodel.addModelResource(@level, 'level')
|
||||
@levelRes.load()
|
||||
|
||||
@sessions = new LevelSessionsCollection(levelID)
|
||||
sessionRes = @supermodel.addModelResource(@sessions, 'level_sessions_collection')
|
||||
sessionRes.load()
|
||||
@sessionRes = @supermodel.addModelResource(@sessions, 'level_sessions_collection')
|
||||
@sessionRes.load()
|
||||
|
||||
@simulatorsLeaderboardData = new SimulatorsLeaderboardData(me)
|
||||
@simulatorsLeaderboardDataRes = @supermodel.addModelResource(@simulatorsLeaderboardData, 'top_simulators')
|
||||
@simulatorsLeaderboardDataRes.markLoaded()
|
||||
|
||||
@simulator = new Simulator()
|
||||
@listenTo(@simulator, 'statusUpdate', @updateSimulationStatus)
|
||||
|
@ -60,10 +67,13 @@ module.exports = class LadderView extends RootView
|
|||
ctx.teams = @teams
|
||||
ctx.levelID = @levelID
|
||||
ctx.levelDescription = marked(@level.get('description')) if @level.get('description')
|
||||
ctx.simulatorsLeaderboardData = @simulatorsLeaderboardData
|
||||
ctx._ = _
|
||||
ctx
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
console.debug 'gintau', 'ladder_view-afterRender', @supermodel.finished()
|
||||
return unless @supermodel.finished()
|
||||
@insertSubView(@ladderTab = new LadderTabView({}, @level, @sessions))
|
||||
@insertSubView(@myMatchesTab = new MyMatchesTabView({}, @level, @sessions))
|
||||
|
@ -123,17 +133,17 @@ module.exports = class LadderView extends RootView
|
|||
|
||||
onClickPlayButton: (e) ->
|
||||
@showPlayModal($(e.target).closest('.play-button').data('team'))
|
||||
|
||||
|
||||
resimulateAllSessions: ->
|
||||
postData =
|
||||
originalLevelID: @level.get('original')
|
||||
levelMajorVersion: @level.get('version').major
|
||||
console.log postData
|
||||
|
||||
|
||||
$.ajax
|
||||
url: '/queue/scoring/resimulateAllSessions'
|
||||
method: 'POST'
|
||||
data: postData
|
||||
data: postData
|
||||
complete: (jqxhr) ->
|
||||
console.log jqxhr.responseText
|
||||
|
||||
|
@ -158,3 +168,53 @@ module.exports = class LadderView extends RootView
|
|||
clearInterval @refreshInterval
|
||||
@simulator.destroy()
|
||||
super()
|
||||
|
||||
class SimulatorsLeaderboardData extends CocoClass
|
||||
###
|
||||
Consolidates what you need to load for a leaderboard into a single Backbone Model-like object.
|
||||
###
|
||||
|
||||
constructor: (@me) ->
|
||||
super()
|
||||
@fetch()
|
||||
|
||||
fetch: ->
|
||||
@topSimulators = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: -1, limit: 20})
|
||||
promises = []
|
||||
promises.push @topSimulators.fetch()
|
||||
unless @me.get('anonymous')
|
||||
score = @me.get('simulatedBy') or 0
|
||||
@playersAbove = new SimulatorsLeaderboardCollection({order:1, scoreOffset: score, limit: 4})
|
||||
promises.push @playersAbove.fetch()
|
||||
if score
|
||||
@playersBelow = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: score, limit: 4})
|
||||
promises.push @playersBelow.fetch()
|
||||
@promise = $.when(promises...)
|
||||
@promise.then @onLoad
|
||||
@promise.fail @onFail
|
||||
@promise
|
||||
|
||||
onLoad: =>
|
||||
return if @destroyed
|
||||
@loaded = true
|
||||
@trigger 'sync', @
|
||||
|
||||
onFail: (resource, jqxhr) =>
|
||||
return if @destroyed
|
||||
@trigger 'error', @, jqxhr
|
||||
|
||||
inTopSimulators: ->
|
||||
return me.id in (user.id for user in @topSimulators.models)
|
||||
|
||||
nearbySimulators: ->
|
||||
l = []
|
||||
above = @playersAbove.models
|
||||
above.reverse()
|
||||
l = l.concat(above)
|
||||
l.push @me
|
||||
l = l.concat(@playersBelow.models) if @playersBelow
|
||||
l
|
||||
|
||||
allResources: ->
|
||||
resources = [@topSimulators, @playersAbove, @playersBelow]
|
||||
return (r for r in resources when r)
|
||||
|
|
Loading…
Reference in a new issue