Merge branch 'master' into production

This commit is contained in:
Nick Winter 2015-08-21 03:28:35 -07:00
commit 86b076fde0
4 changed files with 35 additions and 19 deletions

View file

@ -17,6 +17,9 @@
h1
text-align: center
&.league-header
margin: 15px 0 20px 0
.tournament-blurb
margin-top: -10px
margin-bottom: 10px

View file

@ -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

View file

@ -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)

View file

@ -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) ->