|
1 | 1 | {% extends "base.html.jinja" %} |
2 | 2 |
|
3 | 3 | {% 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"> |
5 | 20 | <div class="row"> |
6 | 21 | {% 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 }}"> |
8 | 23 | <div class="card shadow mb-3 w-100"> |
9 | 24 | <div class="card-body"> |
10 | 25 | <h3 class="card-title">{{ project.language.name }}</h3> |
|
47 | 62 | 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>. |
48 | 63 | </p> |
49 | 64 | {% 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