()
| 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 } |
no test coverage detected