Add debug logging and improve map loading UX

Added console logging to map loading callbacks and AJAX requests for better debugging. Reduced failsafe timeout from 35s to 10s to improve user experience. Improved date range display logic to check for element existence before updating.
这个提交包含在:
Peter Goodhall 2025-08-10 22:06:11 +01:00
父节点 129cb5986f
当前提交 4db4822c09
共有 3 个文件被更改,包括 27 次插入9 次删除

查看文件

@ -795,14 +795,14 @@ if ($this->session->userdata('user_id') != null) {
$('.warningOnSubmit').hide(); $('.warningOnSubmit').hide();
$('#map-success-alert').addClass('d-none'); $('#map-success-alert').addClass('d-none');
// Failsafe timeout to prevent stuck spinner (35 seconds) // Failsafe timeout to prevent stuck spinner (10 seconds)
const failsafeTimeout = setTimeout(function() { const failsafeTimeout = setTimeout(function() {
console.warn('Map loading timed out - forcing spinner hide'); console.warn('Map loading timed out - forcing spinner hide');
$button.prop('disabled', false); $button.prop('disabled', false);
$spinner.addClass('d-none'); $spinner.addClass('d-none');
$('.warningOnSubmit .warningOnSubmit_txt').text('Map loading timed out. Please try again.'); $('.warningOnSubmit .warningOnSubmit_txt').text('Map loading timed out. Please try again.');
$('.warningOnSubmit').show(); $('.warningOnSubmit').show();
}, 35000); }, 10000);
var customdata = { var customdata = {
'dataPost': { 'dataPost': {
@ -818,17 +818,23 @@ if ($this->session->userdata('user_id') != null) {
// Add success and error callbacks to the customdata // Add success and error callbacks to the customdata
customdata.onSuccess = function(plotjson) { customdata.onSuccess = function(plotjson) {
console.log('Map loading success callback called with data:', plotjson);
// Clear the failsafe timeout // Clear the failsafe timeout
clearTimeout(failsafeTimeout); clearTimeout(failsafeTimeout);
try { try {
// Update statistics // Update statistics
if (typeof updateMapStatistics === 'function') { if (typeof updateMapStatistics === 'function') {
console.log('Calling updateMapStatistics function');
updateMapStatistics(plotjson); updateMapStatistics(plotjson);
} else {
console.warn('updateMapStatistics function not found');
} }
// Show success message // Show success message
const qsoCount = plotjson['markers'] ? plotjson['markers'].length : 0; const qsoCount = plotjson['markers'] ? plotjson['markers'].length : 0;
console.log('QSO count:', qsoCount);
$('#qso-count-display').text(`Loaded ${qsoCount} QSOs successfully`); $('#qso-count-display').text(`Loaded ${qsoCount} QSOs successfully`);
$('#map-success-alert').removeClass('d-none'); $('#map-success-alert').removeClass('d-none');
@ -841,12 +847,15 @@ if ($this->session->userdata('user_id') != null) {
$('.warningOnSubmit').show(); $('.warningOnSubmit').show();
} finally { } finally {
// Always re-enable button and hide spinner // Always re-enable button and hide spinner
console.log('Re-enabling button and hiding spinner');
$button.prop('disabled', false); $button.prop('disabled', false);
$spinner.addClass('d-none'); $spinner.addClass('d-none');
} }
}; };
customdata.onError = function() { customdata.onError = function() {
console.log('Map loading error callback called');
// Clear the failsafe timeout // Clear the failsafe timeout
clearTimeout(failsafeTimeout); clearTimeout(failsafeTimeout);

查看文件

@ -327,6 +327,8 @@ function updateDateRangeDisplay() {
const toDate = document.getElementById('to').value; const toDate = document.getElementById('to').value;
const display = document.getElementById('date-range-display'); const display = document.getElementById('date-range-display');
// Only update if the display element exists
if (display) {
if (fromDate && toDate) { if (fromDate && toDate) {
if (fromDate === toDate) { if (fromDate === toDate) {
display.textContent = new Date(fromDate).toLocaleDateString(); display.textContent = new Date(fromDate).toLocaleDateString();
@ -337,6 +339,7 @@ function updateDateRangeDisplay() {
display.textContent = 'Select dates'; display.textContent = 'Select dates';
} }
} }
}
function setDateRange(period) { function setDateRange(period) {
const today = new Date(); const today = new Date();

查看文件

@ -65,6 +65,7 @@ function initplot(_url_qso, options={}) {
} }
function askForPlots(_url_qso, options={}) { function askForPlots(_url_qso, options={}) {
console.log('askForPlots called with URL:', _url_qso, 'options:', options);
removeMarkers(); removeMarkers();
if (typeof options.dataPost !== "undefined") { _dataPost = options.dataPost; } else { _dataPost = {}; } if (typeof options.dataPost !== "undefined") { _dataPost = options.dataPost; } else { _dataPost = {}; }
$.ajax({ $.ajax({
@ -74,13 +75,15 @@ function askForPlots(_url_qso, options={}) {
data: _dataPost, data: _dataPost,
timeout: 30000, // 30 second timeout timeout: 30000, // 30 second timeout
error: function(xhr, status, error) { error: function(xhr, status, error) {
console.log('[ERROR] ajax askForPlots() function return error:', status, error); console.log('[ERROR] ajax askForPlots() function return error:', status, error, xhr);
// Call custom error callback if provided // Call custom error callback if provided
if (typeof options.onError === 'function') { if (typeof options.onError === 'function') {
console.log('Calling custom error callback');
options.onError(); options.onError();
} }
}, },
success: function(plotjson) { success: function(plotjson) {
console.log('askForPlots AJAX success, plotjson:', plotjson);
if ((typeof plotjson['markers'] !== "undefined")&&(plotjson['markers'].length>0)) { if ((typeof plotjson['markers'] !== "undefined")&&(plotjson['markers'].length>0)) {
for (i=0;i<plotjson['markers'].length;i++) { createPlots(plotjson['markers'][i]); } for (i=0;i<plotjson['markers'].length;i++) { createPlots(plotjson['markers'][i]); }
} }
@ -93,7 +96,10 @@ function askForPlots(_url_qso, options={}) {
// Call custom success callback if provided // Call custom success callback if provided
if (typeof options.onSuccess === 'function') { if (typeof options.onSuccess === 'function') {
console.log('Calling custom success callback');
options.onSuccess(plotjson); options.onSuccess(plotjson);
} else {
console.warn('No custom success callback provided');
} }
} }
}); });