mirror of
https://github.com/trevor1969/teatracker.git
synced 2026-08-09 18:51:59 +00:00
Compare commits
7 Commits
v1.1.0
...
a16da66c2d
| Author | SHA1 | Date | |
|---|---|---|---|
| a16da66c2d | |||
| 073834a5dc | |||
| ac12cc5cab | |||
| 394480c516 | |||
| ff37d35134 | |||
| 4f8890da7f | |||
| 733e2db3c4 |
306
app.js
306
app.js
@ -8,6 +8,9 @@ const STORAGE_KEY_TEAS = 'teatracker_teas';
|
|||||||
const STORAGE_KEY_ENTRIES = 'teatracker_entries';
|
const STORAGE_KEY_ENTRIES = 'teatracker_entries';
|
||||||
const STORAGE_KEY_NC_CONFIG = 'teatracker_nextcloud_config';
|
const STORAGE_KEY_NC_CONFIG = 'teatracker_nextcloud_config';
|
||||||
|
|
||||||
|
// Data directory for Nextcloud storage
|
||||||
|
const DATA_DIRECTORY = 'data/';
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Nextcloud Storage Integration
|
// Nextcloud Storage Integration
|
||||||
// ============================================
|
// ============================================
|
||||||
@ -63,12 +66,44 @@ class NextcloudStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Migrate old files from root to data/ directory
|
||||||
|
async migrateToDataDirectory() {
|
||||||
|
try {
|
||||||
|
// Check if old teas.json exists in root
|
||||||
|
const oldTeasUrl = this.getFileUrl('teas.json');
|
||||||
|
const oldTeasResponse = await fetch(oldTeasUrl, {
|
||||||
|
headers: { 'Authorization': this.authHeader }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (oldTeasResponse.ok) {
|
||||||
|
const oldTeas = await oldTeasResponse.json();
|
||||||
|
await this.saveFile(DATA_DIRECTORY + 'teas.json', oldTeas);
|
||||||
|
console.log('Migrated teas.json to data/ directory');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if old entries.json exists in root
|
||||||
|
const oldEntriesUrl = this.getFileUrl('entries.json');
|
||||||
|
const oldEntriesResponse = await fetch(oldEntriesUrl, {
|
||||||
|
headers: { 'Authorization': this.authHeader }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (oldEntriesResponse.ok) {
|
||||||
|
const oldEntries = await oldEntriesResponse.json();
|
||||||
|
await this.saveFile(DATA_DIRECTORY + 'entries.json', oldEntries);
|
||||||
|
console.log('Migrated entries.json to data/ directory');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log('No old files to migrate or migration failed:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
async ensureDirectory() {
|
async ensureDirectory() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.getDirectoryUrl(), {
|
const response = await fetch(this.getDirectoryUrl(), {
|
||||||
method: 'MKCOL',
|
method: 'MKCOL',
|
||||||
headers: { 'Authorization': this.authHeader }
|
headers: { 'Authorization': this.authHeader }
|
||||||
});
|
});
|
||||||
|
await this.ensureSubDirectory('data');
|
||||||
await this.ensureSubDirectory('backup');
|
await this.ensureSubDirectory('backup');
|
||||||
return response.ok || response.status === 405;
|
return response.ok || response.status === 405;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -144,6 +179,7 @@ class NextcloudStorage {
|
|||||||
|
|
||||||
async createBackup(backupName, teas, entries) {
|
async createBackup(backupName, teas, entries) {
|
||||||
try {
|
try {
|
||||||
|
await this.ensureSubDirectory('data');
|
||||||
await this.ensureSubDirectory('backup');
|
await this.ensureSubDirectory('backup');
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||||
const backupData = { timestamp, teas, entries };
|
const backupData = { timestamp, teas, entries };
|
||||||
@ -185,6 +221,7 @@ class TeeTracker {
|
|||||||
this.entries = [];
|
this.entries = [];
|
||||||
this.currentTeaId = null;
|
this.currentTeaId = null;
|
||||||
this.charts = {};
|
this.charts = {};
|
||||||
|
this.currentBgImage = null;
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
this.initStorage();
|
this.initStorage();
|
||||||
@ -237,18 +274,25 @@ class TeeTracker {
|
|||||||
// Try to load from Nextcloud first
|
// Try to load from Nextcloud first
|
||||||
await this.nextcloudStorage.ensureDirectory();
|
await this.nextcloudStorage.ensureDirectory();
|
||||||
|
|
||||||
const teas = await this.nextcloudStorage.loadFile('teas.json');
|
// Check if old files exist in root directory and migrate to data/ directory
|
||||||
const entries = await this.nextcloudStorage.loadFile('entries.json');
|
await this.migrateToDataDirectory();
|
||||||
|
|
||||||
|
const teas = await this.nextcloudStorage.loadFile(DATA_DIRECTORY + 'teas.json');
|
||||||
|
const entries = await this.nextcloudStorage.loadFile(DATA_DIRECTORY + 'entries.json');
|
||||||
|
|
||||||
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
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
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 Nextcloud loading failed, fall back to localStorage
|
||||||
@ -269,7 +313,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 = [];
|
||||||
@ -278,7 +323,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 = [];
|
||||||
}
|
}
|
||||||
@ -294,8 +342,8 @@ class TeeTracker {
|
|||||||
await this.nextcloudStorage.ensureDirectory();
|
await this.nextcloudStorage.ensureDirectory();
|
||||||
|
|
||||||
// Save to Nextcloud
|
// Save to Nextcloud
|
||||||
const teasSaved = await this.nextcloudStorage.saveFile('teas.json', this.teas);
|
const teasSaved = await this.nextcloudStorage.saveFile(DATA_DIRECTORY + 'teas.json', this.teas);
|
||||||
const entriesSaved = await this.nextcloudStorage.saveFile('entries.json', this.entries);
|
const entriesSaved = await this.nextcloudStorage.saveFile(DATA_DIRECTORY + 'entries.json', this.entries);
|
||||||
|
|
||||||
// Also save locally as backup
|
// Also save locally as backup
|
||||||
this.saveToLocalStorage();
|
this.saveToLocalStorage();
|
||||||
@ -373,6 +421,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);
|
||||||
@ -412,6 +462,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()
|
||||||
};
|
};
|
||||||
@ -580,6 +631,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());
|
||||||
@ -625,6 +688,9 @@ class TeeTracker {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Background image settings
|
||||||
|
this.setupBackgroundListeners();
|
||||||
|
|
||||||
// Nextcloud settings
|
// Nextcloud settings
|
||||||
this.setupNextcloudListeners();
|
this.setupNextcloudListeners();
|
||||||
}
|
}
|
||||||
@ -717,6 +783,111 @@ class TeeTracker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupBackgroundListeners() {
|
||||||
|
// Background image upload
|
||||||
|
const bgUpload = document.getElementById('bg-image-upload');
|
||||||
|
if (bgUpload) {
|
||||||
|
bgUpload.addEventListener('change', (e) => this.handleBackgroundUpload(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Background enable toggle
|
||||||
|
const bgEnabled = document.getElementById('bg-enabled');
|
||||||
|
if (bgEnabled) {
|
||||||
|
bgEnabled.addEventListener('change', () => this.toggleBackground());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save background button
|
||||||
|
const saveBgBtn = document.getElementById('save-bg');
|
||||||
|
if (saveBgBtn) {
|
||||||
|
saveBgBtn.addEventListener('click', () => this.saveBackgroundSettings());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove background button
|
||||||
|
const removeBgBtn = document.getElementById('remove-bg');
|
||||||
|
if (removeBgBtn) {
|
||||||
|
removeBgBtn.addEventListener('click', () => this.removeBackground());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load saved background settings
|
||||||
|
this.loadBackgroundSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleBackgroundUpload(e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (!file) return;
|
||||||
|
|
||||||
|
const preview = document.getElementById('bg-preview-img');
|
||||||
|
const previewContainer = document.getElementById('bg-image-preview');
|
||||||
|
const removeBtn = document.getElementById('remove-bg');
|
||||||
|
|
||||||
|
if (file.type.startsWith('image/')) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = (event) => {
|
||||||
|
preview.src = event.target.result;
|
||||||
|
previewContainer.style.display = 'block';
|
||||||
|
removeBtn.style.display = 'inline-flex';
|
||||||
|
this.currentBgImage = event.target.result;
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleBackground() {
|
||||||
|
const enabled = document.getElementById('bg-enabled').checked;
|
||||||
|
if (enabled && this.currentBgImage) {
|
||||||
|
document.documentElement.style.setProperty('--bg-image', `url("${this.currentBgImage}")`);
|
||||||
|
} else {
|
||||||
|
document.documentElement.style.setProperty('--bg-image', 'none');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveBackgroundSettings() {
|
||||||
|
const enabled = document.getElementById('bg-enabled').checked;
|
||||||
|
const bgImage = this.currentBgImage;
|
||||||
|
|
||||||
|
if (enabled && bgImage) {
|
||||||
|
localStorage.setItem('teatracker_bg_enabled', 'true');
|
||||||
|
localStorage.setItem('teatracker_bg_image', bgImage);
|
||||||
|
this.showToast('Hintergrundbild gespeichert!', 'success');
|
||||||
|
} else {
|
||||||
|
localStorage.removeItem('teatracker_bg_enabled');
|
||||||
|
localStorage.removeItem('teatracker_bg_image');
|
||||||
|
this.showToast('Hintergrundbild deaktiviert!', 'success');
|
||||||
|
}
|
||||||
|
this.toggleBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
removeBackground() {
|
||||||
|
this.currentBgImage = null;
|
||||||
|
document.getElementById('bg-preview-img').src = '';
|
||||||
|
document.getElementById('bg-image-preview').style.display = 'none';
|
||||||
|
document.getElementById('remove-bg').style.display = 'none';
|
||||||
|
document.getElementById('bg-enabled').checked = false;
|
||||||
|
this.toggleBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadBackgroundSettings() {
|
||||||
|
this.currentBgImage = localStorage.getItem('teatracker_bg_image');
|
||||||
|
const enabled = localStorage.getItem('teatracker_bg_enabled') === 'true';
|
||||||
|
|
||||||
|
if (this.currentBgImage) {
|
||||||
|
document.getElementById('bg-enabled').checked = enabled;
|
||||||
|
if (enabled) {
|
||||||
|
document.documentElement.style.setProperty('--bg-image', `url("${this.currentBgImage}")`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show preview
|
||||||
|
const preview = document.getElementById('bg-preview-img');
|
||||||
|
const previewContainer = document.getElementById('bg-image-preview');
|
||||||
|
const removeBtn = document.getElementById('remove-bg');
|
||||||
|
if (preview && previewContainer && removeBtn) {
|
||||||
|
preview.src = this.currentBgImage;
|
||||||
|
previewContainer.style.display = 'block';
|
||||||
|
removeBtn.style.display = 'inline-flex';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================
|
// ============================================
|
||||||
// Nextcloud Functions
|
// Nextcloud Functions
|
||||||
// ============================================
|
// ============================================
|
||||||
@ -778,6 +949,30 @@ 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 };
|
||||||
@ -914,8 +1109,8 @@ class TeeTracker {
|
|||||||
localStorage.removeItem(STORAGE_KEY_ENTRIES);
|
localStorage.removeItem(STORAGE_KEY_ENTRIES);
|
||||||
|
|
||||||
if (this.useNextcloud && this.nextcloudStorage) {
|
if (this.useNextcloud && this.nextcloudStorage) {
|
||||||
await this.nextcloudStorage.saveFile('teas.json', []);
|
await this.nextcloudStorage.saveFile(DATA_DIRECTORY + 'teas.json', []);
|
||||||
await this.nextcloudStorage.saveFile('entries.json', []);
|
await this.nextcloudStorage.saveFile(DATA_DIRECTORY + 'entries.json', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.closeConfirmModal();
|
this.closeConfirmModal();
|
||||||
@ -1035,7 +1230,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('');
|
||||||
@ -1063,11 +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>
|
||||||
<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">
|
||||||
@ -1107,11 +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>
|
||||||
<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">
|
||||||
@ -1140,6 +1343,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;
|
||||||
}
|
}
|
||||||
@ -1147,6 +1361,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;
|
||||||
}
|
}
|
||||||
@ -1173,7 +1392,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;
|
||||||
@ -1194,6 +1415,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);
|
||||||
}
|
}
|
||||||
@ -1282,6 +1560,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) {
|
||||||
@ -1294,6 +1573,7 @@ class TeeTracker {
|
|||||||
date,
|
date,
|
||||||
time,
|
time,
|
||||||
amount,
|
amount,
|
||||||
|
teaspoons,
|
||||||
notes
|
notes
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1349,7 +1629,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('');
|
||||||
|
|||||||
59
index.html
59
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">
|
||||||
|
|||||||
100
styles.css
100
styles.css
@ -936,3 +936,103 @@ header p {
|
|||||||
outline: none;
|
outline: none;
|
||||||
border-color: var(--primary-color);
|
border-color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Background Image Settings */
|
||||||
|
.bg-preview {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bg-preview img {
|
||||||
|
max-width: 200px;
|
||||||
|
max-height: 150px;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Background Image for App */
|
||||||
|
.app-container {
|
||||||
|
background-image: var(--bg-image, none);
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
background-attachment: fixed;
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Overlay for better text readability */
|
||||||
|
.app-container::before {
|
||||||
|
content: '';
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: rgba(255, 255, 255, 0.85);
|
||||||
|
z-index: -1;
|
||||||
|
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