MCPcopy Index your code
hub / github.com/codecombat/codecombat / fetch

Method fetch

app/views/ladder/LadderTabView.js:488–556  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

486 }
487
488 fetch () {
489 if (this.topPlayers) { console.warn('Already have top players on', this) }
490
491 const params = this.collectionParameters({ order: -1, scoreOffset: HIGHEST_SCORE, limit: this.limit })
492 if (this.ageBracket != null) {
493 params.age = this.ageBracket
494 }
495 if (this.tournamentId != null) {
496 this.topPlayers = new TournamentLeaderboardCollection(this.tournamentId, params)
497 } else {
498 this.topPlayers = new LeaderboardCollection(this.level, params)
499 }
500 const promises = []
501 promises.push(this.topPlayers.fetch({ cache: false }))
502
503 if (this.session) {
504 let score
505 if (this.myTotalScore) {
506 score = this.myTotalScore
507 } else if (this.league) {
508 score = __guard__(_.find(this.session.get('leagues'), { leagueID: this.league.id }), x => x.stats.totalScore)
509 } else {
510 score = this.session.get('totalScore')
511 }
512 if (score) {
513 if (this.tournamentId != null) {
514 this.playersAbove = new TournamentLeaderboardCollection(this.tournamentId, this.collectionParameters({ order: 1, scoreOffset: score, limit: 4, winRate: this.myWinRate }))
515 promises.push(this.playersAbove.fetch({ cache: false }))
516 this.playersBelow = new TournamentLeaderboardCollection(this.tournamentId, this.collectionParameters({ order: -1, scoreOffset: score, limit: 4, winRate: this.myWinRate }))
517 promises.push(this.playersBelow.fetch({ cache: false }))
518 } else {
519 this.playersAbove = new LeaderboardCollection(this.level, this.collectionParameters({ order: 1, scoreOffset: score, limit: 4 }))
520 promises.push(this.playersAbove.fetch({ cache: false }))
521 this.playersBelow = new LeaderboardCollection(this.level, this.collectionParameters({ order: -1, scoreOffset: score, limit: 4 }))
522 promises.push(this.playersBelow.fetch({ cache: false }))
523 }
524 let success = myRank => {
525 this.myRank = myRank
526 }
527 let loadURL = `/db/level/${this.level.get('original')}/rankings/${this.session.id}?scoreOffset=${score}&team=${this.team}&levelSlug=${this.level.get('slug')}`
528 if (this.league) { loadURL += '&leagues.leagueID=' + this.league.id }
529 if (this.tournamentId != null) {
530 success = ({ rank, wins, losses, totalScore }) => {
531 this.myRank = rank
532 this.myWins = wins
533 this.myLosses = losses
534 this.myTotalScore = totalScore
535 return this.myWinRate = (this.myWins || 0) / Math.max((this.myWins || 0) + (this.myLosses || 0), 1)
536 }
537 loadURL = `/db/tournament/${this.tournamentId}/rankings/${this.session.id}?scoreOffset=${score}&team=${this.team}`
538 }
539 const loadPromise = $.ajax(loadURL, { cache: false, success })
540 const deferred = $.Deferred()
541 loadPromise.done(data => deferred.resolve(data))
542 loadPromise.fail(jqxhr => {
543 if (jqxhr.status === 404) {
544 return deferred.resolve('ignored')
545 } else {

Callers 15

constructorMethod · 0.45
constructorMethod · 0.45
initializeMethod · 0.45
fetchLevelSessionMethod · 0.45
initializeMethod · 0.45
loadStatsMethod · 0.45
constructorMethod · 0.45
constructorMethod · 0.45
constructorMethod · 0.45
onCollectionSyncedMethod · 0.45
constructorMethod · 0.45
onSubscriptionSuccessMethod · 0.45

Calls 5

collectionParametersMethod · 0.95
doneMethod · 0.80
failMethod · 0.80
__guard__Function · 0.70
getMethod · 0.45

Tested by

no test coverage detected