diff --git a/cms/db/contest.py b/cms/db/contest.py index c245a3534f..13c84c263c 100644 --- a/cms/db/contest.py +++ b/cms/db/contest.py @@ -306,6 +306,7 @@ def phase(self, timestamp: datetime) -> int: timestamp: the time we are iterested in. """ + # NOTE: this logic is duplicated in aws_utils.js. if timestamp < self.start: return -1 if timestamp <= self.stop: diff --git a/cms/server/admin/handlers/base.py b/cms/server/admin/handlers/base.py index 25af1222c8..9418df8706 100644 --- a/cms/server/admin/handlers/base.py +++ b/cms/server/admin/handlers/base.py @@ -334,7 +334,6 @@ def render_params(self) -> dict: if self.current_user is not None: params["admin"] = self.current_user if self.contest is not None: - params["phase"] = self.contest.phase(params["timestamp"]) params["unanswered"] = self.sql_session.query(Question)\ .join(Participation)\ .filter(Participation.contest_id == self.contest.id)\ diff --git a/cms/server/admin/static/aws_utils.js b/cms/server/admin/static/aws_utils.js index eb4a1c3460..fa97ee87c8 100644 --- a/cms/server/admin/static/aws_utils.js +++ b/cms/server/admin/static/aws_utils.js @@ -30,7 +30,7 @@ var CMS = CMS || {}; CMS.AWSUtils = function(url_root, timestamp, contest_start, contest_stop, analysis_start, analysis_stop, - phase) { + analysis_enabled) { this.url = CMS.AWSUtils.create_url_builder(url_root); this.first_date = new Date(); this.last_notification = timestamp; @@ -39,7 +39,7 @@ CMS.AWSUtils = function(url_root, timestamp, this.contest_stop = contest_stop; this.analysis_start = analysis_start; this.analysis_stop = analysis_stop; - this.phase = phase; + this.analysis_enabled = analysis_enabled; this.file_asked_name = ""; this.file_asked_url = ""; @@ -476,42 +476,35 @@ CMS.AWSUtils.prototype.two_digits = function(n) { /** * Update the remaining time showed in the "remaining" div. - * - * timer (int): handle for the timer that called this function, or -1 if none */ -CMS.AWSUtils.prototype.update_remaining_time = function(timer = -1) { - // We assume this.phase always is the correct phase (since this - // method also refreshes the page when the phase changes). +CMS.AWSUtils.prototype.update_remaining_time = function() { var relevant_timestamp = null; var text = null; - if (this.phase === -1) { + var now_timestamp = this.timestamp + (new Date() - this.first_date) / 1000; + + // based on the phase logic from cms/db/contest.py. + if (now_timestamp < this.contest_start) { relevant_timestamp = this.contest_start; text = "To start of contest: " - } else if (this.phase === 0) { + } else if (now_timestamp <= this.contest_stop) { relevant_timestamp = this.contest_stop; text = "To end of contest: " - } else if (this.phase === 1) { + } else if (this.analysis_enabled && now_timestamp < this.analysis_start) { relevant_timestamp = this.analysis_start; text = "To start of analysis: " - } else if (this.phase === 2) { + } else if (this.analysis_enabled && now_timestamp <= this.analysis_stop) { relevant_timestamp = this.analysis_stop; text = "To end of analysis: " } // We are in phase 3, nothing to show. if (relevant_timestamp === null) { + $("#remaining_text").text(""); + $("#remaining_value").text(""); return; } - // Compute actual seconds to next phase value, and if negative we - // refresh to update the phase. - var now = new Date(); - var countdown_sec = - relevant_timestamp - this.timestamp - (now - this.first_date) / 1000; - if (countdown_sec <= 0) { - clearInterval(timer); - location.reload(); - } + var countdown_sec = relevant_timestamp - now_timestamp; $("#remaining_text").text(text); $("#remaining_value").text(this.format_countdown(countdown_sec)); diff --git a/cms/server/admin/templates/base.html b/cms/server/admin/templates/base.html index ab46588e4d..ff6b099509 100644 --- a/cms/server/admin/templates/base.html +++ b/cms/server/admin/templates/base.html @@ -26,22 +26,18 @@ function init() { {% if contest is none %} - utils = new CMS.AWSUtils("{{ url() }}", {{ timestamp|make_timestamp }}, 0, 0, 0, 0, -1); - utils.update_notifications(); - setInterval(function() { utils.update_notifications(); }, 15000); + utils = new CMS.AWSUtils("{{ url() }}", {{ timestamp|make_timestamp }}, 0, 0, 0, 0, 0); {% else %} utils = new CMS.AWSUtils("{{ url() }}", {{ timestamp|make_timestamp }}, {{ contest.start|make_timestamp }}, {{ contest.stop|make_timestamp }}, {{ contest.analysis_start|make_timestamp }}, {{ contest.analysis_stop|make_timestamp }}, - {{ phase }}); + {{ contest.analysis_enabled | int }}); - {% if phase < 3 %} utils.update_remaining_time(); - var timer = setInterval(function() { utils.update_remaining_time(timer); }, 1000); + setInterval(function() { utils.update_remaining_time(); }, 1000); {% endif %} utils.update_notifications(); setInterval(function() { utils.update_notifications(); }, 15000); - {% endif %} $(document).click(utils.hide_subpage);