Relento
first commit.
ecd3201
raw
history blame
5.15 kB
<!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>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome for Icons -->
<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.
<!-- Search Input -->
<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 -->
<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>
<!-- Bootstrap JS (for responsive elements) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
let sortDirections = [true, true, true]; // True for ascending, false for descending for each column
// Load the JSON data from a local file
async function loadJSON() {
const response = await fetch('/pieces_metadata'); // Ensure 'pieces_metadata.json' is in the same directory
const pieces = await response.json();
return pieces;
}
// Generate the table rows from the fetched JSON data
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);
});
}
// Sort table based on columns
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();
// Sort piece_id as numbers
if (columnIndex === 0) {
return ascending ? aText - bText : bText - aText;
}
// Sort by text for other columns
return ascending ? aText.localeCompare(bText) : bText.localeCompare(aText);
});
// Toggle the sort direction for next click
sortDirections[columnIndex] = !ascending;
// Clear the table and re-append the sorted rows
table.innerHTML = '';
rows.forEach(row => table.appendChild(row));
// Update sort icons
updateSortIcons(columnIndex, ascending);
}
// Update the sort icons
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'; // Show up or down arrow
} else {
icon.className = 'fas fa-sort'; // Reset other columns to neutral
}
});
}
// Search function for filtering rows
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';
});
}
// Initialize the table on page load
loadJSON().then(pieces => {
loadTable(pieces);
});
</script>
</body>
</html>