Refactor 3-col-content

This commit is contained in:
cuom1999 2024-06-24 14:56:00 -05:00
parent 326b3d5dd3
commit a711fb9768
37 changed files with 453 additions and 384 deletions

View file

@ -66,7 +66,7 @@ class AceWidget(forms.Textarea):
if self.toolbar:
toolbar = (
'<div style="width: {}" class="django-ace-toolbar">'
'<a href="./" class="django-ace-max_min"></a>'
'<a href="#" class="django-ace-max_min"></a>'
"</div>"
).format(self.width)
html = toolbar + html

View file

@ -671,21 +671,13 @@ class OrganizationRequestBaseView(
LoginRequiredMixin,
SingleObjectTemplateResponseMixin,
SingleObjectMixin,
AdminOrganizationMixin,
):
model = Organization
slug_field = "key"
slug_url_kwarg = "key"
tab = None
def get_object(self, queryset=None):
organization = super(OrganizationRequestBaseView, self).get_object(queryset)
if not (
organization.admins.filter(id=self.request.profile.id).exists()
or organization.registrant_id == self.request.profile.id
):
raise PermissionDenied()
return organization
def get_content_title(self):
return _("Manage join requests")

View file

@ -426,6 +426,192 @@ function submitFormWithParams($form, method) {
}
}
function saveCurrentPageToSessionStorage() {
const storageLimit = 5;
const sessionStorageKey = 'oj-content-keys';
let key = `oj-content-${window.location.href}`;
let $contentClone = $('body').clone();
$contentClone.find('.select2').remove();
$contentClone.find('.select2-hidden-accessible').removeClass('select2-hidden-accessible');
$contentClone.find('.noUi-base').remove();
$contentClone.find('.wmd-button-row').remove();
let contentData = JSON.stringify({
"html": $contentClone.html(),
"page": window.page,
"has_next_page": window.has_next_page,
"scrollOffset": $(window).scrollTop(),
});
let keys = JSON.parse(sessionStorage.getItem(sessionStorageKey)) || [];
// Remove the existing key if it exists
if (keys.includes(key)) {
keys = keys.filter(k => k !== key);
}
keys.push(key);
if (keys.length > storageLimit) {
let oldestKey = keys.shift();
sessionStorage.removeItem(oldestKey);
}
sessionStorage.setItem(sessionStorageKey, JSON.stringify(keys));
sessionStorage.setItem(key, contentData);
}
function loadPageFromSessionStorage() {
let key = `oj-content-${window.location.href}`;
let content = sessionStorage.getItem(key);
if (content) {
content = JSON.parse(content);
$('body').html(content.html);
onWindowReady();
window.PAGE_FROM_BACK_BUTTON_CACHE = true;
setTimeout(() => {
$(window).scrollTop(content.scrollOffset - 50);
}, 1);
window.page = content.page;
window.has_next_page = content.has_next_page;
}
}
let currentRequest = null; // Variable to keep track of the current request
function navigateTo(url, reload_container, force_new_page=false) {
if (url === '#') return;
if (force_new_page) {
window.location.href = url;
return;
}
if (!reload_container || !$(reload_container).length) {
reload_container = "#content";
}
if (currentRequest) {
currentRequest.abort();
}
const controller = new AbortController();
const signal = controller.signal;
currentRequest = controller;
$(window).off("scroll");
saveCurrentPageToSessionStorage();
replaceLoadingPage(reload_container);
const toUpdateElements = [
"#nav-container",
"#js_media",
"#media",
".left-sidebar",
"#bodyend",
];
$.ajax({
url: url,
method: 'GET',
dataType: 'html',
signal: signal,
success: function (data) {
let reload_content = $(data).find(reload_container).first();
if (!reload_content.length) {
reload_container = "#content";
reload_content = $(data).find(reload_container).first();
}
if (reload_content.length) {
window.history.pushState("", "", url);
$(window).scrollTop(0);
$("#loading-bar").stop(true, true);
$("#loading-bar").hide().css({ width: 0});
for (let elem of toUpdateElements) {
$(elem).replaceWith($(data).find(elem).first());
}
$(reload_container).replaceWith(reload_content);
$(document).prop('title', $(data).filter('title').text());
renderKatex($(reload_container)[0]);
onWindowReady();
$('.xdsoft_datetimepicker').hide();
} else {
window.location.href = url;
}
},
error: function (xhr, status, error) {
if (status !== 'abort') { // Ignore aborted requests
window.location.href = url;
}
}
});
}
function isEligibleLinkToRegister($e) {
if ($e.attr('target') === '_blank') {
return false;
}
if ($e.data('initialized_navigation')) {
return false;
}
const href = $e.attr('href');
if (!href) return false;
return (
href.startsWith('http')
|| href.startsWith('/')
|| href.startsWith('#')
|| href.startsWith('?')
);
};
function replaceLoadingPage(reload_container) {
const loadingPage = `
<div style="height: 80vh; margin: 0; display: flex; align-items: center; justify-content: center; width: 100%; font-size: xx-large;">
<i class="fa fa-spinner fa-pulse"></i>
</div>
`;
$(reload_container).fadeOut(100, function() {
$(this).html(loadingPage).fadeIn(100);
});
}
function registerNavigation() {
const containerMap = {
'.left-sidebar-item': '.middle-right-content',
'.pagination li a': '.middle-content',
'.tabs li a': '.middle-content',
'#control-panel a': '.middle-content',
};
$.each(containerMap, function(selector, target) {
$(selector).each(function() {
const href = $(this).attr('href');
const force_new_page = $(this).data('force_new_page');
if (isEligibleLinkToRegister($(this))) {
$(this).data('initialized_navigation', true);
$(this).on('click', function(e) {
e.preventDefault();
let containerSelector = null;
for (let key in containerMap) {
if ($(this).is(key)) {
containerSelector = containerMap[key];
break;
}
}
navigateTo(href, containerSelector, force_new_page);
});
}
});
});
}
function onWindowReady() {
// http://stackoverflow.com/a/1060034/1090657
var hidden = 'hidden';
@ -537,12 +723,13 @@ function onWindowReady() {
});
register_all_toggles();
activateBlogBoxOnClick();
registerNavigation();
registerPopper($('#nav-lang-icon'), $('#lang-dropdown'));
registerPopper($('#user-links'), $('#userlink_dropdown'));
}
$(function() {
onWindowReady();
registerPopper($('#nav-lang-icon'), $('#lang-dropdown'));
registerPopper($('#user-links'), $('#userlink_dropdown'));
var $nav_list = $('#nav-list');
$('#navicon').click(function (event) {
event.stopPropagation();
@ -582,33 +769,15 @@ $(function() {
$nav_list.hide();
});
$(window).on('beforeunload', function() {
let key = `oj-content-${window.location.href}`;
let $contentClone = $('#content').clone();
$contentClone.find('.select2').remove();
$contentClone.find('.select2-hidden-accessible').removeClass('select2-hidden-accessible');
$contentClone.find('.noUi-base').remove();
$contentClone.find('.wmd-button-row').remove();
sessionStorage.setItem(key, JSON.stringify({
"html": $contentClone.html(),
"page": window.page,
"has_next_page": window.has_next_page,
"scrollOffset": $(window).scrollTop(),
}));
});
$(window).on('beforeunload', saveCurrentPageToSessionStorage);
if (window.performance &&
window.performance.navigation.type
=== window.performance.navigation.TYPE_BACK_FORWARD) {
let key = `oj-content-${window.location.href}`;
let content = sessionStorage.getItem(key);
if (content) {
content = JSON.parse(content);
$('#content').html(content.html);
onWindowReady();
window.PAGE_FROM_BACK_BUTTON_CACHE = true;
$(window).scrollTop(content.scrollOffset - 100);
window.page = content.page;
window.has_next_page = content.has_next_page;
}
loadPageFromSessionStorage();
}
window.addEventListener('popstate', (e) => {
window.location.href = e.currentTarget.location.href;
});
});

File diff suppressed because one or more lines are too long

View file

@ -67,7 +67,7 @@
}
</style>
{% endif %}
{% block media %}{% endblock %}
{% if use_darkmode %}
<link rel="stylesheet" href="{{ static('darkmode.css') }}">
<link rel="stylesheet" href="{{ static('darkmode-svg.css') }}">
@ -210,7 +210,7 @@
<div class="dropdown-item"><i class="fa fa-gear"></i> {{ _('Settings') }}</div>
</a>
{% if request.user.is_impersonate %}
<a href="{{ url('impersonate-stop') }}">
<a href="{{ url('impersonate-stop') }}" data-force_new_page="1">
<div class="dropdown-item"><i class="fa fa-eye"></i> {{_('Stop impersonating')}}</div>
</a>
{% else %}
@ -261,6 +261,9 @@
</div>
{% endif %}
<div id="page-container">
<div id="media">
{% block media %}{% endblock %}
</div>
<noscript>
<div id="noscript">{{ _('This site works best with JavaScript enabled.') }}</div>
</noscript>
@ -303,8 +306,9 @@
});
</script>
{% endcompress %}
<div id="js_media">
{% block js_media %}{% endblock %}
</div>
{% if request.in_contest %}
<script>$(function () {
if ($("#contest-time-remaining").length) {
@ -379,10 +383,9 @@
{{ misc_config.analytics|safe }}
{% endif %}
<div id="extra_js">
{% block extra_js %}{% endblock %}
</div>
<div id="bodyend">
{% block bodyend %}{% endblock %}
</div>
<script src="{{ static('katex_config.js') }}"></script>
{% include "katex-load.html" %}
{% block footer %}

View file

@ -46,8 +46,3 @@
<hr style="width: 60%; margin:4em auto;">
{% include "comments/list.html" %}
{% endblock %}
{% block bodyend %}
{{ super() }}
{% include "comments/math.html" %}
{% endblock %}

View file

@ -19,7 +19,7 @@
</style>
{% endblock %}
{% block three_col_js %}
{% block js_media %}
{% include "actionbar/media-js.html" %}
{% include "feed/feed_js.html" %}
<script type="text/javascript">

View file

@ -4,8 +4,6 @@
{% block title_ruler %}{% endblock %}
{% block title %} {{_('Chat Box')}} {% endblock %}
{% block js_media %}
{% include "comments/math.html" %}
<script type="text/javascript" src="{{ static('event.js') }}"></script>
<script type="module" src="https://unpkg.com/emoji-picker-element@1"></script>
{% compress js %}
@ -41,11 +39,12 @@
return receiver;
}
let message_template = `
function message_template() {
return`
{% with message=message_template %}
{% include "chat/message.html" %}
{% endwith %}
`;
`};
$(function() {
load_dynamic_update({{last_msg}});
});

View file

@ -1,5 +1,7 @@
<script type="text/javascript">
let isMobile = window.matchMedia("only screen and (max-width: 799px)").matches;
function isMobile() {
return window.matchMedia("only screen and (max-width: 799px)").matches;
}
function load_next_page(last_id, refresh_html=false) {
if (refresh_html) {
@ -218,7 +220,7 @@
if (window.room_id) {
$("#last_msg-" + window.room_id).html(body);
}
var html = message_template;
var html = message_template();
html = html.replaceAll('$body', body).replaceAll('$id', tmp_id);
var $html = $(html);
$html.find('.time-with-rel').attr('data-iso', (new Date()).toISOString());
@ -288,7 +290,7 @@
}
function show_right_panel() {
if (isMobile) {
if (isMobile()) {
$('.chat-left-panel').hide();
$('#chat-area').css('display', 'flex');
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
@ -296,7 +298,7 @@
}
function hide_right_panel() {
if (isMobile) {
if (isMobile()) {
$('.chat-left-panel').show();
$('#chat-area').hide();
}
@ -479,7 +481,7 @@
const button = document.querySelector('#emoji-button');
const tooltip = document.querySelector('.tooltip');
const popper = Popper.createPopper(button, tooltip, {
placement: isMobile ? 'auto-end' : 'left',
placement: isMobile() ? 'auto-end' : 'left',
});
function toggleEmoji() {

View file

@ -1,3 +0,0 @@
{% compress js, inline %}
<script src="{{ static('pagedown_math.js') }}"></script>
{% endcompress %}

View file

@ -10,7 +10,7 @@
{% include "contest/contest-tabs.html" %}
{% endblock %}
{% block two_col_js %}
{% block js_media %}
{% include "contest/media-js.html" %}
{% include "comments/media-js.html" %}
{% include "actionbar/media-js.html" %}

View file

@ -31,13 +31,14 @@
{% block contest_list_media %}{% endblock %}
{% endblock %}
{% block three_col_js %}
{% block js_media %}
<script type="text/javascript">
$(document).ready(function () {
$('#active-url').attr('href', changeTabParameter('active'));
$('#current-url').attr('href', changeTabParameter('current'));
$('#future-url').attr('href', changeTabParameter('future'));
$('#past-url').attr('href', changeTabParameter('past'));
registerNavigation();
var $form = $('form#filter-form');

View file

@ -18,7 +18,7 @@
</style>
{% endblock %}
{% block two_col_js %}
{% block js_media %}
<script type="text/javascript">
$(function () {
$('.contest-moss').click(function () {

View file

@ -5,7 +5,7 @@
{% include "contest/contest-tabs.html" %}
{% endblock %}
{% block two_col_js %}
{% block js_media %}
<script type="text/javascript">
window.stats = {{ stats }};
</script>

View file

@ -12,7 +12,7 @@
</style>
{% endblock %}
{% block two_col_js %}
{% block js_media %}
{{ form.media.js }}
{% endblock %}

View file

@ -18,7 +18,7 @@
</style>
{% endblock %}
{% block two_col_js %}
{% block js_media %}
<script>
$(document).ready(function(){
var $searchInput = $("#search-input");

View file

@ -10,7 +10,7 @@
</style>
{% endblock %}
{% block three_col_js %}
{% block js_media %}
<script type="text/javascript">
$(function () {
$('.vote-detail').each(function() {

View file

@ -1,6 +1,6 @@
{% extends "two-column-content.html" %}
{% block two_col_js %}
{% block js_media %}
{{ form.media.js }}
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "organization/home-base.html" %}
{% block three_col_js %}
{% block js_media %}
{{ form.media.js }}
{% include "organization/home-js.html" %}
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "organization/home-base.html" %}
{% block three_col_js %}
{% block js_media %}
{{ form.media.js }}
{% include "organization/home-js.html" %}
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "organization/home-base.html" %}
{% block three_col_js %}
{% block js_media %}
{{ form.media.js }}
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "organization/home-base.html" %}
{% block three_col_js %}
{% block js_media %}
{{ form.media.js }}
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "three-column-content.html" %}
{% block three_col_js %}
{% block js_media %}
{% include "organization/home-js.html" %}
{% block org_js %}{% endblock %}
{% endblock %}

View file

@ -1,8 +1,5 @@
<script type="text/javascript">
$(function () {
$('.time-remaining').each(function () {
count_down($(this));
});
function confirmLeaveOrganization() {
$('.leave-organization').click(function () {
if (confirm('{{ _('Are you sure you want to leave this organization?') }}\n' +
{% if organization.is_open %}
@ -14,5 +11,10 @@
$(this).parent().submit();
}
});
}
$(function () {
$('.time-remaining').each(function () {
count_down($(this));
});
});
</script>

View file

@ -1,11 +1,12 @@
{% extends "three-column-content.html" %}
{% block three_col_js %}
{% block js_media %}
<script type="text/javascript">
$(document).ready(function () {
$('#mine-tab').attr('href', changeTabParameter('mine'));
$('#public-tab').attr('href', changeTabParameter('public'));
$('#private-tab').attr('href', changeTabParameter('private'));
registerNavigation();
var $form = $('form#filter-form');

View file

@ -58,7 +58,7 @@
<div class="link-row" style="color: red;">
<form method="post" action="{{ url('leave_organization', organization.id, organization.slug) }}">
{% csrf_token %}
<a href="#" class="leave-organization">
<a href="#" class="leave-organization" onclick="confirmLeaveOrganization()">
<i class="fa fa-sign-out-alt"></i>{{ _('Leave group') }}</a>
</form>
</div>

View file

@ -36,7 +36,3 @@
<br>
{% include "comments/list.html" %}
{% endblock %}
{% block bodyend %}
{% include "comments/math.html" %}
{% endblock %}

View file

@ -24,7 +24,7 @@
</div>
{% if request.user.has_perm('judge.suggest_problem_changes') and feed_type == 'volunteer' %}
<ul style="margin-bottom: 1em; margin-left: auto">
<li><a href="{{url('admin:judge_volunteerproblemvote_changelist')}}">{{_('View your votes')}}</a></li>
<li><a href="{{url('admin:judge_volunteerproblemvote_changelist')}}" target="_blank">{{_('View your votes')}}</a></li>
</ul>
{% endif %}
{% include "problem/feed/items.html" %}

View file

@ -47,7 +47,7 @@
{% endif %}
{% endblock %}
{% block three_col_js %}
{% block js_media %}
{% include "actionbar/media-js.html" %}
{% block problem_list_js %}{% endblock %}
<script>

View file

@ -467,8 +467,3 @@
{% include "problem/related_problems.html" %}
<iframe name="raw_problem" id="raw_problem"></iframe>
{% endblock %}
{% block bodyend %}
{{ super() }}
{% include "comments/math.html" %}
{% endblock %}

View file

@ -2,7 +2,7 @@
{% set has_hidden_subtasks = request.in_contest_mode and request.participation.contest.format.has_hidden_subtasks %}
{% block three_col_js %}
{% block js_media %}
<script type="text/javascript">
{% if dynamic_update and last_msg %}
{% if request.in_contest_mode %}
@ -91,6 +91,7 @@
// Draw the statistics graph.
{% if results_json %}
$(function () {
var chart = null;
function stats_graph(raw_data) {
var colors = {{ results_colors_json }};
@ -130,12 +131,15 @@
$('#total-submission-count').text(raw_data.total);
}
$(function () {
stats_graph(window.results_json);
});
{% endif %}
</script>
{% endcompress %}
{% if dynamic_update and last_msg and not has_hidden_subtasks %}
<script type="text/javascript">
$(function () {
function load_dynamic_update(last_msg) {
var _collect = function (e) {
return e.value;
@ -242,19 +246,9 @@
console.log('Navigated away');
return;
}
console.log('You probably should refresh?');
// $('.ws-closed').show().find('a').click(function () {
// window.location.reload();
// });
};
return receiver;
}
</script>
{% endcompress %}
{% if dynamic_update and last_msg and not has_hidden_subtasks %}
<script type="text/javascript">
$(function () {
load_dynamic_update({{last_msg}});
});
</script>

View file

@ -1,6 +1,6 @@
{% macro make_tab(name, fa, url, text) %}
{% macro make_tab(name, fa, url, text, force_new_page=False) %}
<li class="tab{% if tab == name %} active{% endif %}">
{%- if url %}<a href="{{ url }}">{% else %}<span>{% endif -%}
{%- if url %}<a href="{{ url }}" {% if force_new_page%}data-force_new_page="1"{% endif %}>{% else %}<span>{% endif -%}
<i class="tab-icon fa {{ fa }}"></i> {{ text }}
{%- if url %}</a>{% else %}</span>{% endif -%}
</li>

View file

@ -26,86 +26,6 @@
</style>
{% endblock %}
{% block js_media %}
<script type="text/javascript">
let loadingPage;
function navigateTo($elem, update_sidebar = false) {
var url = $elem.attr('href');
var force_new_page = $elem.data('force_new_page');
if (url === '#') return;
if (force_new_page) {
window.location.href = url;
return;
}
if (update_sidebar) {
$('.left-sidebar-item').removeClass('active');
$elem.addClass('active');
}
$(window).off("scroll");
$('.middle-right-content').html(loadingPage);
$.get(url, function (data) {
var reload_content = $(data).find('.middle-right-content');
var bodyend_script = $(data).find('#extra_js');
if (reload_content.length) {
window.history.pushState("", "", url);
$('html, body').animate({scrollTop: 0}, 'fast');
$('.middle-right-content').html(reload_content.first().html());
$('#extra_js').html(bodyend_script.first().html());
$("#loading-bar").stop(true, true);
$("#loading-bar").hide().css({ width: 0});
if (reload_content.hasClass("wrapper")) {
$('.middle-right-content').addClass("wrapper");
}
else {
$('.middle-right-content').removeClass("wrapper");
}
$(document).prop('title', $(data).filter('title').text());
renderKatex($('.middle-right-content')[0]);
onWindowReady();
$('.xdsoft_datetimepicker').hide();
registerNavigation();
}
else {
window.location.href = url;
}
});
}
function registerNavigation() {
const links = ['.pagination a', '.tabs li a', '#control-panel a'];
for (let linkSelector of links) {
$(linkSelector).each(function() {
if ($(this).attr('target') !== '_blank') {
$(this).on('click', function(e) {
e.preventDefault();
navigateTo($(this));
});
}
});
}
}
$(function () {
window.addEventListener('popstate', (e) => {
window.location.href = e.currentTarget.location.href;
});
$('.left-sidebar-item').on('click', function (e) {
e.preventDefault();
navigateTo($(this), true);
});
registerNavigation();
$.get("{{static('html/loading-page.html')}}", function(data) {
loadingPage = data;
});
});
</script>
{% endblock %}
{% macro make_tab_item(name, fa, url, text, force_new_page=False) %}
<a class="left-sidebar-item {% if page_type == name %}active{% endif %}" href="{{ url }}" id="{{ name }}-tab" {% if force_new_page%}data-force_new_page="1"{% endif %}>
<span class="sidebar-icon"><i class="{{ fa }}"></i></span>
@ -128,12 +48,3 @@
</div>
{% block after_posts %}{% endblock %}
{% endblock %}
{% block extra_js %}
{% block three_col_js %}{% endblock %}
{% endblock %}
{% block bodyend %}
{{ super() }}
{% include "comments/math.html" %}
{% endblock %}

View file

@ -223,8 +223,3 @@
</aside>
</div>
{% endblock %}
{% block bodyend %}
{{ super() }}
{% include "comments/math.html" %}
{% endblock %}

View file

@ -1,10 +1,6 @@
{% set is_two_column = true %}
{% extends "three-column-content.html" %}
{% block three_col_js %}
{% block two_col_js %}{% endblock %}
{% endblock %}
{% block three_col_media %}
<style>
@media (min-width: 800px) {

View file

@ -1,6 +1,6 @@
{% extends "two-column-content.html" %}
{% block two_col_js %}
{% block js_media %}
{% block users_js_media %}{% endblock %}
{% include "user/base-users-js.html" %}
{% endblock %}

View file

@ -5,17 +5,17 @@
{{ make_tab('problems', 'fa-puzzle-piece', url('user_problems', user.user.username), _('Problems')) }}
{{ make_tab('submissions', 'fa-code', url('all_user_submissions', user.username), _('Submissions')) }}
{% if request.user.is_superuser and user != request.profile and not user.user.is_superuser %}
{{ make_tab('impersonate', 'fa-eye', url('impersonate-start', user.user.id), _('Impersonate')) }}
{{ make_tab('impersonate', 'fa-eye', url('impersonate-start', user.user.id), _('Impersonate'), force_new_page=True) }}
{% endif %}
{% if user == request.profile %}
{{ make_tab('bookmark', 'fa-bookmark', url('user_bookmark'), _('Bookmarks')) }}
{{ make_tab('edit', 'fa-edit', url('user_edit_profile'), _('Edit profile')) }}
{{ make_tab('edit', 'fa-gear', url('user_edit_profile'), _('Settings')) }}
{% else %}
{% if perms.auth.change_user %}
{{ make_tab('edit', 'fa-edit', url('admin:auth_user_change', user.user.id), _('Admin User')) }}
{{ make_tab('edit', 'fa-edit', url('admin:auth_user_change', user.user.id), _('Admin User'), force_new_page=True) }}
{% endif %}
{% if perms.judge.change_profile %}
{{ make_tab('edit', 'fa-edit', url('admin:judge_profile_change', user.id), _('Admin Profile')) }}
{{ make_tab('edit', 'fa-edit', url('admin:judge_profile_change', user.id), _('Admin Profile'), force_new_page=True) }}
{% endif %}
{% endif %}
{% endblock %}