cache fixed, delete buttons fixed

This commit is contained in:
Dobromir Popov
2025-10-24 21:34:23 +03:00
parent 420251f2d4
commit 6e58f4d88f
5 changed files with 149 additions and 40 deletions

View File

@@ -300,14 +300,33 @@
}
function deleteAnnotation(annotationId) {
console.log('deleteAnnotation called with ID:', annotationId);
console.log('=== deleteAnnotation called ===');
console.log('Annotation ID:', annotationId);
console.log('window.appState:', window.appState);
console.log('window.appState.annotations:', window.appState?.annotations);
if (!window.appState || !window.appState.annotations) {
console.error('appState not initialized');
if (!annotationId) {
console.error('No annotation ID provided');
showError('No annotation ID provided');
return;
}
console.log('Current annotations:', window.appState.annotations.map(a => a.annotation_id));
if (!window.appState || !window.appState.annotations) {
console.error('appState not initialized');
showError('Application state not initialized. Please refresh the page.');
return;
}
// Check if annotation exists
const annotation = window.appState.annotations.find(a => a.annotation_id === annotationId);
if (!annotation) {
console.error('Annotation not found in appState:', annotationId);
showError('Annotation not found');
return;
}
console.log('Found annotation:', annotation);
console.log('Current annotations count:', window.appState.annotations.length);
if (!confirm('Delete this annotation?')) {
console.log('Delete cancelled by user');
@@ -322,35 +341,45 @@
})
.then(response => {
console.log('Delete response status:', response.status);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
return response.json();
})
.then(data => {
console.log('Delete response data:', data);
if (data.success) {
console.log('Delete successful, updating UI...');
// Remove from app state
if (window.appState && window.appState.annotations) {
window.appState.annotations = window.appState.annotations.filter(
a => a.annotation_id !== annotationId
);
console.log('Removed from appState, remaining:', window.appState.annotations.length);
}
const originalCount = window.appState.annotations.length;
window.appState.annotations = window.appState.annotations.filter(
a => a.annotation_id !== annotationId
);
console.log(`Removed from appState: ${originalCount} -> ${window.appState.annotations.length}`);
// Update UI
if (typeof renderAnnotationsList === 'function') {
renderAnnotationsList(window.appState.annotations);
console.log('UI updated');
console.log('UI updated with renderAnnotationsList');
} else {
console.error('renderAnnotationsList function not found');
// Try to reload the page as fallback
location.reload();
return;
}
// Remove from chart
if (window.appState && window.appState.chartManager) {
window.appState.chartManager.removeAnnotation(annotationId);
console.log('Removed from chart');
} else {
console.warn('Chart manager not available');
}
showSuccess('Annotation deleted successfully');
console.log('=== deleteAnnotation completed successfully ===');
} else {
console.error('Delete failed:', data.error);
showError('Failed to delete annotation: ' + (data.error ? data.error.message : 'Unknown error'));
@@ -372,6 +401,9 @@
console.log('=== setupGlobalFunctions called ===');
console.log('deleteAnnotation function exists:', typeof deleteAnnotation);
console.log('highlightAnnotation function exists:', typeof highlightAnnotation);
console.log('renderAnnotationsList function exists:', typeof renderAnnotationsList);
console.log('showError function exists:', typeof showError);
console.log('showSuccess function exists:', typeof showSuccess);
// Make functions globally available
window.showError = showError;
@@ -386,6 +418,7 @@
console.log(' - window.renderAnnotationsList:', typeof window.renderAnnotationsList);
console.log(' - window.showError:', typeof window.showError);
console.log(' - window.showSuccess:', typeof window.showSuccess);
console.log(' - window.highlightAnnotation:', typeof window.highlightAnnotation);
// Test call
console.log('Testing window.deleteAnnotation availability...');
@@ -394,6 +427,40 @@
} else {
console.error('✗ window.deleteAnnotation is NOT a function!');
}
// Add a test button to verify functionality (temporary)
console.log('Adding test delete function to window for debugging...');
window.testDeleteFunction = function() {
console.log('Test delete function called');
console.log('window.deleteAnnotation type:', typeof window.deleteAnnotation);
if (typeof window.deleteAnnotation === 'function') {
console.log('window.deleteAnnotation is available');
// Test with a fake ID to see if the function runs
console.log('Testing delete function with fake ID...');
try {
window.deleteAnnotation('test-fake-id');
} catch (error) {
console.error('Error in test delete:', error);
}
} else {
console.error('window.deleteAnnotation is NOT available');
}
};
// Add test button to page (temporary debugging)
const testButton = document.createElement('button');
testButton.textContent = 'Test Delete Function';
testButton.className = 'btn btn-warning btn-sm';
testButton.style.position = 'fixed';
testButton.style.top = '10px';
testButton.style.right = '10px';
testButton.style.zIndex = '9999';
testButton.onclick = function() {
console.log('Test button clicked');
window.testDeleteFunction();
};
document.body.appendChild(testButton);
console.log('Test button added to page');
}
function renderAnnotationsList(annotations) {
@@ -438,15 +505,23 @@
item.querySelector('.delete-btn').addEventListener('click', function(e) {
e.stopPropagation();
console.log('Delete button clicked for:', annotation.annotation_id);
console.log('=== Delete button clicked ===');
console.log('Annotation ID:', annotation.annotation_id);
console.log('window.deleteAnnotation type:', typeof window.deleteAnnotation);
console.log('window object keys containing delete:', Object.keys(window).filter(k => k.includes('delete')));
if (typeof window.deleteAnnotation === 'function') {
console.log('Calling window.deleteAnnotation...');
window.deleteAnnotation(annotation.annotation_id);
try {
window.deleteAnnotation(annotation.annotation_id);
} catch (error) {
console.error('Error calling deleteAnnotation:', error);
showError('Error calling delete function: ' + error.message);
}
} else {
console.error('window.deleteAnnotation is not a function:', typeof window.deleteAnnotation);
alert('Delete function not available. Please refresh the page.');
console.log('Available window functions:', Object.keys(window).filter(k => typeof window[k] === 'function'));
showError('Delete function not available. Please refresh the page.');
}
});

View File

@@ -165,18 +165,32 @@
item.querySelector('.delete-annotation-btn').addEventListener('click', function(e) {
e.stopPropagation();
console.log('Delete button clicked for:', annotation.annotation_id);
console.log('=== Delete annotation button clicked ===');
console.log('Annotation ID:', annotation.annotation_id);
console.log('window.deleteAnnotation type:', typeof window.deleteAnnotation);
console.log('window object keys:', Object.keys(window).filter(k => k.includes('delete')));
console.log('window object keys containing delete:', Object.keys(window).filter(k => k.includes('delete')));
// Use window.deleteAnnotation to ensure we get the global function
if (typeof window.deleteAnnotation === 'function') {
console.log('Calling window.deleteAnnotation...');
window.deleteAnnotation(annotation.annotation_id);
try {
window.deleteAnnotation(annotation.annotation_id);
} catch (error) {
console.error('Error calling deleteAnnotation:', error);
if (typeof window.showError === 'function') {
window.showError('Error calling delete function: ' + error.message);
} else {
alert('Error calling delete function: ' + error.message);
}
}
} else {
console.error('window.deleteAnnotation is not a function:', typeof window.deleteAnnotation);
console.log('Available functions:', Object.keys(window).filter(k => typeof window[k] === 'function'));
alert('Delete function not available. Please refresh the page.');
if (typeof window.showError === 'function') {
window.showError('Delete function not available. Please refresh the page.');
} else {
alert('Delete function not available. Please refresh the page.');
}
}
});