mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Fixed #1111.
This commit is contained in:
parent
d00c4c2af3
commit
f0cdf6b2e2
3 changed files with 32 additions and 5 deletions
|
@ -36,10 +36,10 @@ module.exports = class LadderTabView extends CocoView
|
|||
|
||||
constructor: (options, @level, @sessions) ->
|
||||
super(options)
|
||||
@socialNetworkRes = @supermodel.addSomethingResource("social_network_apis", 0)
|
||||
@teams = teamDataFromLevel @level
|
||||
@leaderboards = {}
|
||||
@refreshLadder()
|
||||
@socialNetworkRes = @supermodel.addSomethingResource("social_network_apis", 0)
|
||||
@checkFriends()
|
||||
|
||||
checkFriends: ->
|
||||
|
@ -159,7 +159,7 @@ module.exports = class LadderTabView extends CocoView
|
|||
oldLeaderboard.destroy()
|
||||
teamSession = _.find @sessions.models, (session) -> session.get('team') is team.id
|
||||
@leaderboards[team.id] = new LeaderboardData(@level, team.id, teamSession, @ladderLimit)
|
||||
@leaderboardRes = @supermodel.addModelResource(@leaderboards[team.id], 'leaderboard', 3)
|
||||
@leaderboardRes = @supermodel.addModelResource(@leaderboards[team.id], 'leaderboard', {}, 3)
|
||||
@leaderboardRes.load()
|
||||
|
||||
render: ->
|
||||
|
@ -286,16 +286,16 @@ module.exports = class LadderTabView extends CocoView
|
|||
@ladderLimit += 100
|
||||
@refreshLadder()
|
||||
|
||||
class LeaderboardData extends CocoClass
|
||||
module.exports.LeaderboardData = LeaderboardData = class LeaderboardData extends CocoClass
|
||||
###
|
||||
Consolidates what you need to load for a leaderboard into a single Backbone Model-like object.
|
||||
###
|
||||
|
||||
constructor: (@level, @team, @session, @limit) ->
|
||||
super()
|
||||
@fetch()
|
||||
|
||||
fetch: ->
|
||||
console.warn 'Already have top players on', @ if @topPlayers
|
||||
@topPlayers = new LeaderboardCollection(@level, {order:-1, scoreOffset: HIGHEST_SCORE, team: @team, limit: @limit})
|
||||
promises = []
|
||||
promises.push @topPlayers.fetch()
|
||||
|
@ -315,8 +315,9 @@ class LeaderboardData extends CocoClass
|
|||
@promise
|
||||
|
||||
onLoad: =>
|
||||
return if @destroyed
|
||||
return if @destroyed or not @topPlayers.loaded
|
||||
@loaded = true
|
||||
@loading = false
|
||||
@trigger 'sync', @
|
||||
# TODO: cache user ids -> names mapping, and load them here as needed,
|
||||
# and apply them to sessions. Fetching each and every time is too costly.
|
||||
|
|
8
test/app/fixtures/levels.coffee
Normal file
8
test/app/fixtures/levels.coffee
Normal file
|
@ -0,0 +1,8 @@
|
|||
module.exports.LadderLevel =
|
||||
name: 'Ladder Level'
|
||||
original: '0123456789abcdef'
|
||||
version:
|
||||
major: 1
|
||||
minor: 2
|
||||
isLatestMajor: true
|
||||
isLatestMinor: true
|
18
test/app/views/play/ladder/ladder_tab.spec.coffee
Normal file
18
test/app/views/play/ladder/ladder_tab.spec.coffee
Normal file
|
@ -0,0 +1,18 @@
|
|||
LadderTabView = require 'views/play/ladder/ladder_tab'
|
||||
Level = require 'models/Level'
|
||||
fixtures = require 'test/app/fixtures/levels'
|
||||
|
||||
describe 'LeaderboardData', ->
|
||||
it 'triggers "sync" when its request is finished', ->
|
||||
level = new Level(fixtures.LadderLevel)
|
||||
leaderboard = new LadderTabView.LeaderboardData(level, 'humans', null, 4)
|
||||
leaderboard.fetch()
|
||||
|
||||
# no session passed in, so only one request
|
||||
expect(jasmine.Ajax.requests.count()).toBe(1)
|
||||
|
||||
request = jasmine.Ajax.requests.mostRecent()
|
||||
triggered = false
|
||||
leaderboard.once 'sync', -> triggered = true
|
||||
request.response({status: 200, responseText: '{}'})
|
||||
expect(triggered).toBe(true)
|
Loading…
Reference in a new issue