A few fixes and cleanup for .

This commit is contained in:
Nick Winter 2014-04-13 15:28:16 -07:00
parent 3d945492b0
commit af0b8aa5e2
4 changed files with 31 additions and 22 deletions
app
locale
templates/play
views/play
server/users

View file

@ -392,6 +392,7 @@
easy: "Easy"
medium: "Medium"
hard: "Hard"
player: "Player"
about:
who_is_codecombat: "Who is CodeCombat?"
@ -596,6 +597,9 @@
simulate_all: "RESET AND SIMULATE GAMES"
games_simulated_by: "Games simulated by you:"
games_simulated_for: "Games simulated for you:"
games_simulated: "Games simulated"
games_played: "Games played"
ratio: "Ratio"
leaderboard: "Leaderboard"
battle_as: "Battle as "
summary_your: "Your "

View file

@ -61,10 +61,10 @@ block content
table.table.table-bordered.table-condensed.table-hover
tr
th(data-i18n="general.name").name-col-cell Name
th(data-i18n="general.gamessimulated") Games simulated
th(data-i18n="general.gamesplayed") Games played
th(data-i18n="general.ratio") Ratio
th(data-i18n="general.player").name-col-cell Player
th(data-i18n="ladder.games_simulated") Games simulated
th(data-i18n="ladder.games_played") Games played
th(data-i18n="ladder.ratio") Ratio
- var topSimulators = simulatorsLeaderboardData.topSimulators.models;
- var showJustTop = simulatorsLeaderboardData.inTopSimulators() || me.get('anonymous');
- if(!showJustTop) topSimulators = topSimulators.slice(0, 10);
@ -81,8 +81,9 @@ block content
td(colspan=4).ellipsis-row ...
for user in simulatorsLeaderboardData.nearbySimulators()
- var myRow = user.id == me.id
- var ratio = user.get('simulatedBy') / user.get('simulatedFor');
tr(class=myRow ? "success" : "")
td.name-col-cell= user.get('name') || "Anonymous"
td.simulator-leaderboard-cell= user.get('simulatedBy')
td.simulator-leaderboard-cell= user.get('simulatedFor')
td.simulator-leaderboard-cell= Math.round((user.get('simulatedBy') / user.get('simulatedFor')) * 10) / 10
td.simulator-leaderboard-cell= _.isNaN(ratio) || ratio == Infinity ? '' : ratio.toFixed(1)

View file

@ -64,6 +64,7 @@ module.exports = class LadderView extends RootView
ctx.levelID = @levelID
ctx.levelDescription = marked(@level.get('description')) if @level.get('description')
ctx.simulatorsLeaderboardData = @simulatorsLeaderboardData
ctx._ = _
ctx
afterRender: ->
@ -127,17 +128,17 @@ module.exports = class LadderView extends RootView
onClickPlayButton: (e) ->
@showPlayModal($(e.target).closest('.play-button').data('team'))
resimulateAllSessions: ->
postData =
originalLevelID: @level.get('original')
levelMajorVersion: @level.get('version').major
console.log postData
$.ajax
url: '/queue/scoring/resimulateAllSessions'
method: 'POST'
data: postData
data: postData
complete: (jqxhr) ->
console.log jqxhr.responseText
@ -167,21 +168,22 @@ class SimulatorsLeaderboardData extends CocoClass
###
Consolidates what you need to load for a leaderboard into a single Backbone Model-like object.
###
constructor: (@me) ->
super()
@fetch()
fetch: ->
@topSimulators = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: -1, limit: 20})
promises = []
promises.push @topSimulators.fetch()
if !@me.get('anonymous')
score = @me.get('simulatedBy') or 10
promises.push @topSimulators.fetch()
unless @me.get('anonymous')
score = @me.get('simulatedBy') or 0
@playersAbove = new SimulatorsLeaderboardCollection({order:1, scoreOffset: score, limit: 4})
promises.push @playersAbove.fetch()
@playersBelow = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: score, limit: 4})
promises.push @playersBelow.fetch()
if score
@playersBelow = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: score, limit: 4})
promises.push @playersBelow.fetch()
@promise = $.when(promises...)
@promise.then @onLoad
@promise.fail @onFail
@ -191,7 +193,7 @@ class SimulatorsLeaderboardData extends CocoClass
return if @destroyed
@loaded = true
@trigger 'sync', @
onFail: (resource, jqxhr) =>
return if @destroyed
@trigger 'error', @, jqxhr
@ -206,7 +208,7 @@ class SimulatorsLeaderboardData extends CocoClass
above.reverse()
l = l.concat(above)
l.push @me
l = l.concat(@playersBelow.models)
l = l.concat(@playersBelow.models) if @playersBelow
###
if @myRank
startRank = @myRank - 4

View file

@ -157,16 +157,18 @@ UserHandler = class UserHandler extends Handler
getSimulatorLeaderboard: (req, res) ->
@validateSimulateLeaderboardRequestParameters(req)
query = {}
if(req.query.scoreOffset != -1)
sort = '-simulatedBy'
if req.query.scoreOffset isnt -1
simulatedByQuery = {}
simulatedByQuery[if req.query.order is 1 then "$gt" else "$lt"] = req.query.scoreOffset
simulatedByQuery[if req.query.order is 1 then "$gt" else "$lte"] = req.query.scoreOffset
query.simulatedBy = simulatedByQuery
query.simulatedFor = {"$gt": 0}
sort = 'simulatedBy' if req.query.order is 1
User
.find(query)
.limit(req.query.limit)
.sort('-simulatedBy').select('name simulatedBy simulatedFor').exec (err, otherUser) ->
res.send(otherUser)
.sort(sort).select('name simulatedBy simulatedFor').exec (err, otherUsers) ->
otherUsers = _.reject otherUsers, _id: req.user._id if req.query.scoreOffset isnt -1
res.send(otherUsers)
res.end()