Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cms/db/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion cms/server/admin/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)\
Expand Down
33 changes: 13 additions & 20 deletions cms/server/admin/static/aws_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "";

Expand Down Expand Up @@ -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));
Expand Down
10 changes: 3 additions & 7 deletions cms/server/admin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down