From 934c8537898d47183207879d266731c87acaafa9 Mon Sep 17 00:00:00 2001 From: Michael Schmatz Date: Fri, 16 May 2014 13:16:35 -0700 Subject: [PATCH] Live simulation count and fixed double simulator leaderboard session --- app/templates/play/ladder/simulate_tab.jade | 5 ++++- app/views/play/ladder/simulate_tab.coffee | 12 +++++++++++- app/views/play/ladder_view.coffee | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/templates/play/ladder/simulate_tab.jade b/app/templates/play/ladder/simulate_tab.jade index e590c8c4c..fe266c6d9 100644 --- a/app/templates/play/ladder/simulate_tab.jade +++ b/app/templates/play/ladder/simulate_tab.jade @@ -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 diff --git a/app/views/play/ladder/simulate_tab.coffee b/app/views/play/ladder/simulate_tab.coffee index cb7d7dac0..58e559f6d 100644 --- a/app/views/play/ladder/simulate_tab.coffee +++ b/app/views/play/ladder/simulate_tab.coffee @@ -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 diff --git a/app/views/play/ladder_view.coffee b/app/views/play/ladder_view.coffee index 2a65d44c2..26038ea81 100644 --- a/app/views/play/ladder_view.coffee +++ b/app/views/play/ladder_view.coffee @@ -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