Skip to content

Commit

Permalink
Toggling instead of filtering the balloon page (#364)
Browse files Browse the repository at this point in the history
* Toggling instead of filtering the balloon page

* More general check for marked_ids' existence

---------

Co-authored-by: winprn <[email protected]>
  • Loading branch information
2 people authored and leduythuccs committed Oct 18, 2024
1 parent 1f17839 commit 4a00b14
Showing 1 changed file with 67 additions and 11 deletions.
78 changes: 67 additions & 11 deletions templates/contest/balloons.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,85 @@

{% block content_js_media %}
{% include "contest/media-js.html" %}

<style>
.marked {
background-color: #31c742;
}
</style>

<script>
// mark rows with submission id in localStorage
function mark_stored_ids() {
let marked_ids = localStorage.getItem('marked_ids');
marked_ids = marked_ids ? marked_ids.split(',') : [];

let rows = document.querySelectorAll('tbody > tr');

for (let row_i = 0; row_i < rows.length; row_i++) {
let row = rows[row_i];
let sub_id = row.children[1].textContent.trim();

if (marked_ids.includes(sub_id)) {
row.classList.add('marked');
}
}
}

function mark_row() {
let sub_id = $(this).children()[1].textContent.trim();

let marked_ids = localStorage.getItem('marked_ids') || '';
marked_ids = marked_ids ? marked_ids.split(',') : [];

let pos = marked_ids.indexOf(sub_id);

if (pos == -1) {
marked_ids.push(sub_id);
$(this).addClass('marked');
} else {
marked_ids.splice(pos, 1);
$(this).removeClass('marked');
}

localStorage.setItem('marked_ids', marked_ids.join(','));
}

function scroll_to_unmarked() {
const first_unmarked = document.querySelector('tbody > tr:not(.marked)');
const navbar_height = document.getElementById('navigation').offsetHeight;
if (first_unmarked) {
window.scroll(0, first_unmarked.offsetTop - navbar_height);
}
}

document.addEventListener("DOMContentLoaded", function() {
// disable scroll restoration
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}

mark_stored_ids();
scroll_to_unmarked();
$('tr').click(mark_row);
$('#scroll-to-unmarked').click(scroll_to_unmarked);
});
</script>
{% endblock %}


{% block body %}
<div class="contest-clartifications">
<form action="balloons" method="get">
<input type="hidden" name="balloons_done" value="0">
<input type="submit" value="Reset filter">
</form>
<button class="button" id="scroll-to-unmarked">
Scroll to unmarked
</button>
<table id="contest-clartifications" class="table">
<thead>
<tr>
<th>{{ _('NO.') }}</th>
<th>{{ _('SubID.') }}</th>
<th>{{ _('TEAM') }}</th>
<th>{{ _('PROBLEM') }}</th>
<th></th>
</tr>
</thead>
<tbody>
Expand All @@ -54,12 +116,6 @@
<td style="text-align: left; padding-left: 2em;">
{{ submission.problem.code }}
</td>
<td>
<form action="balloons" method="get">
<input type="hidden" name="balloons_done" value="{{ loop.index0 + balloons_done + 1 }}">
<input type="submit" value="Filter from here">
</form>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 4a00b14

Please sign in to comment.