From d3b6836a06386c882890d4b266ea1734f45ec61b Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Mon, 3 Mar 2014 09:20:14 -0800 Subject: [PATCH] Fixed some bugs with the new ladder view when you haven't played before. --- app/templates/play/ladder/my_matches_tab.jade | 65 ++++++++++--------- app/views/play/ladder/my_matches_tab.coffee | 8 +-- app/views/play/ladder/play_modal.coffee | 5 +- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/app/templates/play/ladder/my_matches_tab.jade b/app/templates/play/ladder/my_matches_tab.jade index b9af08530..310beca34 100644 --- a/app/templates/play/ladder/my_matches_tab.jade +++ b/app/templates/play/ladder/my_matches_tab.jade @@ -7,17 +7,17 @@ div#columns.row for team in teams div.matches-column.col-md-6 - if team.matches.length - table.table.table-bordered.table-condensed + table.table.table-bordered.table-condensed - tr - th(colspan=4, style="color: #{team.primaryColor}") - span Your - span - span= team.name - span - span Matches + tr + th(colspan=4, style="color: #{team.primaryColor}") + span Your + span + span= team.name + span + span Matches + if team.session 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.rank.hidden Rank My Game! @@ -25,28 +25,29 @@ div#columns.row span.ranked.hidden Submitted for Ranking span.failed.hidden Failed to Rank + tr + th Result + th Opponent + th When + th + for match in team.matches tr - th Result - th Opponent - th When - th - for match in team.matches - tr - td.state-cell - if match.state === 'win' - span.win Win - if match.state === 'loss' - span.loss Loss - if match.state === 'tie' - span.tie Tie - td.name-cell= match.opponentName || "Anonymous" - td.time-cell= match.when - td.battle-cell - - var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + team.otherTeam - a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{match.sessionID}")= text - - else - div.alert.alert-warning - | No ranked matches played yet! - | Play some competitors on the right and then come back to get your game ranked. + td.state-cell + if match.state === 'win' + span.win Win + if match.state === 'loss' + span.loss Loss + if match.state === 'tie' + span.tie Tie + td.name-cell= match.opponentName || "Anonymous" + td.time-cell= match.when + td.battle-cell + - var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + team.otherTeam + a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{match.sessionID}")= text + + if !team.matches.length + tr + td(colspan=4).alert.alert-warning + | No ranked matches for this team! + | Play against some competitors and then come back here to get your game ranked. diff --git a/app/views/play/ladder/my_matches_tab.coffee b/app/views/play/ladder/my_matches_tab.coffee index 110a289db..f4994d519 100644 --- a/app/views/play/ladder/my_matches_tab.coffee +++ b/app/views/play/ladder/my_matches_tab.coffee @@ -62,9 +62,9 @@ module.exports = class MyMatchesTabView extends CocoView for team in @teams team.session = (s for s in @sessions.models when s.get('team') is team.id)[0] 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.score = (team.session.get('totalScore') or 10).toFixed(2) + team.score = (team.session?.get('totalScore') or 10).toFixed(2) ctx @@ -77,8 +77,8 @@ module.exports = class MyMatchesTabView extends CocoView @setRankingButtonText button, if @readyToRank(session) then 'rank' else 'unavailable' readyToRank: (session) -> - c1 = session.get('code') - c2 = session.get('submittedCode') + c1 = session?.get('code') + c2 = session?.get('submittedCode') c1 and not _.isEqual(c1, c2) rankSession: (e) -> diff --git a/app/views/play/ladder/play_modal.coffee b/app/views/play/ladder/play_modal.coffee index 560397d37..1a31618ad 100644 --- a/app/views/play/ladder/play_modal.coffee +++ b/app/views/play/ladder/play_modal.coffee @@ -2,6 +2,7 @@ View = require 'views/kinds/ModalView' template = require 'templates/play/ladder/play_modal' ThangType = require 'models/ThangType' {me} = require 'lib/auth' +LeaderboardCollection = require 'collections/LeaderboardCollection' module.exports = class LadderPlayModal extends View 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 startLoadingChallengersMaybe: -> - matches = @session.get('matches') + matches = @session?.get('matches') if matches?.length then @loadNames() else @loadChallengers() loadChallengers: -> @@ -126,8 +127,10 @@ class ChallengersData @hardPlayer = new LeaderboardCollection(@level, {order:-1, scoreOffset: score + 5, limit: 1, team: @otherTeam}) @hardPlayer.fetch() @hardPlayer.once 'sync', @challengerLoaded, @ + console.log 'fetching challengers yes' challengerLoaded: -> + console.log 'challenger loaded' if @allLoaded() @loaded = true @trigger 'sync'