Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update "cws_style.css""cws_utils.js""contest.html" #1314

Closed
wants to merge 4 commits into from
Closed
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
727 changes: 0 additions & 727 deletions cms/server/contest/static/css/bootstrap.css

This file was deleted.

6 changes: 6 additions & 0 deletions cms/server/contest/static/css/bootstrap.min.css

Large diffs are not rendered by default.

950 changes: 26 additions & 924 deletions cms/server/contest/static/cws_style.css

Large diffs are not rendered by default.

130 changes: 21 additions & 109 deletions cms/server/contest/static/cws_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ CMS.CWSUtils = function(url_root, contest_root, contest_name, timestamp, timezon
}
};


CMS.CWSUtils.create_url_builder = function(url_root) {
return function() {
var url = url_root;
Expand All @@ -64,7 +63,6 @@ CMS.CWSUtils.create_url_builder = function(url_root) {
};
};


CMS.CWSUtils.prototype.update_notifications = function(hush) {
var self = this;
$.get(
Expand All @@ -87,14 +85,12 @@ CMS.CWSUtils.prototype.update_notifications = function(hush) {
}, "json");
};


CMS.CWSUtils.prototype.display_notification = function(type, timestamp,
subject, text,
level, hush) {
// TODO somehow display timestamp, subject and text

var alert = $('<div class="alert alert-block notification">' +
'<a class="close" data-dismiss="alert" href="#">×</a>' +
// Create alert container
var alert = $('<div class="alert notification fade show" role="alert">' +
'<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>' +
'<h4 class="alert-heading"></h4>' +
'</div>');

Expand All @@ -109,9 +105,9 @@ CMS.CWSUtils.prototype.display_notification = function(type, timestamp,
alert.append($("<span>" + text + "</span>"));
}

// The "warning" level is the default, so no check needed.
// Set alert level (error, success, etc.)
if (level == "error") {
alert.addClass("alert-error");
alert.addClass("alert-danger");
} else if (level == "success") {
alert.addClass("alert-success");
}
Expand All @@ -124,7 +120,6 @@ CMS.CWSUtils.prototype.display_notification = function(type, timestamp,
}
};


CMS.CWSUtils.prototype.desktop_notification = function(type, timestamp,
subject, text) {
// Check desktop notifications support
Expand All @@ -146,7 +141,6 @@ CMS.CWSUtils.prototype.desktop_notification = function(type, timestamp,
}
};


CMS.CWSUtils.prototype.update_unread_count = function(delta, value) {
if (delta > 0) {
this.unread_count += delta;
Expand All @@ -160,22 +154,13 @@ CMS.CWSUtils.prototype.update_unread_count = function(delta, value) {
$("#unread_count").toggleClass("no_unread", this.unread_count === 0);
};


CMS.CWSUtils.prototype.update_last_notification = function(timestamp) {
if (this.last_notification === null || timestamp > this.last_notification) {
this.last_notification = timestamp;
localStorage.setItem(this.contest_name + "_last_notification", this.last_notification.toString());
}
};


/**
* Return a string representation of the number with two digits.
*
* n (int): a number with one or two digits.
* return (string): n as a string with two digits, maybe with a
* leading 0.
*/
CMS.CWSUtils.prototype.two_digits = function(n) {
if (n < 10) {
return "0" + n;
Expand All @@ -184,22 +169,13 @@ CMS.CWSUtils.prototype.two_digits = function(n) {
}
};


/**
* Return the time of the given timestamp as "HH:MM:SS" in UTC.
*
* timestamp (float): a UNIX timestamp.
* return (string): hours, minutes and seconds, zero-padded to two
* digits and colon-separated, of timestamp in UTC timezone.
*/
CMS.CWSUtils.prototype.format_time = function(timestamp) {
var date = new Date(timestamp * 1000);
return this.two_digits(date.getUTCHours()) + ":"
+ this.two_digits(date.getUTCMinutes()) + ":"
+ this.two_digits(date.getUTCSeconds());
};


CMS.CWSUtils.prototype.format_timedelta = function(timedelta) {
// A negative time delta does not make sense, let's show zero to the user.
if (timedelta < 0) {
Expand All @@ -217,12 +193,8 @@ CMS.CWSUtils.prototype.format_timedelta = function(timedelta) {
+ this.two_digits(seconds);
};


CMS.CWSUtils.prototype.update_time = function(usaco_like_contest, timer = -1) {
var now = $.now() / 1000;

// FIXME This may cause some problems around DST boundaries, as it
// is not adjusted because we consider it to be in UTC timezone.
var server_timezoned_time = now - this.client_timestamp + this.server_timezoned_timestamp;
$("#server_time").text(this.format_time(server_timezoned_time));

Expand All @@ -234,93 +206,56 @@ CMS.CWSUtils.prototype.update_time = function(usaco_like_contest, timer = -1) {
window.location.href = contest_url;
};

// TODO consider possible null values of this.current_phase_begin
// and this.current_phase_end (they mean -inf and +inf
// respectively)

switch (this.phase) {
case -2:
// Contest hasn't started yet.
if (server_time >= this.current_phase_end) {
reload_overview();
}
$("#countdown_label").text(
$("#translation_until_contest_starts").text());
$("#countdown").text(
this.format_timedelta(this.current_phase_end - server_time));
$("#countdown_label").text($("#translation_until_contest_starts").text());
$("#countdown").text(this.format_timedelta(this.current_phase_end - server_time));
break;
case -1:
// Contest has already started but user is not competing yet,
// either because they haven't started the per user time yet,
// or because their start was delayed.
if (usaco_like_contest) {
$("#countdown_label").text(
$("#translation_until_contest_ends").text());
$("#countdown_label").text($("#translation_until_contest_ends").text());
} else {
$("#countdown_label").text(
$("#translation_until_contest_starts").text());
$("#countdown_label").text($("#translation_until_contest_starts").text());
}
$("#countdown").text(
this.format_timedelta(this.current_phase_end - server_time));
$("#countdown").text(this.format_timedelta(this.current_phase_end - server_time));
break;
case 0:
// Contest is currently running.
if (server_time >= this.current_phase_end) {
reload_overview();
}
$("#countdown_label").text($("#translation_time_left").text());
$("#countdown").text(
this.format_timedelta(this.current_phase_end - server_time));
$("#countdown").text(this.format_timedelta(this.current_phase_end - server_time));
break;
case +1:
// User has already finished its time but contest hasn't
// finished yet.
if (server_time >= this.current_phase_end) {
reload_overview();
}
$("#countdown_label").text(
$("#translation_until_contest_ends").text());
$("#countdown").text(
this.format_timedelta(this.current_phase_end - server_time));
$("#countdown_label").text($("#translation_until_contest_ends").text());
$("#countdown").text(this.format_timedelta(this.current_phase_end - server_time));
break;
case +2:
// Contest has already finished but analysis mode hasn't started yet.
if (server_time >= this.current_phase_end) {
reload_overview();
}
$("#countdown_label").text(
$("#translation_until_analysis_starts").text());
$("#countdown").text(
this.format_timedelta(this.current_phase_end - server_time));
$("#countdown_label").text($("#translation_until_analysis_starts").text());
$("#countdown").text(this.format_timedelta(this.current_phase_end - server_time));
break;
case +3:
// Contest has already finished. Analysis mode is running.
if (server_time >= this.current_phase_end) {
reload_overview();
}
$("#countdown_label").text(
$("#translation_until_analysis_ends").text());
$("#countdown").text(
this.format_timedelta(this.current_phase_end - server_time));
$("#countdown_label").text($("#translation_until_analysis_ends").text());
$("#countdown").text(this.format_timedelta(this.current_phase_end - server_time));
break;
case +4:
// Contest has already finished and analysis mode is either disabled
// or finished.
$("#countdown_box").addClass("hidden");
break;
}
};

/* Taken from https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie#Using_relative_URLs_in_the_path_parameter */
CMS.CWSUtils.prototype.rel_to_abs = function(sRelPath) {
var nUpLn, sDir = "", sPath = location.pathname.replace(/[^\/]*$/, sRelPath.replace(/(\/|^)(?:\.?\/+)+/g, "$1"));
for (var nEnd, nStart = 0; nEnd = sPath.indexOf("/../", nStart), nEnd > -1; nStart = nEnd + nUpLn) {
nUpLn = /^\/(?:\.\.\/)*/.exec(sPath.slice(nEnd))[0].length;
sDir = (sDir + sPath.substring(nStart, nEnd)).replace(new RegExp("(?:\\\/+[^\\\/]*){0," + ((nUpLn - 1) / 3) + "}$"), "/");
}
return sDir + sPath.substr(nStart);
};

CMS.CWSUtils.prototype.switch_lang = function() {
var cookie_path = this.rel_to_abs(this.contest_url() + "/").slice(0, -1) || "/";
var lang = $("#lang").val();
Expand All @@ -343,7 +278,6 @@ CMS.CWSUtils.filter_languages = function(options, inputs) {
for (var i = 0; i < inputs.length; i++) {
exts.push('.' + inputs[i].value.match(/[^.]*$/)[0]);
}
// Find all languages that should be enabled.
var enabled = {};
var anyEnabled = false;
for (var lang in LANGUAGES) {
Expand All @@ -355,33 +289,11 @@ CMS.CWSUtils.filter_languages = function(options, inputs) {
}
}
}
// If no language matches the extension, enable all and let the user
// select.
if (!anyEnabled) {
options.removeAttr('disabled');
return;
}

// Otherwise, disable all languages that do not match the extension.
var isSelectedDisabled = false;
options.each(function(i, option) {
if (enabled[option.value]) {
$(option).removeAttr('disabled');
} else {
$(option).attr('disabled', 'disabled');
if (option.selected) {
isSelectedDisabled = true;
}
}
});
// Else, if the current selected is disabled, select one that is enabled.
if (isSelectedDisabled) {
for (i = 0; i < options.length; i++) {
if ($(options[i]).attr('disabled') != 'disabled') {
options[i].selected = true;
break;
if (anyEnabled) {
for (var lang in LANGUAGES) {
if (enabled[lang]) {
options.append("<option value='" + lang + "'>" + lang + "</option>");
}
}
}
};

7 changes: 7 additions & 0 deletions cms/server/contest/static/js/bootstrap.bundle.min.js

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions cms/server/contest/static/js/bootstrap.js

This file was deleted.

7 changes: 2 additions & 5 deletions cms/server/contest/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
<title>{% block title %}{% endblock title %}</title>

<link rel="shortcut icon" href="{{ url("static", "favicon.ico") }}" />
<link rel="stylesheet" href="{{ url("static", "css", "bootstrap.css") }}">
<link rel="stylesheet" href="{{ url("static", "css", "bootstrap.min.css") }}">
<link rel="stylesheet" href="{{ url("static", "cws_style.css") }}">

<script src="{{ url("static", "jq", "jquery-3.6.0.min.js") }}"></script>
{# For compatibility with Bootstrap 2.x #}
<script src="{{ url("static", "jq", "jquery-migrate-3.3.2.min.js") }}"></script>
<script src="{{ url("static", "js", "bootstrap.js") }}"></script>
<script src="{{ url("static", "js", "bootstrap.bundle.min.js") }}"></script>
<script src="{{ url("static", "cws_utils.js") }}"></script>

{% block js %}{% endblock js %}
Expand Down
Loading