Fixed some bugs with the new ladder view when you haven't played before.

This commit is contained in:
Scott Erickson 2014-03-03 09:20:14 -08:00
parent 5bb56ac818
commit d3b6836a06
3 changed files with 41 additions and 37 deletions

View file

@ -7,7 +7,6 @@
div#columns.row div#columns.row
for team in teams for team in teams
div.matches-column.col-md-6 div.matches-column.col-md-6
if team.matches.length
table.table.table-bordered.table-condensed table.table.table-bordered.table-condensed
tr tr
@ -18,6 +17,7 @@ div#columns.row
span span
span Matches span Matches
if team.session
button.btn.btn-sm.btn-warning.pull-right.rank-button(data-session-id=team.session.id) button.btn.btn-sm.btn-warning.pull-right.rank-button(data-session-id=team.session.id)
span.unavailable.hidden No New Code to Rank span.unavailable.hidden No New Code to Rank
span.rank.hidden Rank My Game! span.rank.hidden Rank My Game!
@ -45,8 +45,9 @@ div#columns.row
- var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + team.otherTeam - var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + team.otherTeam
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{match.sessionID}")= text a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{match.sessionID}")= text
else if !team.matches.length
div.alert.alert-warning tr
| No ranked matches played yet! td(colspan=4).alert.alert-warning
| Play some competitors on the right and then come back to get your game ranked. | No ranked matches for this team!
| Play against some competitors and then come back here to get your game ranked.

View file

@ -62,9 +62,9 @@ module.exports = class MyMatchesTabView extends CocoView
for team in @teams for team in @teams
team.session = (s for s in @sessions.models when s.get('team') is team.id)[0] team.session = (s for s in @sessions.models when s.get('team') is team.id)[0]
team.readyToRank = @readyToRank(team.session) team.readyToRank = @readyToRank(team.session)
team.matches = (convertMatch(match) for match in team.session.get('matches') or []) team.matches = (convertMatch(match) for match in team.session?.get('matches') or [])
team.matches.reverse() team.matches.reverse()
team.score = (team.session.get('totalScore') or 10).toFixed(2) team.score = (team.session?.get('totalScore') or 10).toFixed(2)
ctx ctx
@ -77,8 +77,8 @@ module.exports = class MyMatchesTabView extends CocoView
@setRankingButtonText button, if @readyToRank(session) then 'rank' else 'unavailable' @setRankingButtonText button, if @readyToRank(session) then 'rank' else 'unavailable'
readyToRank: (session) -> readyToRank: (session) ->
c1 = session.get('code') c1 = session?.get('code')
c2 = session.get('submittedCode') c2 = session?.get('submittedCode')
c1 and not _.isEqual(c1, c2) c1 and not _.isEqual(c1, c2)
rankSession: (e) -> rankSession: (e) ->

View file

@ -2,6 +2,7 @@ View = require 'views/kinds/ModalView'
template = require 'templates/play/ladder/play_modal' template = require 'templates/play/ladder/play_modal'
ThangType = require 'models/ThangType' ThangType = require 'models/ThangType'
{me} = require 'lib/auth' {me} = require 'lib/auth'
LeaderboardCollection = require 'collections/LeaderboardCollection'
module.exports = class LadderPlayModal extends View module.exports = class LadderPlayModal extends View
id: "ladder-play-modal" id: "ladder-play-modal"
@ -19,7 +20,7 @@ module.exports = class LadderPlayModal extends View
# PART 1: Load challengers from the db unless some are in the matches # PART 1: Load challengers from the db unless some are in the matches
startLoadingChallengersMaybe: -> startLoadingChallengersMaybe: ->
matches = @session.get('matches') matches = @session?.get('matches')
if matches?.length then @loadNames() else @loadChallengers() if matches?.length then @loadNames() else @loadChallengers()
loadChallengers: -> loadChallengers: ->
@ -126,8 +127,10 @@ class ChallengersData
@hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: @otherTeam}) @hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: @otherTeam})
@hardPlayer.fetch() @hardPlayer.fetch()
@hardPlayer.once 'sync', @challengerLoaded, @ @hardPlayer.once 'sync', @challengerLoaded, @
console.log 'fetching challengers yes'
challengerLoaded: -> challengerLoaded: ->
console.log 'challenger loaded'
if @allLoaded() if @allLoaded()
@loaded = true @loaded = true
@trigger 'sync' @trigger 'sync'