Skip to content

Commit 5ef70b0

Browse files
Commit
1 parent 166fe3c commit 5ef70b0

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

templates/base.html.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,7 @@
7878
</script>
7979
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
8080

81+
{% block scripts %}
82+
{% endblock %}
83+
8184
</html>

templates/index.html.jinja

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
{% extends "base.html.jinja" %}
22

33
{% block main %}
4-
<div>
4+
<div class="container-fluid">
5+
<div class="row justify-content-center" style="margin-bottom: 10px;">
6+
<div class="col-auto">
7+
<div class="form-group mb-0" style="text-align: center;">
8+
<label for="sortDropdown" style="margin-right: 8px; font-weight: 500;">Sort by:</label>
9+
<select id="sortDropdown" class="form-control d-inline-block" style="width: auto;"
10+
aria-label="Sort languages by completion or name">
11+
<option value="completion">Completion</option>
12+
<option value="name">Name</option>
13+
</select>
14+
</div>
15+
</div>
16+
</div>
17+
</div>
18+
19+
<div id="languageContainer">
520
<div class="row">
621
{% for project in completion_progress | sort(attribute='completion') | reverse %}
7-
<div class="col-12 col-sm-6 col-md-4 d-flex">
22+
<div class="col-12 col-sm-6 col-md-4 d-flex" data-completion="{{ project.completion }}" data-name="{{ project.language.name }}">
823
<div class="card shadow mb-3 w-100">
924
<div class="card-body">
1025
<h3 class="card-title">{{ project.language.name }}</h3>
@@ -47,3 +62,35 @@
4762
You can download the data on this page in <a href="https://raw.githubusercontent.com/python-docs-translations/dashboard/refs/heads/gh-pages/index.json">JSON format</a>.
4863
</p>
4964
{% endblock %}
65+
66+
{% block scripts %}
67+
<script>
68+
document.addEventListener('DOMContentLoaded', function() {
69+
const sortDropdown = document.getElementById('sortDropdown');
70+
const languageContainer = document.getElementById('languageContainer');
71+
72+
if (sortDropdown && languageContainer) {
73+
sortDropdown.addEventListener('change', function() {
74+
sortLanguages(this.value);
75+
});
76+
}
77+
78+
function sortLanguages(sortBy) {
79+
const row = languageContainer.querySelector('.row');
80+
const cards = Array.from(row.children);
81+
82+
cards.sort((a, b) => {
83+
if (sortBy === 'name') {
84+
return a.dataset.name.localeCompare(b.dataset.name);
85+
} else if (sortBy === 'completion') {
86+
return parseFloat(b.dataset.completion) - parseFloat(a.dataset.completion);
87+
}
88+
return 0;
89+
});
90+
91+
row.innerHTML = '';
92+
cards.forEach(card => row.appendChild(card));
93+
}
94+
});
95+
</script>
96+
{% endblock %}

0 commit comments

Comments
 (0)