MCPcopy Create free account
hub / github.com/codecombat/codecombat / checkTournamentClose

Method checkTournamentClose

app/views/ladder/LadderView.js:248–286  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

246 }
247
248 checkTournamentClose () {
249 if (this.tournamentId == null) { return }
250 return $.ajax({
251 url: `/db/tournament/${this.tournamentId}/state`,
252 success: res => {
253 let newInterval
254 this.tournament = new Tournament(res)
255 this.tournamentDisplayName = this.tournament.get('displayName')
256 if (me.isAdmin() && (document.location.hash === '#results')) {
257 // Show the results early, before publish date
258 this.tournament.set('resultsDate', this.tournament.get('endDate'))
259 this.tournament.set('state', 'ended')
260 }
261 if (this.tournament.get('endDate')) {
262 if (this.tournamentTimeRefreshInterval) { clearInterval(this.tournamentTimeRefreshInterval) }
263 this.tournamentTimeRefreshInterval = setInterval(this.refreshTournamentTime.bind(this), 5000)
264 this.refreshTournamentTime()
265 }
266
267 this.tournamentEnd = true // hide play button
268 if (this.tournament.get('state') === 'initializing') {
269 newInterval = this.tournamentTimeElapsed < (-10 * 1000) ? Math.min(10 * 60 * 1000, -this.tournamentTimeElapsed / 2) : 5000
270 } else if (this.tournament.get('state') === 'starting') {
271 this.tournamentEnd = false
272 newInterval = this.tournamentTimeLeft > (10 * 1000) ? Math.min(10 * 60 * 1000, this.tournamentTimeLeft / 2) : 5000
273 } else if (['ranking', 'waiting'].includes(this.tournament.get('state'))) {
274 newInterval = this.tournamentResultsTimeLeft > (10 * 1000) ? Math.min(10 * 60 * 1000, this.tournamentResultsTimeLeft / 2) : 5000
275 }
276
277 if (this.tournamentState !== this.tournament.get('state')) {
278 this.tournamentState = this.tournament.get('state')
279 this.render()
280 }
281
282 if (this.checkTournamentCloseInterval) { clearInterval(this.checkTournamentCloseInterval) }
283 if (newInterval) { return this.checkTournamentCloseInterval = setInterval(this.checkTournamentClose.bind(this), newInterval) }
284 }
285 })
286 }
287
288 refreshTournamentTime () {
289 if (!(this.tournament != null ? this.tournament.get('endDate') : undefined)) { return }

Callers 2

constructorMethod · 0.95

Calls 5

refreshTournamentTimeMethod · 0.95
isAdminMethod · 0.80
getMethod · 0.45
setMethod · 0.45
renderMethod · 0.45

Tested by

no test coverage detected