@@ -30,7 +30,7 @@ var CMS = CMS || {};
3030CMS . AWSUtils = function ( url_root , timestamp ,
3131 contest_start , contest_stop ,
3232 analysis_start , analysis_stop ,
33- phase ) {
33+ analysis_enabled ) {
3434 this . url = CMS . AWSUtils . create_url_builder ( url_root ) ;
3535 this . first_date = new Date ( ) ;
3636 this . last_notification = timestamp ;
@@ -39,7 +39,7 @@ CMS.AWSUtils = function(url_root, timestamp,
3939 this . contest_stop = contest_stop ;
4040 this . analysis_start = analysis_start ;
4141 this . analysis_stop = analysis_stop ;
42- this . phase = phase ;
42+ this . analysis_enabled = analysis_enabled ;
4343 this . file_asked_name = "" ;
4444 this . file_asked_url = "" ;
4545
@@ -476,42 +476,35 @@ CMS.AWSUtils.prototype.two_digits = function(n) {
476476
477477/**
478478 * Update the remaining time showed in the "remaining" div.
479- *
480- * timer (int): handle for the timer that called this function, or -1 if none
481479 */
482- CMS . AWSUtils . prototype . update_remaining_time = function ( timer = - 1 ) {
483- // We assume this.phase always is the correct phase (since this
484- // method also refreshes the page when the phase changes).
480+ CMS . AWSUtils . prototype . update_remaining_time = function ( ) {
485481 var relevant_timestamp = null ;
486482 var text = null ;
487- if ( this . phase === - 1 ) {
483+ var now_timestamp = this . timestamp + ( new Date ( ) - this . first_date ) / 1000 ;
484+
485+ // based on the phase logic from cms/db/contest.py.
486+ if ( now_timestamp < this . contest_start ) {
488487 relevant_timestamp = this . contest_start ;
489488 text = "To start of contest: "
490- } else if ( this . phase === 0 ) {
489+ } else if ( now_timestamp <= this . contest_stop ) {
491490 relevant_timestamp = this . contest_stop ;
492491 text = "To end of contest: "
493- } else if ( this . phase === 1 ) {
492+ } else if ( this . analysis_enabled && now_timestamp < this . analysis_start ) {
494493 relevant_timestamp = this . analysis_start ;
495494 text = "To start of analysis: "
496- } else if ( this . phase === 2 ) {
495+ } else if ( this . analysis_enabled && now_timestamp <= this . analysis_stop ) {
497496 relevant_timestamp = this . analysis_stop ;
498497 text = "To end of analysis: "
499498 }
500499
501500 // We are in phase 3, nothing to show.
502501 if ( relevant_timestamp === null ) {
502+ $ ( "#remaining_text" ) . text ( "" ) ;
503+ $ ( "#remaining_value" ) . text ( "" ) ;
503504 return ;
504505 }
505506
506- // Compute actual seconds to next phase value, and if negative we
507- // refresh to update the phase.
508- var now = new Date ( ) ;
509- var countdown_sec =
510- relevant_timestamp - this . timestamp - ( now - this . first_date ) / 1000 ;
511- if ( countdown_sec <= 0 ) {
512- clearInterval ( timer ) ;
513- location . reload ( ) ;
514- }
507+ var countdown_sec = relevant_timestamp - now_timestamp ;
515508
516509 $ ( "#remaining_text" ) . text ( text ) ;
517510 $ ( "#remaining_value" ) . text ( this . format_countdown ( countdown_sec ) ) ;
0 commit comments