Debug: Tilføj console.log for at tracke entry loading i wizard

This commit is contained in:
Christian 2026-01-02 16:40:03 +01:00
parent 1c12014c5a
commit d704a2f780

View File

@ -385,6 +385,7 @@
// Load a specific time entry // Load a specific time entry
async function loadSpecificEntry(timeId) { async function loadSpecificEntry(timeId) {
console.log('🎯 Loading specific entry:', timeId);
document.getElementById('loading-state').classList.remove('d-none'); document.getElementById('loading-state').classList.remove('d-none');
document.getElementById('time-entry-container').classList.add('d-none'); document.getElementById('time-entry-container').classList.add('d-none');
document.getElementById('completion-state').classList.add('d-none'); document.getElementById('completion-state').classList.add('d-none');
@ -397,6 +398,7 @@
} }
const entry = await response.json(); const entry = await response.json();
console.log('📥 Loaded entry:', entry.id, 'Status:', entry.status, 'Date:', entry.worked_date);
currentEntry = entry; currentEntry = entry;
currentCaseId = entry.case_id; currentCaseId = entry.case_id;
@ -404,19 +406,26 @@
// Only fetch other case entries if this entry is pending // Only fetch other case entries if this entry is pending
// Otherwise just show this single entry // Otherwise just show this single entry
if (entry.status === 'pending' && entry.case_id) { if (entry.status === 'pending' && entry.case_id) {
console.log('🔍 Fetching other pending entries for case:', entry.case_id);
const caseResponse = await fetch(`/api/v1/timetracking/wizard/case/${entry.case_id}/entries`); const caseResponse = await fetch(`/api/v1/timetracking/wizard/case/${entry.case_id}/entries`);
if (caseResponse.ok) { if (caseResponse.ok) {
const caseEntries = await caseResponse.json(); const caseEntries = await caseResponse.json();
console.log('📋 Got', caseEntries.length, 'pending entries for case');
// Make sure our entry is in the list (it should be since it's pending) // Make sure our entry is in the list (it should be since it's pending)
window.currentCaseEntries = caseEntries; window.currentCaseEntries = caseEntries;
} else { } else {
console.log('⚠️ Could not fetch case entries, showing single entry');
window.currentCaseEntries = [entry]; window.currentCaseEntries = [entry];
} }
} else { } else {
console.log(' Entry is not pending or has no case - showing single entry only');
// Entry is not pending - just show this one entry // Entry is not pending - just show this one entry
window.currentCaseEntries = [entry]; window.currentCaseEntries = [entry];
} }
console.log('✨ Current entry to display:', currentEntry.id);
console.log('📦 All entries:', window.currentCaseEntries.map(e => e.id));
// Show the entry // Show the entry
displayCaseEntries({ displayCaseEntries({
time_entry: entry, time_entry: entry,
@ -431,7 +440,7 @@
document.getElementById('time-entry-container').classList.remove('d-none'); document.getElementById('time-entry-container').classList.remove('d-none');
} catch (error) { } catch (error) {
console.error('Error loading specific entry:', error); console.error('Error loading specific entry:', error);
showToast('Kunne ikke indlæse tidsregistrering', 'danger'); showToast('Kunne ikke indlæse tidsregistrering', 'danger');
// Fall back to loading next entry // Fall back to loading next entry
setTimeout(() => loadNextEntry(), 1000); setTimeout(() => loadNextEntry(), 1000);
@ -498,6 +507,9 @@
const entries = window.currentCaseEntries || []; const entries = window.currentCaseEntries || [];
const container = document.getElementById('time-entries-list'); const container = document.getElementById('time-entries-list');
console.log('🖼️ displayCaseEntries called with', entries.length, 'entries');
console.log('🎯 currentEntry.id:', currentEntry?.id);
if (entries.length === 0) { if (entries.length === 0) {
container.innerHTML = '<div class="alert alert-info">Ingen pending tidsregistreringer</div>'; container.innerHTML = '<div class="alert alert-info">Ingen pending tidsregistreringer</div>';
return; return;
@ -507,10 +519,14 @@
let entry; let entry;
if (currentEntry && currentEntry.id) { if (currentEntry && currentEntry.id) {
entry = entries.find(e => e.id === currentEntry.id) || entries[0]; entry = entries.find(e => e.id === currentEntry.id) || entries[0];
console.log('🔎 Looking for entry', currentEntry.id, '- Found:', entry.id);
} else { } else {
entry = entries[0]; entry = entries[0];
console.log(' No currentEntry set, using first entry:', entry.id);
} }
console.log('✅ Displaying entry:', entry.id, 'Date:', entry.worked_date);
// Update header // Update header
document.getElementById('case-header-title').textContent = entry.case_title || 'Ingen case'; document.getElementById('case-header-title').textContent = entry.case_title || 'Ingen case';
document.getElementById('case-header-customer').textContent = entry.customer_name || '-'; document.getElementById('case-header-customer').textContent = entry.customer_name || '-';