A few fixes and cleanup for #831.
This commit is contained in:
parent
3d945492b0
commit
af0b8aa5e2
4 changed files with 31 additions and 22 deletions
app
server/users
|
@ -392,6 +392,7 @@
|
||||||
easy: "Easy"
|
easy: "Easy"
|
||||||
medium: "Medium"
|
medium: "Medium"
|
||||||
hard: "Hard"
|
hard: "Hard"
|
||||||
|
player: "Player"
|
||||||
|
|
||||||
about:
|
about:
|
||||||
who_is_codecombat: "Who is CodeCombat?"
|
who_is_codecombat: "Who is CodeCombat?"
|
||||||
|
@ -596,6 +597,9 @@
|
||||||
simulate_all: "RESET AND SIMULATE GAMES"
|
simulate_all: "RESET AND SIMULATE GAMES"
|
||||||
games_simulated_by: "Games simulated by you:"
|
games_simulated_by: "Games simulated by you:"
|
||||||
games_simulated_for: "Games simulated for you:"
|
games_simulated_for: "Games simulated for you:"
|
||||||
|
games_simulated: "Games simulated"
|
||||||
|
games_played: "Games played"
|
||||||
|
ratio: "Ratio"
|
||||||
leaderboard: "Leaderboard"
|
leaderboard: "Leaderboard"
|
||||||
battle_as: "Battle as "
|
battle_as: "Battle as "
|
||||||
summary_your: "Your "
|
summary_your: "Your "
|
||||||
|
|
|
@ -61,10 +61,10 @@ block content
|
||||||
|
|
||||||
table.table.table-bordered.table-condensed.table-hover
|
table.table.table-bordered.table-condensed.table-hover
|
||||||
tr
|
tr
|
||||||
th(data-i18n="general.name").name-col-cell Name
|
th(data-i18n="general.player").name-col-cell Player
|
||||||
th(data-i18n="general.gamessimulated") Games simulated
|
th(data-i18n="ladder.games_simulated") Games simulated
|
||||||
th(data-i18n="general.gamesplayed") Games played
|
th(data-i18n="ladder.games_played") Games played
|
||||||
th(data-i18n="general.ratio") Ratio
|
th(data-i18n="ladder.ratio") Ratio
|
||||||
- var topSimulators = simulatorsLeaderboardData.topSimulators.models;
|
- var topSimulators = simulatorsLeaderboardData.topSimulators.models;
|
||||||
- var showJustTop = simulatorsLeaderboardData.inTopSimulators() || me.get('anonymous');
|
- var showJustTop = simulatorsLeaderboardData.inTopSimulators() || me.get('anonymous');
|
||||||
- if(!showJustTop) topSimulators = topSimulators.slice(0, 10);
|
- if(!showJustTop) topSimulators = topSimulators.slice(0, 10);
|
||||||
|
@ -81,8 +81,9 @@ block content
|
||||||
td(colspan=4).ellipsis-row ...
|
td(colspan=4).ellipsis-row ...
|
||||||
for user in simulatorsLeaderboardData.nearbySimulators()
|
for user in simulatorsLeaderboardData.nearbySimulators()
|
||||||
- var myRow = user.id == me.id
|
- var myRow = user.id == me.id
|
||||||
|
- var ratio = user.get('simulatedBy') / user.get('simulatedFor');
|
||||||
tr(class=myRow ? "success" : "")
|
tr(class=myRow ? "success" : "")
|
||||||
td.name-col-cell= user.get('name') || "Anonymous"
|
td.name-col-cell= user.get('name') || "Anonymous"
|
||||||
td.simulator-leaderboard-cell= user.get('simulatedBy')
|
td.simulator-leaderboard-cell= user.get('simulatedBy')
|
||||||
td.simulator-leaderboard-cell= user.get('simulatedFor')
|
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)
|
|
@ -64,6 +64,7 @@ module.exports = class LadderView extends RootView
|
||||||
ctx.levelID = @levelID
|
ctx.levelID = @levelID
|
||||||
ctx.levelDescription = marked(@level.get('description')) if @level.get('description')
|
ctx.levelDescription = marked(@level.get('description')) if @level.get('description')
|
||||||
ctx.simulatorsLeaderboardData = @simulatorsLeaderboardData
|
ctx.simulatorsLeaderboardData = @simulatorsLeaderboardData
|
||||||
|
ctx._ = _
|
||||||
ctx
|
ctx
|
||||||
|
|
||||||
afterRender: ->
|
afterRender: ->
|
||||||
|
@ -127,17 +128,17 @@ module.exports = class LadderView extends RootView
|
||||||
|
|
||||||
onClickPlayButton: (e) ->
|
onClickPlayButton: (e) ->
|
||||||
@showPlayModal($(e.target).closest('.play-button').data('team'))
|
@showPlayModal($(e.target).closest('.play-button').data('team'))
|
||||||
|
|
||||||
resimulateAllSessions: ->
|
resimulateAllSessions: ->
|
||||||
postData =
|
postData =
|
||||||
originalLevelID: @level.get('original')
|
originalLevelID: @level.get('original')
|
||||||
levelMajorVersion: @level.get('version').major
|
levelMajorVersion: @level.get('version').major
|
||||||
console.log postData
|
console.log postData
|
||||||
|
|
||||||
$.ajax
|
$.ajax
|
||||||
url: '/queue/scoring/resimulateAllSessions'
|
url: '/queue/scoring/resimulateAllSessions'
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
data: postData
|
data: postData
|
||||||
complete: (jqxhr) ->
|
complete: (jqxhr) ->
|
||||||
console.log jqxhr.responseText
|
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.
|
Consolidates what you need to load for a leaderboard into a single Backbone Model-like object.
|
||||||
###
|
###
|
||||||
|
|
||||||
constructor: (@me) ->
|
constructor: (@me) ->
|
||||||
super()
|
super()
|
||||||
@fetch()
|
@fetch()
|
||||||
|
|
||||||
fetch: ->
|
fetch: ->
|
||||||
@topSimulators = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: -1, limit: 20})
|
@topSimulators = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: -1, limit: 20})
|
||||||
promises = []
|
promises = []
|
||||||
promises.push @topSimulators.fetch()
|
promises.push @topSimulators.fetch()
|
||||||
if !@me.get('anonymous')
|
unless @me.get('anonymous')
|
||||||
score = @me.get('simulatedBy') or 10
|
score = @me.get('simulatedBy') or 0
|
||||||
@playersAbove = new SimulatorsLeaderboardCollection({order:1, scoreOffset: score, limit: 4})
|
@playersAbove = new SimulatorsLeaderboardCollection({order:1, scoreOffset: score, limit: 4})
|
||||||
promises.push @playersAbove.fetch()
|
promises.push @playersAbove.fetch()
|
||||||
@playersBelow = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: score, limit: 4})
|
if score
|
||||||
promises.push @playersBelow.fetch()
|
@playersBelow = new SimulatorsLeaderboardCollection({order:-1, scoreOffset: score, limit: 4})
|
||||||
|
promises.push @playersBelow.fetch()
|
||||||
@promise = $.when(promises...)
|
@promise = $.when(promises...)
|
||||||
@promise.then @onLoad
|
@promise.then @onLoad
|
||||||
@promise.fail @onFail
|
@promise.fail @onFail
|
||||||
|
@ -191,7 +193,7 @@ class SimulatorsLeaderboardData extends CocoClass
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
@loaded = true
|
@loaded = true
|
||||||
@trigger 'sync', @
|
@trigger 'sync', @
|
||||||
|
|
||||||
onFail: (resource, jqxhr) =>
|
onFail: (resource, jqxhr) =>
|
||||||
return if @destroyed
|
return if @destroyed
|
||||||
@trigger 'error', @, jqxhr
|
@trigger 'error', @, jqxhr
|
||||||
|
@ -206,7 +208,7 @@ class SimulatorsLeaderboardData extends CocoClass
|
||||||
above.reverse()
|
above.reverse()
|
||||||
l = l.concat(above)
|
l = l.concat(above)
|
||||||
l.push @me
|
l.push @me
|
||||||
l = l.concat(@playersBelow.models)
|
l = l.concat(@playersBelow.models) if @playersBelow
|
||||||
###
|
###
|
||||||
if @myRank
|
if @myRank
|
||||||
startRank = @myRank - 4
|
startRank = @myRank - 4
|
||||||
|
|
|
@ -157,16 +157,18 @@ UserHandler = class UserHandler extends Handler
|
||||||
getSimulatorLeaderboard: (req, res) ->
|
getSimulatorLeaderboard: (req, res) ->
|
||||||
@validateSimulateLeaderboardRequestParameters(req)
|
@validateSimulateLeaderboardRequestParameters(req)
|
||||||
query = {}
|
query = {}
|
||||||
if(req.query.scoreOffset != -1)
|
sort = '-simulatedBy'
|
||||||
|
if req.query.scoreOffset isnt -1
|
||||||
simulatedByQuery = {}
|
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.simulatedBy = simulatedByQuery
|
||||||
query.simulatedFor = {"$gt": 0}
|
sort = 'simulatedBy' if req.query.order is 1
|
||||||
User
|
User
|
||||||
.find(query)
|
.find(query)
|
||||||
.limit(req.query.limit)
|
.limit(req.query.limit)
|
||||||
.sort('-simulatedBy').select('name simulatedBy simulatedFor').exec (err, otherUser) ->
|
.sort(sort).select('name simulatedBy simulatedFor').exec (err, otherUsers) ->
|
||||||
res.send(otherUser)
|
otherUsers = _.reject otherUsers, _id: req.user._id if req.query.scoreOffset isnt -1
|
||||||
|
res.send(otherUsers)
|
||||||
res.end()
|
res.end()
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue