mirror of
https://github.com/trevor1969/teatracker.git
synced 2026-08-09 10:41:59 +00:00
Compare commits
10 Commits
ff37d35134
...
v2.5
| Author | SHA1 | Date | |
|---|---|---|---|
| c628cf2069 | |||
| f111153bde | |||
| 0baceb14c6 | |||
| 91367a7198 | |||
| 7e1f52a5b2 | |||
| 7f059c9b4c | |||
| a16da66c2d | |||
| 073834a5dc | |||
| ac12cc5cab | |||
| 394480c516 |
263
app.js
263
app.js
@ -135,7 +135,8 @@ class NextcloudStorage {
|
|||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
return text ? JSON.parse(text) : null;
|
// Return empty array if file is empty, otherwise parse JSON
|
||||||
|
return text.trim() === '' ? [] : (text ? JSON.parse(text) : null);
|
||||||
} else if (response.status === 404) {
|
} else if (response.status === 404) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -225,8 +226,11 @@ class TeeTracker {
|
|||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
this.initStorage();
|
this.initStorage();
|
||||||
|
this.setupEventListeners();
|
||||||
this.loadData().then(() => {
|
this.loadData().then(() => {
|
||||||
this.init();
|
this.renderAll();
|
||||||
|
this.initCharts();
|
||||||
|
this.updateSettingsStats();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,25 +279,56 @@ class TeeTracker {
|
|||||||
await this.nextcloudStorage.ensureDirectory();
|
await this.nextcloudStorage.ensureDirectory();
|
||||||
|
|
||||||
// Check if old files exist in root directory and migrate to data/ directory
|
// Check if old files exist in root directory and migrate to data/ directory
|
||||||
await this.migrateToDataDirectory();
|
await this.nextcloudStorage.migrateToDataDirectory();
|
||||||
|
|
||||||
const teas = await this.nextcloudStorage.loadFile(DATA_DIRECTORY + 'teas.json');
|
const teas = await this.nextcloudStorage.loadFile(DATA_DIRECTORY + 'teas.json');
|
||||||
const entries = await this.nextcloudStorage.loadFile(DATA_DIRECTORY + 'entries.json');
|
const entries = await this.nextcloudStorage.loadFile(DATA_DIRECTORY + 'entries.json');
|
||||||
|
|
||||||
|
// Always load from localStorage first as backup
|
||||||
|
const localTeas = localStorage.getItem(STORAGE_KEY_TEAS);
|
||||||
|
const localEntries = localStorage.getItem(STORAGE_KEY_ENTRIES);
|
||||||
|
|
||||||
|
// Load from Nextcloud if available, otherwise use local data
|
||||||
if (teas) {
|
if (teas) {
|
||||||
this.teas = teas.map(tea => ({
|
this.teas = teas.map(tea => ({
|
||||||
...tea,
|
...tea,
|
||||||
organic: tea.organic !== undefined ? tea.organic : false
|
organic: tea.organic !== undefined ? tea.organic : false,
|
||||||
|
rating: tea.rating !== undefined ? tea.rating : 3
|
||||||
}));
|
}));
|
||||||
|
} else if (localTeas) {
|
||||||
|
// Nextcloud has no teas, use local data
|
||||||
|
try {
|
||||||
|
this.teas = JSON.parse(localTeas).map(tea => ({
|
||||||
|
...tea,
|
||||||
|
organic: tea.organic !== undefined ? tea.organic : false,
|
||||||
|
rating: tea.rating !== undefined ? tea.rating : 3
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading local teas:', error);
|
||||||
|
this.teas = [];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.teas = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entries) {
|
if (entries) {
|
||||||
this.entries = entries;
|
this.entries = entries.map(entry => ({
|
||||||
}
|
...entry,
|
||||||
|
teaspoons: entry.teaspoons !== undefined ? entry.teaspoons : 1
|
||||||
// If Nextcloud loading failed, fall back to localStorage
|
}));
|
||||||
if (!teas || !entries) {
|
} else if (localEntries) {
|
||||||
this.loadFromLocalStorage();
|
// Nextcloud has no entries, use local data
|
||||||
|
try {
|
||||||
|
this.entries = JSON.parse(localEntries).map(entry => ({
|
||||||
|
...entry,
|
||||||
|
teaspoons: entry.teaspoons !== undefined ? entry.teaspoons : 1
|
||||||
|
}));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading local entries:', error);
|
||||||
|
this.entries = [];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.entries = [];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Load from localStorage
|
// Load from localStorage
|
||||||
@ -309,7 +344,8 @@ class TeeTracker {
|
|||||||
try {
|
try {
|
||||||
this.teas = JSON.parse(teasData).map(tea => ({
|
this.teas = JSON.parse(teasData).map(tea => ({
|
||||||
...tea,
|
...tea,
|
||||||
organic: tea.organic !== undefined ? tea.organic : false
|
organic: tea.organic !== undefined ? tea.organic : false,
|
||||||
|
rating: tea.rating !== undefined ? tea.rating : 3
|
||||||
}));
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.teas = [];
|
this.teas = [];
|
||||||
@ -318,7 +354,10 @@ class TeeTracker {
|
|||||||
|
|
||||||
if (entriesData) {
|
if (entriesData) {
|
||||||
try {
|
try {
|
||||||
this.entries = JSON.parse(entriesData);
|
this.entries = JSON.parse(entriesData).map(entry => ({
|
||||||
|
...entry,
|
||||||
|
teaspoons: entry.teaspoons !== undefined ? entry.teaspoons : 1
|
||||||
|
}));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.entries = [];
|
this.entries = [];
|
||||||
}
|
}
|
||||||
@ -413,6 +452,8 @@ class TeeTracker {
|
|||||||
description: tea.description || '',
|
description: tea.description || '',
|
||||||
color: tea.color || '#8B4513',
|
color: tea.color || '#8B4513',
|
||||||
organic: tea.organic || false,
|
organic: tea.organic || false,
|
||||||
|
rating: tea.rating || 3,
|
||||||
|
image: tea.image || '',
|
||||||
createdAt: new Date().toISOString()
|
createdAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
this.teas.push(newTea);
|
this.teas.push(newTea);
|
||||||
@ -452,6 +493,7 @@ class TeeTracker {
|
|||||||
date: entry.date,
|
date: entry.date,
|
||||||
time: entry.time || '',
|
time: entry.time || '',
|
||||||
amount: parseInt(entry.amount) || 1,
|
amount: parseInt(entry.amount) || 1,
|
||||||
|
teaspoons: entry.teaspoons ? parseFloat(entry.teaspoons) : 1,
|
||||||
notes: entry.notes || '',
|
notes: entry.notes || '',
|
||||||
createdAt: new Date().toISOString()
|
createdAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
@ -592,7 +634,8 @@ class TeeTracker {
|
|||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this.setupEventListeners();
|
// Initialization is now handled in constructor
|
||||||
|
// This method is kept for backward compatibility
|
||||||
this.renderAll();
|
this.renderAll();
|
||||||
this.initCharts();
|
this.initCharts();
|
||||||
this.updateSettingsStats();
|
this.updateSettingsStats();
|
||||||
@ -609,6 +652,23 @@ class TeeTracker {
|
|||||||
document.getElementById('add-tea-btn').addEventListener('click', () => this.openTeaModal());
|
document.getElementById('add-tea-btn').addEventListener('click', () => this.openTeaModal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Event delegation for tea action buttons (edit/delete)
|
||||||
|
const teasListContainer = document.getElementById('teas-list');
|
||||||
|
if (teasListContainer) {
|
||||||
|
teasListContainer.addEventListener('click', (e) => {
|
||||||
|
const editBtn = e.target.closest('.tea-edit-btn');
|
||||||
|
const deleteBtn = e.target.closest('.tea-delete-btn');
|
||||||
|
|
||||||
|
if (editBtn) {
|
||||||
|
const teaId = editBtn.dataset.teaId;
|
||||||
|
if (teaId) this.editTea(teaId);
|
||||||
|
} else if (deleteBtn) {
|
||||||
|
const teaId = deleteBtn.dataset.teaId;
|
||||||
|
if (teaId) this.showDeleteTeaConfirm(teaId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Tea modal
|
// Tea modal
|
||||||
if (document.getElementById('close-modal')) {
|
if (document.getElementById('close-modal')) {
|
||||||
document.getElementById('close-modal').addEventListener('click', () => this.closeTeaModal());
|
document.getElementById('close-modal').addEventListener('click', () => this.closeTeaModal());
|
||||||
@ -620,6 +680,18 @@ class TeeTracker {
|
|||||||
document.getElementById('delete-tea-btn').addEventListener('click', () => this.handleDeleteTea());
|
document.getElementById('delete-tea-btn').addEventListener('click', () => this.handleDeleteTea());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Star rating for tea form
|
||||||
|
const teaRating = document.getElementById('tea-rating');
|
||||||
|
if (teaRating) {
|
||||||
|
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());
|
||||||
@ -926,30 +998,6 @@ class TeeTracker {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing data from localStorage before switching to Nextcloud
|
|
||||||
// This prevents data loss when connecting to Nextcloud for the first time
|
|
||||||
const existingTeas = localStorage.getItem(STORAGE_KEY_TEAS);
|
|
||||||
const existingEntries = localStorage.getItem(STORAGE_KEY_ENTRIES);
|
|
||||||
|
|
||||||
if (existingTeas) {
|
|
||||||
try {
|
|
||||||
this.teas = JSON.parse(existingTeas).map(tea => ({
|
|
||||||
...tea,
|
|
||||||
organic: tea.organic !== undefined ? tea.organic : false
|
|
||||||
}));
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading existing teas:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existingEntries) {
|
|
||||||
try {
|
|
||||||
this.entries = JSON.parse(existingEntries);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading existing entries:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save config WITHOUT password for security
|
// Save config WITHOUT password for security
|
||||||
// Password will be requested each time or stored in sessionStorage
|
// Password will be requested each time or stored in sessionStorage
|
||||||
const config = { baseUrl: url, username, path };
|
const config = { baseUrl: url, username, path };
|
||||||
@ -962,8 +1010,38 @@ class TeeTracker {
|
|||||||
this.nextcloudStorage = ncStorage;
|
this.nextcloudStorage = ncStorage;
|
||||||
this.useNextcloud = true;
|
this.useNextcloud = true;
|
||||||
|
|
||||||
// Save current data to Nextcloud
|
// Load data from Nextcloud first (this is the critical fix!)
|
||||||
await this.saveData();
|
// This will automatically fall back to localStorage if Nextcloud has no data
|
||||||
|
await this.loadData();
|
||||||
|
|
||||||
|
// Only save to Nextcloud if we actually have data to save
|
||||||
|
// This prevents overwriting existing Nextcloud data with empty arrays
|
||||||
|
if (this.teas.length > 0 || this.entries.length > 0) {
|
||||||
|
await this.saveData();
|
||||||
|
} else {
|
||||||
|
// No data to save, but check if Nextcloud has existing data
|
||||||
|
const existingTeas = await ncStorage.loadFile(DATA_DIRECTORY + 'teas.json');
|
||||||
|
const existingEntries = await ncStorage.loadFile(DATA_DIRECTORY + 'entries.json');
|
||||||
|
|
||||||
|
// If Nextcloud has data, keep it and load it
|
||||||
|
if (existingTeas || existingEntries) {
|
||||||
|
if (existingTeas) {
|
||||||
|
this.teas = existingTeas.map(tea => ({
|
||||||
|
...tea,
|
||||||
|
organic: tea.organic !== undefined ? tea.organic : false,
|
||||||
|
rating: tea.rating !== undefined ? tea.rating : 3
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (existingEntries) {
|
||||||
|
this.entries = existingEntries.map(entry => ({
|
||||||
|
...entry,
|
||||||
|
teaspoons: entry.teaspoons !== undefined ? entry.teaspoons : 1
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
// Don't save, just use the existing Nextcloud data
|
||||||
|
}
|
||||||
|
// If Nextcloud has no data and we have no data, nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
this.showStatusMessage('✅ Konfiguration gespeichert und Daten synchronisiert!', 'success');
|
this.showStatusMessage('✅ Konfiguration gespeichert und Daten synchronisiert!', 'success');
|
||||||
} else {
|
} else {
|
||||||
@ -1207,7 +1285,7 @@ class TeeTracker {
|
|||||||
<div class="activity-tea">${tea ? tea.name : 'Unbekannter Tee'} ${tea && tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</div>
|
<div class="activity-tea">${tea ? tea.name : 'Unbekannter Tee'} ${tea && tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</div>
|
||||||
<div class="activity-details">${formattedDate} ${formattedTime ? `um ${formattedTime}` : ''}</div>
|
<div class="activity-details">${formattedDate} ${formattedTime ? `um ${formattedTime}` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="activity-amount">${entry.amount} Tasse${entry.amount > 1 ? 'n' : ''}</div>
|
<div class="activity-amount">${entry.amount} Tasse${entry.amount > 1 ? 'n' : ''}${entry.teaspoons ? ` (${entry.teaspoons} TL)` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
@ -1236,15 +1314,19 @@ class TeeTracker {
|
|||||||
<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>
|
<div>
|
||||||
<h3 class="tea-name">${tea.name} ${tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</h3>
|
${tea.image ? `<img src="${tea.image}" class="tea-image" alt="${tea.name}">` : ''}
|
||||||
<span class="tea-type">${tea.type}</span>
|
<div>
|
||||||
|
<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>
|
||||||
|
<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">
|
||||||
<button class="tea-action-btn tea-edit-btn" onclick="window.app.editTea('${tea.id}')">Bearbeiten</button>
|
<button class="tea-action-btn tea-edit-btn" data-tea-id="${tea.id}" data-action="edit">Bearbeiten</button>
|
||||||
<button class="tea-action-btn tea-delete-btn" onclick="window.app.showDeleteTeaConfirm('${tea.id}')">Löschen</button>
|
<button class="tea-action-btn tea-delete-btn" data-tea-id="${tea.id}" data-action="delete">Löschen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
@ -1280,15 +1362,19 @@ class TeeTracker {
|
|||||||
<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>
|
<div>
|
||||||
<h3 class="tea-name">${tea.name} ${tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</h3>
|
${tea.image ? `<img src="${tea.image}" class="tea-image" alt="${tea.name}">` : ''}
|
||||||
<span class="tea-type">${tea.type}</span>
|
<div>
|
||||||
|
<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>
|
||||||
|
<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">
|
||||||
<button class="tea-action-btn tea-edit-btn" onclick="window.app.editTea('${tea.id}')">Bearbeiten</button>
|
<button class="tea-action-btn tea-edit-btn" data-tea-id="${tea.id}" data-action="edit">Bearbeiten</button>
|
||||||
<button class="tea-action-btn tea-delete-btn" onclick="window.app.showDeleteTeaConfirm('${tea.id}')">Löschen</button>
|
<button class="tea-action-btn tea-delete-btn" data-tea-id="${tea.id}" data-action="delete">Löschen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
@ -1312,6 +1398,17 @@ class TeeTracker {
|
|||||||
document.getElementById('tea-description').value = tea.description || '';
|
document.getElementById('tea-description').value = tea.description || '';
|
||||||
document.getElementById('tea-color').value = tea.color || '#8B4513';
|
document.getElementById('tea-color').value = tea.color || '#8B4513';
|
||||||
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;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -1319,6 +1416,11 @@ class TeeTracker {
|
|||||||
document.getElementById('modal-title').textContent = 'Tee hinzufügen';
|
document.getElementById('modal-title').textContent = 'Tee hinzufügen';
|
||||||
form.reset();
|
form.reset();
|
||||||
document.getElementById('tea-id').value = '';
|
document.getElementById('tea-id').value = '';
|
||||||
|
document.getElementById('tea-rating-value').value = 3;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -1345,7 +1447,9 @@ class TeeTracker {
|
|||||||
brand: document.getElementById('tea-brand').value.trim(),
|
brand: document.getElementById('tea-brand').value.trim(),
|
||||||
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,
|
||||||
|
image: document.getElementById('tea-image-data').value || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const teaId = document.getElementById('tea-id').value;
|
const teaId = document.getElementById('tea-id').value;
|
||||||
@ -1366,6 +1470,63 @@ class TeeTracker {
|
|||||||
this.updateSettingsStats();
|
this.updateSettingsStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleStarRatingClick(e) {
|
||||||
|
const star = e.target.closest('.star');
|
||||||
|
if (!star) return;
|
||||||
|
|
||||||
|
const value = parseInt(star.dataset.value);
|
||||||
|
const ratingContainer = document.getElementById('tea-rating');
|
||||||
|
const ratingInput = document.getElementById('tea-rating-value');
|
||||||
|
|
||||||
|
if (ratingContainer && ratingInput) {
|
||||||
|
// Update active stars
|
||||||
|
ratingContainer.querySelectorAll('.star').forEach((s, index) => {
|
||||||
|
s.classList.toggle('active', index < value);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set the hidden input value
|
||||||
|
ratingInput.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
const container = document.getElementById(containerId);
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
const stars = [];
|
||||||
|
for (let i = 1; i <= 5; i++) {
|
||||||
|
stars.push(`<span class="star ${i <= rating ? 'active' : ''}" data-value="${i}">★</span>`);
|
||||||
|
}
|
||||||
|
container.innerHTML = stars.join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
renderStarRatingStatic(rating) {
|
||||||
|
const stars = [];
|
||||||
|
for (let i = 1; i <= 5; i++) {
|
||||||
|
stars.push(`<span class="star ${i <= rating ? 'active' : ''}">★</span>`);
|
||||||
|
}
|
||||||
|
return stars.join('');
|
||||||
|
}
|
||||||
|
|
||||||
editTea(teaId) {
|
editTea(teaId) {
|
||||||
this.openTeaModal(teaId);
|
this.openTeaModal(teaId);
|
||||||
}
|
}
|
||||||
@ -1454,6 +1615,7 @@ class TeeTracker {
|
|||||||
const date = document.getElementById('track-date').value;
|
const date = document.getElementById('track-date').value;
|
||||||
const time = document.getElementById('track-time').value;
|
const time = document.getElementById('track-time').value;
|
||||||
const amount = document.getElementById('track-amount').value;
|
const amount = document.getElementById('track-amount').value;
|
||||||
|
const teaspoons = document.getElementById('track-teaspoons').value;
|
||||||
const notes = document.getElementById('track-notes').value.trim();
|
const notes = document.getElementById('track-notes').value.trim();
|
||||||
|
|
||||||
if (!teaId || !date || !amount) {
|
if (!teaId || !date || !amount) {
|
||||||
@ -1466,6 +1628,7 @@ class TeeTracker {
|
|||||||
date,
|
date,
|
||||||
time,
|
time,
|
||||||
amount,
|
amount,
|
||||||
|
teaspoons,
|
||||||
notes
|
notes
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1521,7 +1684,7 @@ class TeeTracker {
|
|||||||
<div class="activity-tea">${tea ? tea.name : 'Unbekannter Tee'} ${tea && tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</div>
|
<div class="activity-tea">${tea ? tea.name : 'Unbekannter Tee'} ${tea && tea.organic ? '<span class="organic-badge" title="Bio-Tee">🌱</span>' : ''}</div>
|
||||||
<div class="activity-details">${formattedDate} ${formattedTime ? `um ${formattedTime}` : ''}</div>
|
<div class="activity-details">${formattedDate} ${formattedTime ? `um ${formattedTime}` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="activity-amount">${entry.amount} Tasse${entry.amount > 1 ? 'n' : ''}</div>
|
<div class="activity-amount">${entry.amount} Tasse${entry.amount > 1 ? 'n' : ''}${entry.teaspoons ? ` (${entry.teaspoons} TL)` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
|
|||||||
63
index.html
63
index.html
@ -101,6 +101,11 @@
|
|||||||
<input type="number" id="track-amount" min="1" max="10" value="1" required>
|
<input type="number" id="track-amount" min="1" max="10" value="1" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="track-teaspoons">Menge Tee-Pulver (Teelöffel)</label>
|
||||||
|
<input type="number" id="track-teaspoons" min="0" max="10" value="1" step="0.5">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="track-notes">Notizen</label>
|
<label for="track-notes">Notizen</label>
|
||||||
<textarea id="track-notes" rows="3" placeholder="z.B. Mit Honig, besonders stark..."></textarea>
|
<textarea id="track-notes" rows="3" placeholder="z.B. Mit Honig, besonders stark..."></textarea>
|
||||||
@ -176,6 +181,39 @@
|
|||||||
<button id="export-data" class="btn btn-secondary">📤 Daten exportieren</button>
|
<button id="export-data" class="btn btn-secondary">📤 Daten exportieren</button>
|
||||||
<button id="import-data" class="btn btn-secondary">📥 Daten importieren</button>
|
<button id="import-data" class="btn btn-secondary">📥 Daten importieren</button>
|
||||||
<button id="clear-data" class="btn btn-danger">🗑️ Alle Daten löschen</button>
|
<button id="clear-data" class="btn btn-danger">🗑️ Alle Daten löschen</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settings-section">
|
||||||
|
<h3>🎨 Hintergrundbild</h3>
|
||||||
|
<p>Wähle ein Hintergrundbild für deine TeeTracker-App.</p>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="bg-image-upload">Hintergrundbild hochladen:</label>
|
||||||
|
<input type="file" id="bg-image-upload" accept="image/*">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="bg-image-preview">Vorschau:</label>
|
||||||
|
<div id="bg-image-preview" class="bg-preview" style="display: none;">
|
||||||
|
<img id="bg-preview-img" style="max-width: 200px; max-height: 150px; border-radius: 8px; margin-top: 10px;">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group checkbox-group">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="bg-enabled">
|
||||||
|
<span class="checkmark"></span>
|
||||||
|
Hintergrundbild aktivieren
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<button id="remove-bg" class="btn btn-secondary" style="display: none;">🗑️ Hintergrund entfernen</button>
|
||||||
|
<button id="save-bg" class="btn btn-primary">💾 Hintergrund speichern</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -285,6 +323,27 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Bewertung</label>
|
||||||
|
<div class="star-rating" id="tea-rating">
|
||||||
|
<span class="star" data-value="1">★</span>
|
||||||
|
<span class="star" data-value="2">★</span>
|
||||||
|
<span class="star" data-value="3">★</span>
|
||||||
|
<span class="star" data-value="4">★</span>
|
||||||
|
<span class="star" data-value="5">★</span>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" id="tea-rating-value" value="3">
|
||||||
|
</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">
|
||||||
@ -327,8 +386,8 @@
|
|||||||
<textarea id="import-data-textarea" class="modal-textarea" placeholder="{\n \"teas\": [...],\n \"entries\": [...]\n}"></textarea>
|
<textarea id="import-data-textarea" class="modal-textarea" placeholder="{\n \"teas\": [...],\n \"entries\": [...]\n}"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button id="import-data-btn" class="btn btn-primary" onclick="window.app.handleImportData()">📥 Importieren</button>
|
<button id="import-data-btn" class="btn btn-primary">📥 Importieren</button>
|
||||||
<button id="cancel-import-btn" class="btn btn-secondary" onclick="window.app.closeImportModal()">Abbrechen</button>
|
<button id="cancel-import-btn" class="btn btn-secondary">Abbrechen</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
65
styles.css
65
styles.css
@ -971,3 +971,68 @@ header p {
|
|||||||
z-index: -1;
|
z-index: -1;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Star Rating */
|
||||||
|
.star-rating {
|
||||||
|
display: flex;
|
||||||
|
gap: 5px;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.star-rating .star {
|
||||||
|
color: #ccc;
|
||||||
|
transition: color 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.star-rating .star:hover,
|
||||||
|
.star-rating .star.active {
|
||||||
|
color: #FFD700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.star-rating .star:hover ~ .star {
|
||||||
|
color: #ccc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rating display on tea cards */
|
||||||
|
.rating-display {
|
||||||
|
color: #FFD700;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rating display on tea cards */
|
||||||
|
.tea-rating-display {
|
||||||
|
display: inline-block;
|
||||||
|
margin-left: 8px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tea-rating-display .star {
|
||||||
|
color: #FFD700;
|
||||||
|
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