mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-24 11:50:58 -04:00
Merge pull request #3727 from duybkict/refactor-MyMatchesTabView
#3138 #3488 refactor MyMatchesTabView
This commit is contained in:
commit
57def1fbeb
2 changed files with 44 additions and 51 deletions
app
|
@ -1,5 +1,5 @@
|
|||
.row
|
||||
for team in teams
|
||||
for team in view.teams
|
||||
div.matches-column.col-md-6
|
||||
table.table.table-bordered.table-condensed.my-matches-table
|
||||
|
||||
|
@ -43,6 +43,8 @@
|
|||
td.name-cell= match.opponentName || "Anonymous"
|
||||
td.time-cell= match.when
|
||||
td.battle-cell
|
||||
- var levelID = view.level.get('slug') || view.level.id
|
||||
- var league = view.options.league
|
||||
a(href="/play/level/#{levelID}?team=#{team.id}&opponent=#{match.sessionID}" + (league ? "&league=" + league.id : ""))
|
||||
if (match.state === 'win')
|
||||
span(data-i18n="ladder.watch_victory") Watch your victory
|
||||
|
|
|
@ -10,14 +10,53 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
id: 'my-matches-tab-view'
|
||||
template: require 'templates/play/ladder/my_matches_tab'
|
||||
|
||||
constructor: (options, @level, @sessions) ->
|
||||
super(options)
|
||||
initialize: (options, @level, @sessions) ->
|
||||
@nameMap = {}
|
||||
@previouslyRankingTeams = {}
|
||||
@refreshMatches 20
|
||||
|
||||
refreshMatches: (@refreshDelay) ->
|
||||
@teams = teamDataFromLevel @level
|
||||
|
||||
convertMatch = (match, submitDate) =>
|
||||
opponent = match.opponents[0]
|
||||
state = 'win'
|
||||
state = 'loss' if match.metrics.rank > opponent.metrics.rank
|
||||
state = 'tie' if match.metrics.rank is opponent.metrics.rank
|
||||
fresh = match.date > (new Date(new Date() - @refreshDelay * 1000)).toISOString()
|
||||
if fresh
|
||||
@playSound 'chat_received'
|
||||
{
|
||||
state: state
|
||||
opponentName: @nameMap[opponent.userID]
|
||||
opponentID: opponent.userID
|
||||
when: moment(match.date).fromNow()
|
||||
sessionID: opponent.sessionID
|
||||
stale: match.date < submitDate
|
||||
fresh: fresh
|
||||
codeLanguage: match.codeLanguage
|
||||
simulator: if match.simulator then JSON.stringify(match.simulator) + ' | seed ' + match.randomSeed else ''
|
||||
}
|
||||
|
||||
for team in @teams
|
||||
team.session = (s for s in @sessions.models when s.get('team') is team.id)[0]
|
||||
stats = @statsFromSession team.session
|
||||
team.readyToRank = team.session?.readyToRank()
|
||||
team.isRanking = team.session?.get('isRanking')
|
||||
team.matches = (convertMatch(match, team.session.get('submitDate')) for match in (stats?.matches or []))
|
||||
team.matches.reverse()
|
||||
team.score = (stats?.totalScore ? 10).toFixed(2)
|
||||
team.wins = _.filter(team.matches, {state: 'win', stale: false}).length
|
||||
team.ties = _.filter(team.matches, {state: 'tie', stale: false}).length
|
||||
team.losses = _.filter(team.matches, {state: 'loss', stale: false}).length
|
||||
scoreHistory = stats?.scoreHistory
|
||||
if scoreHistory?.length > 1
|
||||
team.scoreHistory = scoreHistory
|
||||
|
||||
if not team.isRanking and @previouslyRankingTeams[team.id]
|
||||
@playSound 'cast-end'
|
||||
@previouslyRankingTeams[team.id] = team.isRanking
|
||||
|
||||
@loadNames()
|
||||
|
||||
loadNames: ->
|
||||
|
@ -62,54 +101,6 @@ module.exports = class MyMatchesTabView extends CocoView
|
|||
}, 0
|
||||
userNamesRequest.load()
|
||||
|
||||
getRenderData: ->
|
||||
ctx = super()
|
||||
ctx.level = @level
|
||||
ctx.levelID = @level.get('slug') or @level.id
|
||||
ctx.teams = @teams
|
||||
ctx.league = @options.league
|
||||
|
||||
convertMatch = (match, submitDate) =>
|
||||
opponent = match.opponents[0]
|
||||
state = 'win'
|
||||
state = 'loss' if match.metrics.rank > opponent.metrics.rank
|
||||
state = 'tie' if match.metrics.rank is opponent.metrics.rank
|
||||
fresh = match.date > (new Date(new Date() - @refreshDelay * 1000)).toISOString()
|
||||
if fresh
|
||||
@playSound 'chat_received'
|
||||
{
|
||||
state: state
|
||||
opponentName: @nameMap[opponent.userID]
|
||||
opponentID: opponent.userID
|
||||
when: moment(match.date).fromNow()
|
||||
sessionID: opponent.sessionID
|
||||
stale: match.date < submitDate
|
||||
fresh: fresh
|
||||
codeLanguage: match.codeLanguage
|
||||
simulator: if match.simulator then JSON.stringify(match.simulator) + ' | seed ' + match.randomSeed else ''
|
||||
}
|
||||
|
||||
for team in @teams
|
||||
team.session = (s for s in @sessions.models when s.get('team') is team.id)[0]
|
||||
stats = @statsFromSession team.session
|
||||
team.readyToRank = team.session?.readyToRank()
|
||||
team.isRanking = team.session?.get('isRanking')
|
||||
team.matches = (convertMatch(match, team.session.get('submitDate')) for match in (stats?.matches or []))
|
||||
team.matches.reverse()
|
||||
team.score = (stats?.totalScore ? 10).toFixed(2)
|
||||
team.wins = _.filter(team.matches, {state: 'win', stale: false}).length
|
||||
team.ties = _.filter(team.matches, {state: 'tie', stale: false}).length
|
||||
team.losses = _.filter(team.matches, {state: 'loss', stale: false}).length
|
||||
scoreHistory = stats?.scoreHistory
|
||||
if scoreHistory?.length > 1
|
||||
team.scoreHistory = scoreHistory
|
||||
|
||||
if not team.isRanking and @previouslyRankingTeams[team.id]
|
||||
@playSound 'cast-end'
|
||||
@previouslyRankingTeams[team.id] = team.isRanking
|
||||
|
||||
ctx
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
@removeSubView subview for key, subview of @subviews when subview instanceof LadderSubmissionView
|
||||
|
|
Loading…
Add table
Reference in a new issue