mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-27 14:33:59 -04:00
Set up the my matches tab in the new ladder view.
This commit is contained in:
parent
d0f416f668
commit
956e2b3c40
7 changed files with 46 additions and 49 deletions
app
templates/play
views/play
server/levels
|
@ -39,7 +39,7 @@ block content
|
|||
.tab-pane.active.well#ladder
|
||||
#ladder-tab-view
|
||||
.tab-pane.well#my-matches
|
||||
| My Matches Pane
|
||||
#my-matches-tab-view
|
||||
.tab-pane.well#simulate
|
||||
p(id="simulation-status-text")
|
||||
if simulationStatus
|
||||
|
|
|
@ -4,26 +4,33 @@
|
|||
// span
|
||||
// strong= score
|
||||
|
||||
h3.pull-left Ranked Games
|
||||
div#columns.row
|
||||
for team in teams
|
||||
div#matches-column.col-md-6
|
||||
button.btn.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!
|
||||
span.ranking.hidden Submitting...
|
||||
span.ranked.hidden Submitted for Ranking
|
||||
span.failed.hidden Failed to Rank
|
||||
|
||||
hr.clearfix(style="clear: both")
|
||||
|
||||
if matches.length
|
||||
div.matches-column.col-md-6
|
||||
if team.matches.length
|
||||
table.table.table-bordered.table-condensed
|
||||
|
||||
tr
|
||||
th(colspan=4, style="color: #{team.primaryColor}")
|
||||
span Your
|
||||
span
|
||||
span= team.name
|
||||
span
|
||||
span Matches
|
||||
|
||||
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!
|
||||
span.ranking.hidden Submitting...
|
||||
span.ranked.hidden Submitted for Ranking
|
||||
span.failed.hidden Failed to Rank
|
||||
|
||||
tr
|
||||
th Result
|
||||
th Opponent
|
||||
th When
|
||||
for match in matches
|
||||
th
|
||||
for match in team.matches
|
||||
tr
|
||||
td.state-cell
|
||||
if match.state === 'win'
|
||||
|
@ -35,7 +42,7 @@ div#columns.row
|
|||
td.name-cell= match.opponentName || "Anonymous"
|
||||
td.time-cell= match.when
|
||||
td.battle-cell
|
||||
- var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + otherTeamID
|
||||
- var text = match.state === 'win' ? 'Watch your victory' : 'Defeat the ' + team.otherTeam
|
||||
a(href="/play/level/#{levelID}?team=#{teamID}&opponent=#{match.sessionID}")= text
|
||||
|
||||
else
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = class LadderView extends CocoView
|
|||
for team in @teams
|
||||
# teamSession = _.find @sessions.models, (session) -> session.get('team') is team.id
|
||||
teamSession = null
|
||||
console.log "Team session: #{JSON.stringify teamSession}"
|
||||
# console.log "Team session: #{JSON.stringify teamSession}"
|
||||
@leaderboards[team.id] = new LeaderboardData(@level, team.id, teamSession)
|
||||
@leaderboards[team.id].once 'sync', @onLeaderboardLoaded, @
|
||||
|
||||
|
|
|
@ -4,17 +4,18 @@ LevelSession = require 'models/LevelSession'
|
|||
LeaderboardCollection = require 'collections/LeaderboardCollection'
|
||||
{teamDataFromLevel} = require './utils'
|
||||
|
||||
module.exports = class LadderTeamView extends CocoView
|
||||
id: 'ladder-team-view'
|
||||
template: require 'templates/play/ladder/team'
|
||||
module.exports = class MyMatchesTabView extends CocoView
|
||||
id: 'my-matches-tab-view'
|
||||
template: require 'templates/play/ladder/my_matches_tab'
|
||||
startsLoading: true
|
||||
|
||||
events:
|
||||
'click #rank-button': 'rankSession'
|
||||
'click .rank-button': 'rankSession'
|
||||
|
||||
constructor: (options, @level, @sessions) ->
|
||||
super(options)
|
||||
@teams = teamDataFromLevel @level
|
||||
@nameMap = {}
|
||||
@loadNames()
|
||||
|
||||
loadNames: ->
|
||||
|
@ -23,9 +24,10 @@ module.exports = class LadderTeamView extends CocoView
|
|||
ids.push match.opponents[0].userID for match in session.get('matches') or []
|
||||
|
||||
success = (@nameMap) =>
|
||||
for match in @session.get('matches') or []
|
||||
opponent = match.opponents[0]
|
||||
opponent.userName = @nameMap[opponent.userID]
|
||||
for session in @sessions.models
|
||||
for match in session.get('matches') or []
|
||||
opponent = match.opponents[0]
|
||||
opponent.userName = @nameMap[opponent.userID]
|
||||
@finishRendering()
|
||||
|
||||
$.ajax('/db/user/-/names', {
|
||||
|
@ -69,9 +71,10 @@ module.exports = class LadderTeamView extends CocoView
|
|||
afterRender: ->
|
||||
super()
|
||||
@$el.find('.rank-button').each (i, el) =>
|
||||
button = $(el)
|
||||
sessionID = button.data('session-id')
|
||||
session = _.find @sessions.models, { id: sessionID }
|
||||
@setRankingButtonText $(el), if @readyToRank(session) then 'rank' else 'unavailable'
|
||||
@setRankingButtonText button, if @readyToRank(session) then 'rank' else 'unavailable'
|
||||
|
||||
readyToRank: (session) ->
|
||||
c1 = session.get('code')
|
||||
|
|
|
@ -19,5 +19,4 @@ module.exports.teamDataFromLevel = (level) ->
|
|||
primaryColor: primaryColor
|
||||
})
|
||||
|
||||
console.log 'created teams', teams
|
||||
teams
|
|
@ -6,6 +6,7 @@ CocoCollection = require 'models/CocoCollection'
|
|||
LeaderboardCollection = require 'collections/LeaderboardCollection'
|
||||
{teamDataFromLevel} = require './ladder/utils'
|
||||
LadderTabView = require './ladder/ladder_tab'
|
||||
MyMatchesTabView = require './ladder/my_matches_tab'
|
||||
|
||||
HIGHEST_SCORE = 1000000
|
||||
|
||||
|
@ -15,7 +16,7 @@ class LevelSessionsCollection extends CocoCollection
|
|||
|
||||
constructor: (levelID) ->
|
||||
super()
|
||||
@url = "/db/level/#{levelID}/all_sessions"
|
||||
@url = "/db/level/#{levelID}/my_sessions"
|
||||
|
||||
module.exports = class LadderView extends RootView
|
||||
id: 'ladder-view'
|
||||
|
@ -31,9 +32,9 @@ module.exports = class LadderView extends RootView
|
|||
@level = new Level(_id:@levelID)
|
||||
@level.fetch()
|
||||
@level.once 'sync', @onLevelLoaded, @
|
||||
# @sessions = new LevelSessionsCollection(levelID)
|
||||
# @sessions.fetch({})
|
||||
# @sessions.once 'sync', @onMySessionsLoaded, @
|
||||
@sessions = new LevelSessionsCollection(levelID)
|
||||
@sessions.fetch({})
|
||||
@sessions.once 'sync', @onMySessionsLoaded, @
|
||||
@simulator = new Simulator()
|
||||
@simulator.on 'statusUpdate', @updateSimulationStatus, @
|
||||
@teams = []
|
||||
|
@ -42,9 +43,8 @@ module.exports = class LadderView extends RootView
|
|||
onMySessionsLoaded: -> @renderMaybe()
|
||||
|
||||
renderMaybe: ->
|
||||
return unless @level.loaded # and @sessions.loaded
|
||||
return unless @level.loaded and @sessions.loaded
|
||||
@teams = teamDataFromLevel @level
|
||||
console.log 'made teams', @teams
|
||||
@startsLoading = false
|
||||
@render()
|
||||
|
||||
|
@ -54,15 +54,14 @@ module.exports = class LadderView extends RootView
|
|||
ctx.link = "/play/level/#{@level.get('name')}"
|
||||
ctx.simulationStatus = @simulationStatus
|
||||
ctx.teams = @teams
|
||||
console.log 'ctx teams', ctx.teams
|
||||
ctx.levelID = @levelID
|
||||
ctx
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
return if @startsLoading
|
||||
@ladderTab = new LadderTabView({}, @level, @sessions)
|
||||
@insertSubView(@ladderTab)
|
||||
@insertSubView(@ladderTab = new LadderTabView({}, @level, @sessions))
|
||||
@insertSubView(@myMatchesTab = new MyMatchesTabView({}, @level, @sessions))
|
||||
|
||||
# Simulations
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ LevelHandler = class LevelHandler extends Handler
|
|||
getByRelationship: (req, res, args...) ->
|
||||
return @getSession(req, res, args[0]) if args[1] is 'session'
|
||||
return @getLeaderboard(req, res, args[0]) if args[1] is 'leaderboard'
|
||||
return @getAllSessions(req, res, args[0]) if args[1] is 'all_sessions'
|
||||
return @getMySessions(req, res, args[0]) if args[1] is 'my_sessions'
|
||||
return @getFeedback(req, res, args[0]) if args[1] is 'feedback'
|
||||
return @sendNotFoundError(res)
|
||||
|
||||
|
@ -86,26 +86,15 @@ LevelHandler = class LevelHandler extends Handler
|
|||
# associated with the handler, because the handler might return a different type
|
||||
# of model, like in this case. Refactor to move that logic to the model instead.
|
||||
|
||||
getAllSessions: (req, res, id) ->
|
||||
getMySessions: (req, res, id) ->
|
||||
@fetchLevelByIDAndHandleErrors id, req, res, (err, level) =>
|
||||
sessionQuery =
|
||||
level:
|
||||
original: level.original.toString()
|
||||
majorVersion: level.version.major
|
||||
submitted: true
|
||||
|
||||
propertiesToReturn = [
|
||||
'_id'
|
||||
'totalScore'
|
||||
'submitted'
|
||||
'team'
|
||||
'creatorName'
|
||||
]
|
||||
|
||||
query = Session
|
||||
.find(sessionQuery)
|
||||
.select(propertiesToReturn.join ' ')
|
||||
creator: req.user._id+''
|
||||
|
||||
query = Session.find(sessionQuery)
|
||||
query.exec (err, results) =>
|
||||
if err then @sendDatabaseError(res, err) else @sendSuccess res, results
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue