From 9c4197242782f0f26ac0d827fc702672f1f4ae29 Mon Sep 17 00:00:00 2001 From: mattk70 Date: Fri, 8 Nov 2024 12:23:04 +0000 Subject: [PATCH] Disable UI elements that change list settings during analysis --- js/DOMcache.js | 1 + js/ui.js | 44 ++++++++++++++++---------------------------- js/worker.js | 5 +++-- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/js/DOMcache.js b/js/DOMcache.js index e8aa7ab..5bc5ddf 100644 --- a/js/DOMcache.js +++ b/js/DOMcache.js @@ -39,6 +39,7 @@ const DOM = { get listIcon() { if (!this._listIcon) { this._listIcon = document.getElementById('list-icon') } return this._listIcon}, get loading() { if (!this._loading) { this._loading = document.getElementById('loading') } return this._loading}, get speciesThresholdEl() { if (!this._speciesThresholdEl) { this._speciesThresholdEl = document.getElementById('species-threshold-el') } return this._speciesThresholdEl}, + get speciesWeek() { if (!this._speciesWeek) { this._speciesWeek = document.getElementById('species-week') } return this._speciesWeek}, get speciesThreshold() { if (!this._speciesThreshold) { this._speciesThreshold = document.getElementById('species-frequency-threshold') } return this._speciesThreshold}, get customListFile() { if (!this._customListFile) { this._customListFile = document.getElementById('custom-list-location') } return this._customListFile}, get customListSelector() { if (!this._customListSelector) { this._customListSelector = document.getElementById('list-file-selector') } return this._customListSelector}, diff --git a/js/ui.js b/js/ui.js index 7e2199b..f7f98e8 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1038,6 +1038,7 @@ function postAnalyseMessage(args) { const selection = !!args.end; const filesInScope = args.filesInScope; PREDICTING = true; + disableSettingsListElements(true) if (!selection) { analyseReset(); refreshResultsView(); @@ -2561,21 +2562,6 @@ function onChartData(args) { tooltip.appendChild(textNode); // Add the text node } - // // Get the tooltip's dimensions - // tooltip.style.display = 'block'; // Ensure tooltip is visible to measure dimensions - // const tooltipWidth = tooltip.offsetWidth; - // const windowWidth = window.innerWidth; - - // // Calculate the new tooltip position - // let tooltipLeft; - - // // If the tooltip would overflow past the right side of the window, position it to the left - // if (event.clientX + tooltipWidth + 15 > windowWidth) { - // tooltipLeft = event.clientX - tooltipWidth - 5; // Position to the left of the mouse cursor - // } else { - // tooltipLeft = event.clientX + 15; // Position to the right of the mouse cursor - // } - // Apply styles to the tooltip Object.assign(tooltip.style, { top: `${event.clientY}px`, @@ -2600,7 +2586,10 @@ function onChartData(args) { } DOM.listIcon.addEventListener('click', () => { - // todo: skip custom list if custom list not set + if (PREDICTING){ + generateToast({type:'warning', message: 'It is not possible to change the list settings while an analysis is underway. However, the list can be changed after the analysis completes', type:'warning'}) + return; + } const keys = Object.keys(LIST_MAP); const currentListIndex = keys.indexOf(config.list); const next = (currentListIndex === keys.length - 1) ? 0 : currentListIndex + 1; @@ -2779,6 +2768,7 @@ function centreSpec(){ if (PREDICTING) { console.log('Operation aborted'); PREDICTING = false; + disableSettingsListElements(true); STATE.analysisDone = true; worker.postMessage({ action: 'abort', @@ -2891,6 +2881,13 @@ function centreSpec(){ } : undefined; } + function disableSettingsListElements(bool){ + DOM.listToUse.disabled = bool; + DOM.customListContainer.disabled = bool; + DOM.localSwitchContainer.disabled = bool + DOM.speciesThreshold.disabled = bool; + DOM.speciesWeek.disabled = bool; + } const postBufferUpdate = ({ file = STATE.currentFile, begin = 0, @@ -3158,6 +3155,7 @@ function centreSpec(){ */ function onResultsComplete({active = undefined, select = undefined} = {}){ PREDICTING = false; + disableSettingsListElements(false) DOM.resultTable.replaceWith(resultsBuffer); const table = DOM.resultTable; showElement(['resultTableContainer', 'resultsHead'], false); @@ -3222,6 +3220,7 @@ function formatDuration(seconds){ function onAnalysisComplete({quiet}){ PREDICTING = false; + disableSettingsListElements(false) STATE.analysisDone = true; STATE.diskHasRecords && enableMenuItem(['explore', 'charts']); DOM.progressDiv.classList.add('invisible'); @@ -3356,11 +3355,6 @@ function formatDuration(seconds){ }) { let tr = ''; - if (typeof (result) === 'string') { - // const nocturnal = config.detect.nocmig ? 'during the night' : ''; - generateToast({ message: result}); - return - } if (index <= 1) { adjustSpecDims(true) if (selection) { @@ -3368,9 +3362,6 @@ function formatDuration(seconds){ selectionTable.textContent = ''; } else { - //adjustSpecDims(true); - //if (isFromDB) PREDICTING = false; - DOM.resultHeader.innerHTML =` sort Time @@ -3381,7 +3372,6 @@ function formatDuration(seconds){ Notes `; setTimelinePreferences(); - //showSortIcon(); showElement(['resultTableContainer', 'resultsHead'], false); } } else if (!isFromDB && index % (config.limit + 1) === 0) { @@ -3424,7 +3414,6 @@ function formatDuration(seconds){ const labelHTML = label ? tags[label] : ''; const hide = selection ? 'd-none' : ''; const countIcon = count > 1 ? `${count}` : ''; - //const XC_type = cname.includes('(song)') ? "song" : "nocturnal flight call"; tr += ` ${UI_timestamp} ${UI_position} @@ -3454,7 +3443,6 @@ function formatDuration(seconds){ const table = isSelection ? document.getElementById('selectionResultTableBody') : document.getElementById('resultTableBody'); if (isFromDB && !isSelection) { - //if (!resultsBuffer) resultsBuffer = table.cloneNode(); resultsBuffer.lastElementChild ? resultsBuffer.lastElementChild.insertAdjacentHTML('afterend', row) : resultsBuffer.innerHTML = row; @@ -4612,7 +4600,7 @@ function playRegion(){ }) function updateList () { - STATE.analysisDone && worker.postMessage({ action: 'update-list', list: config.list, refreshResults: STATE.analysisDone }) + worker.postMessage({ action: 'update-list', list: config.list, refreshResults: STATE.analysisDone }) } function refreshSummary() { diff --git a/js/worker.js b/js/worker.js index d02b733..056aa99 100644 --- a/js/worker.js +++ b/js/worker.js @@ -2540,11 +2540,12 @@ const getResults = async ({ if (!result.length) { if (STATE.selection) { // No more detections in the selection + generateAlert({message: 'No detections found in the selection'}) sendResult(++index, 'No detections found in the selection', true) } else { species = species || ''; - const nocmig = STATE.detect.nocmig ? 'nocturnal' : '' - sendResult(++index, `No ${nocmig} ${species} detections found ${STATE.mode === 'explore' ? 'in the Archive' : ''} using the ${STATE.list} list.`, true) + const nocmig = STATE.detect.nocmig ? 'nocturnal' : ''; + generateAlert({message: `No ${nocmig} ${species} detections found ${STATE.mode === 'explore' ? 'in the Archive' : ''} using the ${STATE.list} list.`}); } } (STATE.selection && topRankin === STATE.topRankin) || UI.postMessage({event: 'database-results-complete', active: active, select: position?.start});