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(data-i18n="ladder.games_simulated_for") Games simulated for you:
| |
span#simulated-for-you= me.get('simulatedFor') || 0 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 table.table.table-bordered.table-condensed.table-hover
tr tr
th th

View file

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

View file

@ -68,7 +68,7 @@ module.exports = class LadderView extends RootView
@showPlayModal(hash) if @sessions.loaded @showPlayModal(hash) if @sessions.loaded
fetchSessionsAndRefreshViews: -> 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}) @sessions.fetch({"success": @refreshViews})
refreshViews: => refreshViews: =>
@ -76,7 +76,7 @@ module.exports = class LadderView extends RootView
@lastRefreshTime = new Date() @lastRefreshTime = new Date()
@ladderTab.refreshLadder() @ladderTab.refreshLadder()
@myMatchesTab.refreshMatches() @myMatchesTab.refreshMatches()
console.log "Refreshed sessions for ladder and matches." @simulateTab.refresh()
onIdleChanged: (e) -> onIdleChanged: (e) ->
@fetchSessionsAndRefreshViews() unless e.idle @fetchSessionsAndRefreshViews() unless e.idle