Bug fixes.
This commit is contained in:
@@ -4,7 +4,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
const selectionGrid = document.getElementById('selection-grid');
|
||||
const filterButtons = document.querySelectorAll('.filter-buttons .filter-btn');
|
||||
const orientationButtons = document.querySelectorAll('.orientation-filters .filter-btn');
|
||||
const resolutionFilter = document.getElementById('resolution-filter');
|
||||
const resolutionFilter = document.getElementById('resolution-select');
|
||||
const selectAllBtn = document.getElementById('select-all');
|
||||
const deselectAllBtn = document.getElementById('deselect-all');
|
||||
const downloadSelectedBtn = document.getElementById('download-selected');
|
||||
@@ -176,7 +176,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
<p>No selections match the current filters</p>
|
||||
</div>
|
||||
`;
|
||||
filteredCountEl.textContent = `0 images match your filters (out of ${selections.length} total)`;
|
||||
if (filteredCountEl) {
|
||||
filteredCountEl.textContent = `0 images match your filters (out of ${selections.length} total)`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -259,8 +261,19 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
};
|
||||
|
||||
const updateDownloadButton = () => {
|
||||
if (!downloadSelectedBtn) return;
|
||||
|
||||
downloadSelectedBtn.disabled = selectedItems.length === 0;
|
||||
downloadSelectedBtn.querySelector('.label').textContent = selectedItems.length > 0 ? `Download (${selectedItems.length})` : 'Download';
|
||||
const labelEl = downloadSelectedBtn.querySelector('.label');
|
||||
if (labelEl) {
|
||||
labelEl.textContent = selectedItems.length > 0 ? `Download (${selectedItems.length})` : 'Download';
|
||||
} else {
|
||||
// If there's no label element, update the count element instead
|
||||
const countEl = downloadSelectedBtn.querySelector('.count');
|
||||
if (countEl) {
|
||||
countEl.textContent = selectedItems.length > 0 ? selectedItems.length : '0';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Enhanced selection item click handler
|
||||
@@ -379,34 +392,53 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
confirmDialog.remove();
|
||||
}, 400);
|
||||
|
||||
// Simulate delete functionality (replace with actual API call)
|
||||
setTimeout(() => {
|
||||
selectionItem.remove();
|
||||
showToast('Selection removed');
|
||||
|
||||
// Update selected items if this was selected
|
||||
if (selectedItems.some(item => item.id === selectionId)) {
|
||||
selectedItems = selectedItems.filter(item => item.id !== selectionId);
|
||||
updateDownloadButton();
|
||||
// Delete the selection via API
|
||||
fetch('/delete-selection', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: selectionId })
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to delete selection');
|
||||
}
|
||||
|
||||
// Update allSelections array
|
||||
allSelections = allSelections.filter(s => s.id !== selectionId);
|
||||
|
||||
// Update stats
|
||||
const stats = calculateStats(allSelections);
|
||||
updateStats(stats);
|
||||
|
||||
// Update filtered count
|
||||
if (filteredCountEl) {
|
||||
const filteredSelections = allSelections.filter(s =>
|
||||
(currentFilter === 'all' || s.action === currentFilter) &&
|
||||
(currentOrientation === 'all' || s.orientation === currentOrientation) &&
|
||||
(currentResolution === 'all' || s.resolution === currentResolution)
|
||||
);
|
||||
filteredCountEl.textContent = `Showing ${filteredSelections.length} of ${allSelections.length} images`;
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
selectionItem.remove();
|
||||
showToast('Selection removed');
|
||||
|
||||
// Update selected items if this was selected
|
||||
if (selectedItems.some(item => item.id === selectionId)) {
|
||||
selectedItems = selectedItems.filter(item => item.id !== selectionId);
|
||||
updateDownloadButton();
|
||||
}
|
||||
|
||||
// Update allSelections array
|
||||
allSelections = allSelections.filter(s => s.id !== selectionId);
|
||||
|
||||
// Update stats
|
||||
const stats = calculateStats(allSelections);
|
||||
updateStats(stats);
|
||||
|
||||
// Update filtered count
|
||||
if (filteredCountEl) {
|
||||
const filteredSelections = allSelections.filter(s =>
|
||||
(currentFilter === 'all' || s.action === currentFilter) &&
|
||||
(currentOrientation === 'all' || s.orientation === currentOrientation) &&
|
||||
(currentResolution === 'all' || s.resolution === currentResolution)
|
||||
);
|
||||
filteredCountEl.textContent = `Showing ${filteredSelections.length} of ${allSelections.length} images`;
|
||||
}
|
||||
} else {
|
||||
showToast('Error removing selection', 'error');
|
||||
}
|
||||
}, 300);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error deleting selection:', error);
|
||||
showToast('Error removing selection', 'error');
|
||||
});
|
||||
});
|
||||
|
||||
confirmDialog.querySelector('.cancel-delete-btn').addEventListener('click', () => {
|
||||
@@ -523,44 +555,65 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
modalMessage.textContent = `Updating action to ${getActionName(action)}...`;
|
||||
modalMessage.style.color = '#3498db';
|
||||
|
||||
// Simulate API call (replace with actual implementation)
|
||||
setTimeout(() => {
|
||||
modalMessage.textContent = `Action updated successfully!`;
|
||||
modalMessage.style.color = '#2ecc71';
|
||||
|
||||
// Close modal after success
|
||||
setTimeout(() => {
|
||||
actionModal.classList.remove('show');
|
||||
setTimeout(() => {
|
||||
actionModal.style.display = 'none';
|
||||
modalMessage.textContent = '';
|
||||
}, 400);
|
||||
// Update the selection via API
|
||||
fetch('/update-selection', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ id: currentSelectionId, action })
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to update selection');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
modalMessage.textContent = `Action updated successfully!`;
|
||||
modalMessage.style.color = '#2ecc71';
|
||||
|
||||
// Update the UI to reflect the change
|
||||
const selectionItem = document.querySelector(`.selection-item[data-id="${currentSelectionId}"]`);
|
||||
if (selectionItem) {
|
||||
const actionEl = selectionItem.querySelector('.selection-action');
|
||||
const oldAction = actionEl.classList[1].replace('action-', '');
|
||||
// Close modal after success
|
||||
setTimeout(() => {
|
||||
actionModal.classList.remove('show');
|
||||
setTimeout(() => {
|
||||
actionModal.style.display = 'none';
|
||||
modalMessage.textContent = '';
|
||||
}, 400);
|
||||
|
||||
// Update the action element
|
||||
actionEl.className = `selection-action action-${action}`;
|
||||
actionEl.innerHTML = `<i class="fa-solid ${getActionIcon(action)}"></i> ${getActionName(action)}`;
|
||||
|
||||
// Update the selection in allSelections
|
||||
const selectionIndex = allSelections.findIndex(s => s.id === currentSelectionId);
|
||||
if (selectionIndex !== -1) {
|
||||
allSelections[selectionIndex].action = action;
|
||||
// Update the UI to reflect the change
|
||||
const selectionItem = document.querySelector(`.selection-item[data-id="${currentSelectionId}"]`);
|
||||
if (selectionItem) {
|
||||
const actionEl = selectionItem.querySelector('.selection-action');
|
||||
const oldAction = actionEl.classList[1].replace('action-', '');
|
||||
|
||||
// Update the action element
|
||||
actionEl.className = `selection-action action-${action}`;
|
||||
actionEl.innerHTML = `<i class="fa-solid ${getActionIcon(action)}"></i> ${getActionName(action)}`;
|
||||
|
||||
// Update the selection in allSelections
|
||||
const selectionIndex = allSelections.findIndex(s => s.id === currentSelectionId);
|
||||
if (selectionIndex !== -1) {
|
||||
allSelections[selectionIndex].action = action;
|
||||
}
|
||||
|
||||
// Update stats
|
||||
const stats = calculateStats(allSelections);
|
||||
updateStats(stats);
|
||||
|
||||
// Show toast notification
|
||||
showToast(`Updated to ${getActionName(action)}`);
|
||||
}
|
||||
|
||||
// Update stats
|
||||
const stats = calculateStats(allSelections);
|
||||
updateStats(stats);
|
||||
|
||||
// Show toast notification
|
||||
showToast(`Updated to ${getActionName(action)}`);
|
||||
}
|
||||
}, 1000);
|
||||
}, 800);
|
||||
}, 1000);
|
||||
} else {
|
||||
modalMessage.textContent = `Error updating action`;
|
||||
modalMessage.style.color = '#e74c3c';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error updating selection:', error);
|
||||
modalMessage.textContent = `Error: ${error.message}`;
|
||||
modalMessage.style.color = '#e74c3c';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -579,40 +632,64 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
resetMessage.textContent = 'Deleting all selections...';
|
||||
resetMessage.style.color = '#3498db';
|
||||
|
||||
// Simulate API call (replace with actual implementation)
|
||||
setTimeout(() => {
|
||||
resetMessage.textContent = 'All selections have been deleted successfully!';
|
||||
resetMessage.style.color = '#2ecc71';
|
||||
|
||||
// Close modal after success
|
||||
setTimeout(() => {
|
||||
resetModal.classList.remove('show');
|
||||
// Reset database via API
|
||||
fetch('/reset-database', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to reset database');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
resetMessage.textContent = 'All selections have been deleted successfully!';
|
||||
resetMessage.style.color = '#2ecc71';
|
||||
|
||||
// Close modal after success
|
||||
setTimeout(() => {
|
||||
resetModal.style.display = 'none';
|
||||
confirmResetBtn.disabled = false;
|
||||
confirmResetBtn.textContent = 'Yes, Delete All';
|
||||
resetMessage.textContent = '';
|
||||
|
||||
// Clear the grid and update state
|
||||
selectionGrid.innerHTML = `
|
||||
<div class="no-selections">
|
||||
<i class="fa-solid fa-image-slash fa-3x"></i>
|
||||
<p>No selections found</p>
|
||||
</div>
|
||||
`;
|
||||
selectedItems = [];
|
||||
allSelections = [];
|
||||
updateDownloadButton();
|
||||
|
||||
// Update stats
|
||||
const stats = calculateStats([]);
|
||||
updateStats(stats);
|
||||
|
||||
// Show toast notification
|
||||
showToast('All selections have been deleted');
|
||||
}, 400);
|
||||
}, 1000);
|
||||
}, 1500);
|
||||
resetModal.classList.remove('show');
|
||||
setTimeout(() => {
|
||||
resetModal.style.display = 'none';
|
||||
confirmResetBtn.disabled = false;
|
||||
confirmResetBtn.textContent = 'Yes, Delete All';
|
||||
resetMessage.textContent = '';
|
||||
|
||||
// Clear the grid and update state
|
||||
selectionGrid.innerHTML = `
|
||||
<div class="no-selections">
|
||||
<i class="fa-solid fa-image-slash fa-3x"></i>
|
||||
<p>No selections found</p>
|
||||
</div>
|
||||
`;
|
||||
selectedItems = [];
|
||||
allSelections = [];
|
||||
updateDownloadButton();
|
||||
|
||||
// Update stats
|
||||
const stats = calculateStats([]);
|
||||
updateStats(stats);
|
||||
|
||||
// Show toast notification
|
||||
showToast('All selections have been deleted');
|
||||
}, 400);
|
||||
}, 1000);
|
||||
} else {
|
||||
resetMessage.textContent = 'Error resetting database';
|
||||
resetMessage.style.color = '#e74c3c';
|
||||
confirmResetBtn.disabled = false;
|
||||
confirmResetBtn.textContent = 'Yes, Delete All';
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error resetting database:', error);
|
||||
resetMessage.textContent = `Error: ${error.message}`;
|
||||
resetMessage.style.color = '#e74c3c';
|
||||
confirmResetBtn.disabled = false;
|
||||
confirmResetBtn.textContent = 'Yes, Delete All';
|
||||
});
|
||||
});
|
||||
|
||||
cancelResetBtn.addEventListener('click', () => {
|
||||
|
||||
Reference in New Issue
Block a user