| | <!DOCTYPE html> |
| | <html lang="en"> |
| | <head> |
| | <meta charset="UTF-8"> |
| | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| | <title>FürElise Dataset Visualizer</title> |
| | |
| | <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> |
| | |
| | <link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'> |
| | <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> |
| |
|
| | <style> |
| | body { |
| | font-family: 'Source Sans Pro', sans-serif; |
| | margin: 20px; |
| | } |
| | th { |
| | cursor: pointer; |
| | } |
| | tr:hover { |
| | background-color: #f1f1f1; |
| | } |
| | th i { |
| | margin-left: 10px; |
| | } |
| | </style> |
| | </head> |
| | <body> |
| |
|
| | <div class="container"> |
| | <h1 class="my-4 text-center">FürElise Dataset Visualizer</h1> |
| | Click any piece to start. |
| |
|
| | |
| | <div class="row"> |
| | <div class="col-md-6 mx-auto"> |
| | <input type="text" class="form-control" id="searchInput" placeholder="Search by piece ID, name, or composer" onkeyup="searchTable()"> |
| | </div> |
| | </div> |
| |
|
| | |
| | <table class="table table-hover mt-4"> |
| | <thead class="table-dark"> |
| | <tr> |
| | <th scope="col" onclick="sortTable(0)">Piece ID <i class="fas fa-sort"></i></th> |
| | <th scope="col" onclick="sortTable(1)">Piece Name <i class="fas fa-sort"></i></th> |
| | <th scope="col" onclick="sortTable(2)">Composer <i class="fas fa-sort"></i></th> |
| | </tr> |
| | </thead> |
| | <tbody id="piecesTable"></tbody> |
| | </table> |
| | </div> |
| |
|
| | |
| | <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> |
| |
|
| | <script> |
| | let sortDirections = [true, true, true]; |
| | |
| | |
| | async function loadJSON() { |
| | const response = await fetch('/pieces_metadata'); |
| | const pieces = await response.json(); |
| | return pieces; |
| | } |
| | |
| | |
| | function loadTable(pieces) { |
| | const table = document.getElementById('piecesTable'); |
| | pieces.forEach(piece => { |
| | let row = document.createElement('tr'); |
| | row.innerHTML = ` |
| | <td>${piece.piece_id}</td> |
| | <td><a href="/vis?id=${piece.piece_id}" class="text-decoration-none">${piece.name}</a></td> |
| | <td>${piece.composer}</td> |
| | `; |
| | table.appendChild(row); |
| | }); |
| | } |
| | |
| | |
| | function sortTable(columnIndex) { |
| | const table = document.getElementById('piecesTable'); |
| | let rows = Array.from(table.getElementsByTagName('tr')); |
| | |
| | const ascending = sortDirections[columnIndex]; |
| | rows.sort((a, b) => { |
| | const aText = a.cells[columnIndex].textContent.trim(); |
| | const bText = b.cells[columnIndex].textContent.trim(); |
| | |
| | |
| | if (columnIndex === 0) { |
| | return ascending ? aText - bText : bText - aText; |
| | } |
| | |
| | return ascending ? aText.localeCompare(bText) : bText.localeCompare(aText); |
| | }); |
| | |
| | |
| | sortDirections[columnIndex] = !ascending; |
| | |
| | |
| | table.innerHTML = ''; |
| | rows.forEach(row => table.appendChild(row)); |
| | |
| | |
| | updateSortIcons(columnIndex, ascending); |
| | } |
| | |
| | |
| | function updateSortIcons(columnIndex, ascending) { |
| | const ths = document.querySelectorAll('th'); |
| | ths.forEach((th, i) => { |
| | const icon = th.querySelector('i'); |
| | if (i === columnIndex) { |
| | icon.className = ascending ? 'fas fa-sort-up' : 'fas fa-sort-down'; |
| | } else { |
| | icon.className = 'fas fa-sort'; |
| | } |
| | }); |
| | } |
| | |
| | |
| | function searchTable() { |
| | const input = document.getElementById('searchInput').value.toLowerCase(); |
| | const rows = document.querySelectorAll('#piecesTable tr'); |
| | |
| | rows.forEach(row => { |
| | const pieceID = row.cells[0].textContent.toLowerCase(); |
| | const name = row.cells[1].textContent.toLowerCase(); |
| | const composer = row.cells[2].textContent.toLowerCase(); |
| | row.style.display = pieceID.includes(input) || name.includes(input) || composer.includes(input) ? '' : 'none'; |
| | }); |
| | } |
| | |
| | |
| | loadJSON().then(pieces => { |
| | loadTable(pieces); |
| | }); |
| | </script> |
| |
|
| | </body> |
| | </html> |
| |
|