From 256b19d331d95629fd48c578fbbbc46b48da67cb Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Fri, 21 Aug 2015 03:28:25 -0700 Subject: [PATCH] More improvements and fixes for league ladder pages. --- app/styles/play/ladder/ladder.sass | 3 +++ app/templates/play/ladder/ladder.jade | 4 +-- app/views/ladder/LadderTabView.coffee | 38 ++++++++++++++++----------- server/levels/level_handler.coffee | 9 +++++-- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/app/styles/play/ladder/ladder.sass b/app/styles/play/ladder/ladder.sass index aa04a6afb..b134ec5c1 100644 --- a/app/styles/play/ladder/ladder.sass +++ b/app/styles/play/ladder/ladder.sass @@ -17,6 +17,9 @@ h1 text-align: center + &.league-header + margin: 15px 0 20px 0 + .tournament-blurb margin-top: -10px margin-bottom: 10px diff --git a/app/templates/play/ladder/ladder.jade b/app/templates/play/ladder/ladder.jade index dd085a269..2c800ced1 100644 --- a/app/templates/play/ladder/ladder.jade +++ b/app/templates/play/ladder/ladder.jade @@ -11,7 +11,7 @@ block content h1= level.get('name') if league - h1 + h1.league-header a(href="/#{leagueType == 'clan' ? 'clans' : leagueType}/#{league.id}")= league.get('name') span.spl(data-i18n="ladder.league") League @@ -75,7 +75,7 @@ block content a(href="http://discourse.codecombat.com/") the forum | and discuss your strategies, your triumphs, and your turmoils. - if level.get('name') == 'Zero Sum' + if level.get('name') == 'Zero Sum' && !league .tournament-blurb h2 span(data-i18n="ladder.tournament_ended") Tournament ended diff --git a/app/views/ladder/LadderTabView.coffee b/app/views/ladder/LadderTabView.coffee index d3859cb4c..63301fae5 100644 --- a/app/views/ladder/LadderTabView.coffee +++ b/app/views/ladder/LadderTabView.coffee @@ -252,10 +252,13 @@ module.exports = class LadderTabView extends CocoView message = "#{histogramData.length} players" if @leaderboards[teamName].session? - if @leaderboards[teamName].myRank <= histogramData.length - message="##{@leaderboards[teamName].myRank} of #{histogramData.length}" + if @options.league + # TODO: fix server handler to properly fetch myRank with a leagueID + message = "#{histogramData.length} players in league" + else if @leaderboards[teamName].myRank <= histogramData.length + message = "##{@leaderboards[teamName].myRank} of #{histogramData.length}" else - message='Rank your session!' + message = 'Rank your session!' svg.append('g') .append('text') .attr('class', rankClass) @@ -325,18 +328,19 @@ module.exports.LeaderboardData = LeaderboardData = class LeaderboardData extends if @session if @league - score = _.find(@session.get('leagues'), {leagueID: @league.id})?.stats.totalScore or 10 + score = _.find(@session.get('leagues'), {leagueID: @league.id})?.stats.totalScore else - score = @session.get('totalScore') or 10 - @playersAbove = new LeaderboardCollection(@level, @collectionParameters(order: 1, scoreOffset: score, limit: 4)) - promises.push @playersAbove.fetch cache: false - @playersBelow = new LeaderboardCollection(@level, @collectionParameters(order: -1, scoreOffset: score, limit: 4)) - promises.push @playersBelow.fetch cache: false - level = "#{@level.get('original')}.#{@level.get('version').major}" - success = (@myRank) => - loadURL = "/db/level/#{level}/leaderboard_rank?scoreOffset=#{score}&team=#{@team}" - loadURL += '&leagues.leagueID=' + @league.id if @league - promises.push $.ajax(loadURL, cache: false, success: success) + score = @session.get('totalScore') + if score + @playersAbove = new LeaderboardCollection(@level, @collectionParameters(order: 1, scoreOffset: score, limit: 4)) + promises.push @playersAbove.fetch cache: false + @playersBelow = new LeaderboardCollection(@level, @collectionParameters(order: -1, scoreOffset: score, limit: 4)) + promises.push @playersBelow.fetch cache: false + level = "#{@level.get('original')}.#{@level.get('version').major}" + success = (@myRank) => + loadURL = "/db/level/#{level}/leaderboard_rank?scoreOffset=#{score}&team=#{@team}" + loadURL += '&leagues.leagueID=' + @league.id if @league + promises.push $.ajax(loadURL, cache: false, success: success) @promise = $.when(promises...) @promise.then @onLoad @promise.fail @onFail @@ -358,7 +362,11 @@ module.exports.LeaderboardData = LeaderboardData = class LeaderboardData extends return me.id in (session.attributes.creator for session in @topPlayers.models) nearbySessions: -> - return [] unless @session?.get('totalScore') + if @league + score = _.find(@session?.get('leagues'), {leagueID: @league.id})?.stats.totalScore + else + score = @session?.get('totalScore') + return [] unless score l = [] above = @playersAbove.models l = l.concat(above) diff --git a/server/levels/level_handler.coffee b/server/levels/level_handler.coffee index f841cafb7..2ed106990 100644 --- a/server/levels/level_handler.coffee +++ b/server/levels/level_handler.coffee @@ -167,15 +167,20 @@ LevelHandler = class LevelHandler extends Handler getHistogramData: (req, res, slug) -> match = levelID: slug, submitted: true, team: req.query.team match['leagues.leagueID'] = league if league = req.query['leagues.leagueID'] + project = totalScore: 1, _id: 0 + project['leagues.leagueID'] = project['leagues.stats.totalScore'] = 1 if league aggregate = Session.aggregate [ {$match: match} - {$project: {totalScore: 1, _id: 0}} + {$project: project} ] aggregate.cache() unless league aggregate.exec (err, data) => if err? then return @sendDatabaseError res, err - valueArray = _.pluck data, 'totalScore' + if league + valueArray = _.pluck data, (session) -> _.find(session.leagues, leagueID: league)?.stats?.totalScore or 10 + else + valueArray = _.pluck data, 'totalScore' @sendSuccess res, valueArray checkExistence: (req, res, slugOrID) ->