Live simulation count and fixed double simulator leaderboard session

This commit is contained in:
Michael Schmatz 2014-05-16 13:16:35 -07:00
parent 60342cc40e
commit 934c853789
3 changed files with 17 additions and 4 deletions

View file

@ -15,7 +15,10 @@ p.simulation-count
span(data-i18n="ladder.games_simulated_for") Games simulated for you:
|
span#simulated-for-you= me.get('simulatedFor') || 0
p.simulation-count
span(data-i18n="ladder.games_in_queue") Games currently in the queue:
|
span#games-in-queue= numberOfGamesInQueue || 0
table.table.table-bordered.table-condensed.table-hover
tr
th

View file

@ -29,6 +29,7 @@ module.exports = class SimulateTabView extends CocoView
ctx = super()
ctx.simulationStatus = @simulationStatus
ctx.simulatorsLeaderboardData = @simulatorsLeaderboardData
ctx.numberOfGamesInQueue = @simulatorsLeaderboardData.numberOfGamesInQueue
ctx._ = _
ctx
@ -44,6 +45,11 @@ module.exports = class SimulateTabView extends CocoView
@simulator.fetchAndSimulateTask()
refresh: ->
success = (numberOfGamesInQueue) ->
$("#games-in-queue").text numberOfGamesInQueue
$.ajax "/queue/messagesInQueueCount", {success}
updateSimulationStatus: (simulationStatus, sessions) ->
@simulationStatus = simulationStatus
try
@ -92,13 +98,17 @@ class SimulatorsLeaderboardData extends CocoClass
promises.push @topSimulators.fetch()
unless @me.get('anonymous')
score = @me.get('simulatedBy') or 0
queueSuccess = (@numberOfGamesInQueue) =>
promises.push $.ajax "/queue/messagesInQueueCount", {success: queueSuccess}
@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()
success = (@myRank) =>
promises.push $.ajax "/db/user/me/simulator_leaderboard_rank?scoreOffset=#{score}", {success}
@promise = $.when(promises...)
@promise.then @onLoad
@promise.fail @onFail
@ -121,7 +131,7 @@ class SimulatorsLeaderboardData extends CocoClass
above = @playersAbove.models
l = l.concat(above)
l.reverse()
l.push @me
#l.push @me
l = l.concat(@playersBelow.models) if @playersBelow
if @myRank
startRank = @myRank - 4

View file

@ -68,7 +68,7 @@ module.exports = class LadderView extends RootView
@showPlayModal(hash) if @sessions.loaded
fetchSessionsAndRefreshViews: ->
return if @destroyed or application.userIsIdle or @$el.find('#simulate.active').length or (new Date() - 2000 < @lastRefreshTime) or not @supermodel.finished()
return if @destroyed or application.userIsIdle or (new Date() - 2000 < @lastRefreshTime) or not @supermodel.finished()
@sessions.fetch({"success": @refreshViews})
refreshViews: =>
@ -76,7 +76,7 @@ module.exports = class LadderView extends RootView
@lastRefreshTime = new Date()
@ladderTab.refreshLadder()
@myMatchesTab.refreshMatches()
console.log "Refreshed sessions for ladder and matches."
@simulateTab.refresh()
onIdleChanged: (e) ->
@fetchSessionsAndRefreshViews() unless e.idle