mirror of
https://github.com/trevor1969/teatracker.git
synced 2026-08-09 10:41:59 +00:00
feat: Add image upload for tea varieties
- Add image upload field to tea form with preview - Add image property to tea data model - Update addTea() to include image data (base64) - Update openTeaModal() to display image when editing - Display tea images on tea cards - Add handleImageUpload() method for file processing - Add migration for existing teas without image field - Add CSS styles for image preview and display on cards - Images stored as base64 in localStorage/Nextcloud Co-authored-by: trevor1969 <trevor1969@users.noreply.github.com>
This commit is contained in:
47
app.js
47
app.js
@ -422,6 +422,7 @@ class TeeTracker {
|
|||||||
color: tea.color || '#8B4513',
|
color: tea.color || '#8B4513',
|
||||||
organic: tea.organic || false,
|
organic: tea.organic || false,
|
||||||
rating: tea.rating || 3,
|
rating: tea.rating || 3,
|
||||||
|
image: tea.image || '',
|
||||||
createdAt: new Date().toISOString()
|
createdAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
this.teas.push(newTea);
|
this.teas.push(newTea);
|
||||||
@ -636,6 +637,12 @@ class TeeTracker {
|
|||||||
teaRating.addEventListener('click', (e) => this.handleStarRatingClick(e));
|
teaRating.addEventListener('click', (e) => this.handleStarRatingClick(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tea image upload
|
||||||
|
const teaImageUpload = document.getElementById('tea-image-upload');
|
||||||
|
if (teaImageUpload) {
|
||||||
|
teaImageUpload.addEventListener('change', (e) => this.handleImageUpload(e));
|
||||||
|
}
|
||||||
|
|
||||||
// Confirm modal
|
// Confirm modal
|
||||||
if (document.getElementById('close-confirm')) {
|
if (document.getElementById('close-confirm')) {
|
||||||
document.getElementById('close-confirm').addEventListener('click', () => this.closeConfirmModal());
|
document.getElementById('close-confirm').addEventListener('click', () => this.closeConfirmModal());
|
||||||
@ -1251,12 +1258,15 @@ class TeeTracker {
|
|||||||
container.innerHTML = this.teas.map(tea => `
|
container.innerHTML = this.teas.map(tea => `
|
||||||
<div class="tea-card" data-id="${tea.id}">
|
<div class="tea-card" data-id="${tea.id}">
|
||||||
<div class="tea-card-header">
|
<div class="tea-card-header">
|
||||||
|
<div>
|
||||||
|
${tea.image ? `<img src="${tea.image}" class="tea-image" alt="${tea.name}">` : ''}
|
||||||
<div>
|
<div>
|
||||||
<h3 class="tea-name">${tea.name} ${tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</h3>
|
<h3 class="tea-name">${tea.name} ${tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</h3>
|
||||||
<div class="tea-rating-display">${this.renderStarRatingStatic(tea.rating || 3)}</div>
|
<div class="tea-rating-display">${this.renderStarRatingStatic(tea.rating || 3)}</div>
|
||||||
<span class="tea-type">${tea.type}</span>
|
<span class="tea-type">${tea.type}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
${tea.brand ? `<div class="tea-brand">Marke: ${tea.brand}</div>` : ''}
|
${tea.brand ? `<div class="tea-brand">Marke: ${tea.brand}</div>` : ''}
|
||||||
${tea.description ? `<div class="tea-description">${tea.description}</div>` : ''}
|
${tea.description ? `<div class="tea-description">${tea.description}</div>` : ''}
|
||||||
<div class="tea-actions">
|
<div class="tea-actions">
|
||||||
@ -1296,12 +1306,15 @@ class TeeTracker {
|
|||||||
container.innerHTML = filteredTeas.map(tea => `
|
container.innerHTML = filteredTeas.map(tea => `
|
||||||
<div class="tea-card" data-id="${tea.id}">
|
<div class="tea-card" data-id="${tea.id}">
|
||||||
<div class="tea-card-header">
|
<div class="tea-card-header">
|
||||||
|
<div>
|
||||||
|
${tea.image ? `<img src="${tea.image}" class="tea-image" alt="${tea.name}">` : ''}
|
||||||
<div>
|
<div>
|
||||||
<h3 class="tea-name">${tea.name} ${tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</h3>
|
<h3 class="tea-name">${tea.name} ${tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</h3>
|
||||||
<div class="tea-rating-display">${this.renderStarRatingStatic(tea.rating || 3)}</div>
|
<div class="tea-rating-display">${this.renderStarRatingStatic(tea.rating || 3)}</div>
|
||||||
<span class="tea-type">${tea.type}</span>
|
<span class="tea-type">${tea.type}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
${tea.brand ? `<div class="tea-brand">Marke: ${tea.brand}</div>` : ''}
|
${tea.brand ? `<div class="tea-brand">Marke: ${tea.brand}</div>` : ''}
|
||||||
${tea.description ? `<div class="tea-description">${tea.description}</div>` : ''}
|
${tea.description ? `<div class="tea-description">${tea.description}</div>` : ''}
|
||||||
<div class="tea-actions">
|
<div class="tea-actions">
|
||||||
@ -1332,6 +1345,15 @@ class TeeTracker {
|
|||||||
document.getElementById('tea-organic').checked = tea.organic || false;
|
document.getElementById('tea-organic').checked = tea.organic || false;
|
||||||
document.getElementById('tea-rating-value').value = tea.rating || 3;
|
document.getElementById('tea-rating-value').value = tea.rating || 3;
|
||||||
this.renderStarRating(tea.rating || 3, 'tea-rating');
|
this.renderStarRating(tea.rating || 3, 'tea-rating');
|
||||||
|
if (tea.image) {
|
||||||
|
document.getElementById('tea-image-data').value = tea.image;
|
||||||
|
document.getElementById('tea-image-preview-img').src = tea.image;
|
||||||
|
document.getElementById('tea-image-preview').style.display = 'block';
|
||||||
|
} else {
|
||||||
|
document.getElementById('tea-image-data').value = '';
|
||||||
|
document.getElementById('tea-image-preview-img').src = '';
|
||||||
|
document.getElementById('tea-image-preview').style.display = 'none';
|
||||||
|
}
|
||||||
deleteBtn.style.display = 'inline-flex';
|
deleteBtn.style.display = 'inline-flex';
|
||||||
this.currentTeaId = tea.id;
|
this.currentTeaId = tea.id;
|
||||||
}
|
}
|
||||||
@ -1341,6 +1363,9 @@ class TeeTracker {
|
|||||||
document.getElementById('tea-id').value = '';
|
document.getElementById('tea-id').value = '';
|
||||||
document.getElementById('tea-rating-value').value = 3;
|
document.getElementById('tea-rating-value').value = 3;
|
||||||
this.renderStarRating(3, 'tea-rating');
|
this.renderStarRating(3, 'tea-rating');
|
||||||
|
document.getElementById('tea-image-data').value = '';
|
||||||
|
document.getElementById('tea-image-preview-img').src = '';
|
||||||
|
document.getElementById('tea-image-preview').style.display = 'none';
|
||||||
deleteBtn.style.display = 'none';
|
deleteBtn.style.display = 'none';
|
||||||
this.currentTeaId = null;
|
this.currentTeaId = null;
|
||||||
}
|
}
|
||||||
@ -1368,7 +1393,8 @@ class TeeTracker {
|
|||||||
description: document.getElementById('tea-description').value.trim(),
|
description: document.getElementById('tea-description').value.trim(),
|
||||||
color: document.getElementById('tea-color').value,
|
color: document.getElementById('tea-color').value,
|
||||||
organic: document.getElementById('tea-organic').checked,
|
organic: document.getElementById('tea-organic').checked,
|
||||||
rating: parseInt(document.getElementById('tea-rating-value').value) || 3
|
rating: parseInt(document.getElementById('tea-rating-value').value) || 3,
|
||||||
|
image: document.getElementById('tea-image-data').value || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const teaId = document.getElementById('tea-id').value;
|
const teaId = document.getElementById('tea-id').value;
|
||||||
@ -1408,6 +1434,25 @@ class TeeTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleImageUpload(e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file || !file.type.startsWith('image/')) return;
|
||||||
|
|
||||||
|
const preview = document.getElementById('tea-image-preview-img');
|
||||||
|
const previewContainer = document.getElementById('tea-image-preview');
|
||||||
|
const imageDataInput = document.getElementById('tea-image-data');
|
||||||
|
|
||||||
|
if (preview && previewContainer && imageDataInput) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
preview.src = event.target.result;
|
||||||
|
previewContainer.style.display = 'block';
|
||||||
|
imageDataInput.value = event.target.result;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderStarRating(rating, containerId) {
|
renderStarRating(rating, containerId) {
|
||||||
const container = document.getElementById(containerId);
|
const container = document.getElementById(containerId);
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
|||||||
@ -302,6 +302,15 @@
|
|||||||
<input type="hidden" id="tea-rating-value" value="3">
|
<input type="hidden" id="tea-rating-value" value="3">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="tea-image-upload">Tee-Foto</label>
|
||||||
|
<input type="file" id="tea-image-upload" accept="image/*">
|
||||||
|
<div id="tea-image-preview" class="image-preview" style="display: none; margin-top: 10px;">
|
||||||
|
<img id="tea-image-preview-img" style="max-width: 150px; max-height: 150px; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.2);">
|
||||||
|
</div>
|
||||||
|
<input type="hidden" id="tea-image-data" value="">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="tea-color">Farbe</label>
|
<label for="tea-color">Farbe</label>
|
||||||
<input type="color" id="tea-color" value="#8B4513">
|
<input type="color" id="tea-color" value="#8B4513">
|
||||||
|
|||||||
23
styles.css
23
styles.css
@ -1013,3 +1013,26 @@ header p {
|
|||||||
color: #FFD700;
|
color: #FFD700;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Image Upload Preview */
|
||||||
|
.image-preview {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-preview img {
|
||||||
|
max-width: 150px;
|
||||||
|
max-height: 150px;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tea card image */
|
||||||
|
.tea-image {
|
||||||
|
width: 60px;
|
||||||
|
height: 60px;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
object-fit: cover;
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user