BrickTracker/templates/frontpage.html

188 lines
5.3 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Grid</title>
<!-- CSS Reset -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
<!-- Milligram CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.css">
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 10px;
padding: 10px;
}
.grid-item {
border: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
}
.grid-item img {
max-width: 100%;
height: auto;
display: block;
}
/* Style to display paragraphs inline */
.grid-item p {
display: inline-block;
margin: 0; /* Remove default margin */
}
.button {
background-color: black;
border-color: black;
}
.button.button-clear,
.button.button-outline {
background-color: transparent;
color: black;
}
.button.button-clear {
border-color: transparent;
}
.search-container {
padding: 10px;
}
</style>
</head>
<body>
<div class="search-container">
<input type="text" id="searchInput" onkeyup="searchFunction()" placeholder="Search...">
</select>
<center>
<button class="button button-outline" onclick="dynamicSort('set_id')">Sort by ID</button>
<button class="button button-outline" onclick="dynamicSort('set_year')">Sort by Year</button>
<button class="button button-outline" onclick="dynamicSort('set_parts')">Sort by Parts</button>
<button class="button button-outline" onclick="dynamicSort('set_name')">Sort by Name</button>
</center>
<!-- Add more buttons for other text values if needed -->
</div>
<div class="grid-container" id="gridContainer">
{% for i in set_list %}
<div class="grid-item">
<center><img src="/static/sets/{{ i['set_num'] }}/cover.jpg" style="height: 150px; width: auto;" alt="Image"></center>
<h2 class='set_name'>{{ i['name'] }}</h2>
<p><b>Set:</b></p><p class='set_id'>{{ i['set_num'] }}</p>
<br>
<p><b>Year: </b></p><p class='set_year'>{{ i['year'] }}</p>
<br>
<p><b>Parts:</b></p><p class='set_parts'>{{ i['num_parts'] }}</p>
<br>
<p><b>Inventory:</b> <a href="/{{ i['set_num'] }}">Link</a></p>
</div>
{% endfor %}
</div>
<script>
function searchFunction() {
var input, filter, gridContainer, gridItems, i, txtValue;
input = document.getElementById('searchInput');
filter = input.value.toUpperCase();
gridContainer = document.getElementById('gridContainer');
gridItems = gridContainer.getElementsByClassName('grid-item');
for (i = 0; i < gridItems.length; i++) {
txtValue = gridItems[i].textContent || gridItems[i].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
gridItems[i].style.display = "";
} else {
gridItems[i].style.display = "none";
}
}
}
function sortFunction() {
var sortSelect, sortValue, gridContainer, gridItems, sortedItems, i;
sortSelect = document.getElementById('sortSelect');
sortValue = sortSelect.value;
gridContainer = document.getElementById('gridContainer');
gridItems = gridContainer.getElementsByClassName('grid-item');
sortedItems = Array.from(gridItems);
if (sortValue === 'alphabetical') {
sortedItems.sort(function(a, b) {
var textA = a.textContent.trim().toUpperCase();
var textB = b.textContent.trim().toUpperCase();
if (textA < textB) {
return -1;
}
if (textA > textB) {
return 1;
}
return 0;
});
}
// Remove existing items
while (gridContainer.firstChild) {
gridContainer.removeChild(gridContainer.firstChild);
}
// Append sorted items
for (i = 0; i < sortedItems.length; i++) {
gridContainer.appendChild(sortedItems[i]);
}
}
var sortOrder = 'asc';
function dynamicSort(className) {
var gridContainer, gridItems, sortedItems, i;
gridContainer = document.getElementById('gridContainer');
gridItems = gridContainer.getElementsByClassName('grid-item');
sortedItems = Array.from(gridItems);
sortedItems.sort(function(a, b) {
var textA = a.getElementsByClassName(className)[0].textContent.trim();
var textB = b.getElementsByClassName(className)[0].textContent.trim();
// Remove digits after hyphen if present
textA = textA.replace(/-\d+$/, '').trim();
textB = textB.replace(/-\d+$/, '').trim();
// If text1 is an integer, parse it as a number
if (!isNaN(textA) && !isNaN(textB)) {
var result = parseInt(textA) - parseInt(textB);
// Toggle result based on current sort order
return sortOrder === 'asc' ? result : -result;
}
// If text1 is not an integer, treat it as a string
else {
textA = textA.toUpperCase();
textB = textB.toUpperCase();
var result = textA.localeCompare(textB);
// Toggle result based on current sort order
return sortOrder === 'asc' ? result : -result;
}
});
// Reverse sort order for next click
sortOrder = sortOrder === 'asc' ? 'desc' : 'asc';
// Remove existing items
while (gridContainer.firstChild) {
gridContainer.removeChild(gridContainer.firstChild);
}
// Append sorted items
for (i = 0; i < sortedItems.length; i++) {
gridContainer.appendChild(sortedItems[i]);
}
}
</script>
</body>
</html>