Add search page and thing detail with AJAX
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 32s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 7s
All checks were successful
Build containers when image tags change / build-if-image-changed (., web, containers, main container, git.baumann.gr/adebaumann/labhelper) (push) Successful in 32s
Build containers when image tags change / build-if-image-changed (data-loader, loader, initContainers, init-container, git.baumann.gr/adebaumann/labhelper-data-loader) (push) Successful in 7s
This commit is contained in:
187
boxes/templates/boxes/search.html
Normal file
187
boxes/templates/boxes/search.html
Normal file
@@ -0,0 +1,187 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Search - LabHelper</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
margin: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
.search-container {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 20px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 12px 15px;
|
||||
font-size: 16px;
|
||||
border: 2px solid #ddd;
|
||||
border-radius: 6px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: #4a90a4;
|
||||
}
|
||||
.search-hint {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
background: white;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
th, td {
|
||||
padding: 10px 12px;
|
||||
text-align: left;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
th {
|
||||
background-color: #4a90a4;
|
||||
color: white;
|
||||
font-weight: 600;
|
||||
}
|
||||
tr:hover {
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
a {
|
||||
color: #4a90a4;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.back-link {
|
||||
margin-bottom: 20px;
|
||||
display: inline-block;
|
||||
}
|
||||
.no-results {
|
||||
background: white;
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
border-radius: 8px;
|
||||
color: #666;
|
||||
}
|
||||
#results-container {
|
||||
display: none;
|
||||
}
|
||||
.description {
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
max-width: 300px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<a href="/" class="back-link">← Back to Home</a>
|
||||
|
||||
<h1>Search Things</h1>
|
||||
|
||||
<div class="search-container">
|
||||
<input type="text"
|
||||
id="search-input"
|
||||
class="search-input"
|
||||
placeholder="Search for things..."
|
||||
autocomplete="off">
|
||||
<div class="search-hint">Type at least 2 characters to search</div>
|
||||
</div>
|
||||
|
||||
<div id="results-container">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Box</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="results-body">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="no-results" class="no-results" style="display: none;">
|
||||
No results found.
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const resultsContainer = document.getElementById('results-container');
|
||||
const resultsBody = document.getElementById('results-body');
|
||||
const noResults = document.getElementById('no-results');
|
||||
|
||||
let searchTimeout = null;
|
||||
|
||||
searchInput.addEventListener('input', function() {
|
||||
const query = this.value.trim();
|
||||
|
||||
// Clear previous timeout
|
||||
if (searchTimeout) {
|
||||
clearTimeout(searchTimeout);
|
||||
}
|
||||
|
||||
// Hide results if query too short
|
||||
if (query.length < 2) {
|
||||
resultsContainer.style.display = 'none';
|
||||
noResults.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
|
||||
// Debounce search
|
||||
searchTimeout = setTimeout(function() {
|
||||
fetch('/search/api/?q=' + encodeURIComponent(query))
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
resultsBody.innerHTML = '';
|
||||
|
||||
if (data.results.length === 0) {
|
||||
resultsContainer.style.display = 'none';
|
||||
noResults.style.display = 'block';
|
||||
return;
|
||||
}
|
||||
|
||||
noResults.style.display = 'none';
|
||||
resultsContainer.style.display = 'block';
|
||||
|
||||
data.results.forEach(function(thing) {
|
||||
const row = document.createElement('tr');
|
||||
row.innerHTML =
|
||||
'<td><a href="/thing/' + thing.id + '/">' + escapeHtml(thing.name) + '</a></td>' +
|
||||
'<td>' + escapeHtml(thing.type) + '</td>' +
|
||||
'<td><a href="/box/' + escapeHtml(thing.box) + '/">' + escapeHtml(thing.box) + '</a></td>' +
|
||||
'<td class="description">' + escapeHtml(thing.description) + '</td>';
|
||||
resultsBody.appendChild(row);
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
|
||||
function escapeHtml(text) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = text;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Focus search input on page load
|
||||
searchInput.focus();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
131
boxes/templates/boxes/thing_detail.html
Normal file
131
boxes/templates/boxes/thing_detail.html
Normal file
@@ -0,0 +1,131 @@
|
||||
{% load thumbnail %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{{ thing.name }} - LabHelper</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
margin: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
h1 {
|
||||
color: #333;
|
||||
}
|
||||
.thing-card {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
}
|
||||
.thing-image {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.thing-image img {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.no-image {
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
background-color: #e0e0e0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #999;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.thing-details {
|
||||
flex-grow: 1;
|
||||
}
|
||||
.detail-row {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.detail-label {
|
||||
font-weight: 600;
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.detail-value {
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
}
|
||||
.detail-value a {
|
||||
color: #4a90a4;
|
||||
text-decoration: none;
|
||||
}
|
||||
.detail-value a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.description {
|
||||
white-space: pre-wrap;
|
||||
line-height: 1.5;
|
||||
}
|
||||
.back-link {
|
||||
margin-bottom: 20px;
|
||||
display: inline-block;
|
||||
color: #4a90a4;
|
||||
text-decoration: none;
|
||||
}
|
||||
.back-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.nav-links {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.nav-links a {
|
||||
margin-right: 15px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="nav-links">
|
||||
<a href="/" class="back-link">← Home</a>
|
||||
<a href="/search/" class="back-link">Search</a>
|
||||
<a href="/box/{{ thing.box.id }}/" class="back-link">Box {{ thing.box.id }}</a>
|
||||
</div>
|
||||
|
||||
<h1>{{ thing.name }}</h1>
|
||||
|
||||
<div class="thing-card">
|
||||
<div class="thing-image">
|
||||
{% if thing.picture %}
|
||||
{% thumbnail thing.picture "300x300" crop="center" as thumb %}
|
||||
<img src="{{ thumb.url }}" alt="{{ thing.name }}">
|
||||
{% endthumbnail %}
|
||||
{% else %}
|
||||
<div class="no-image">No image</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="thing-details">
|
||||
<div class="detail-row">
|
||||
<div class="detail-label">Type</div>
|
||||
<div class="detail-value">{{ thing.thing_type.name }}</div>
|
||||
</div>
|
||||
|
||||
<div class="detail-row">
|
||||
<div class="detail-label">Location</div>
|
||||
<div class="detail-value">
|
||||
<a href="/box/{{ thing.box.id }}/">Box {{ thing.box.id }}</a>
|
||||
({{ thing.box.box_type.name }})
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if thing.description %}
|
||||
<div class="detail-row">
|
||||
<div class="detail-label">Description</div>
|
||||
<div class="detail-value description">{{ thing.description }}</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user