Skip to content

Commit

Permalink
Disable UI elements that change list settings during analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Nov 8, 2024
1 parent 0450078 commit 9c41972
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
1 change: 1 addition & 0 deletions js/DOMcache.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 16 additions & 28 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,7 @@ function postAnalyseMessage(args) {
const selection = !!args.end;
const filesInScope = args.filesInScope;
PREDICTING = true;
disableSettingsListElements(true)
if (!selection) {
analyseReset();
refreshResultsView();
Expand Down Expand Up @@ -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`,
Expand All @@ -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 <b>can</b> 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;
Expand Down Expand Up @@ -2779,6 +2768,7 @@ function centreSpec(){
if (PREDICTING) {
console.log('Operation aborted');
PREDICTING = false;
disableSettingsListElements(true);
STATE.analysisDone = true;
worker.postMessage({
action: 'abort',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -3356,21 +3355,13 @@ function formatDuration(seconds){
}) {

let tr = '';
if (typeof (result) === 'string') {
// const nocturnal = config.detect.nocmig ? '<b>during the night</b>' : '';
generateToast({ message: result});
return
}
if (index <= 1) {
adjustSpecDims(true)
if (selection) {
const selectionTable = document.getElementById('selectionResultTableBody');
selectionTable.textContent = '';
}
else {
//adjustSpecDims(true);
//if (isFromDB) PREDICTING = false;

DOM.resultHeader.innerHTML =`
<tr>
<th id="sort-time" class="time-sort col text-start timeOfDay" title="Sort results by detection time"><span class="text-muted material-symbols-outlined time-sort-icon d-none">sort</span> Time</th>
Expand All @@ -3381,7 +3372,6 @@ function formatDuration(seconds){
<th class="col text-end">Notes</th>
</tr>`;
setTimelinePreferences();
//showSortIcon();
showElement(['resultTableContainer', 'resultsHead'], false);
}
} else if (!isFromDB && index % (config.limit + 1) === 0) {
Expand Down Expand Up @@ -3424,7 +3414,6 @@ function formatDuration(seconds){
const labelHTML = label ? tags[label] : '';
const hide = selection ? 'd-none' : '';
const countIcon = count > 1 ? `<span class="circle pointer" title="Click to view the ${count} detections at this timecode">${count}</span>` : '';
//const XC_type = cname.includes('(song)') ? "song" : "nocturnal flight call";
tr += `<tr tabindex="-1" id="result${index}" name="${file}|${position}|${end || position + 3}|${sname}|${cname}${isUncertain}" class='${activeTable} border-top border-2 border-secondary ${dayNight}'>
<td class='text-start text-nowrap timeOfDay ${showTimeOfDay}'>${UI_timestamp}</td>
<td class="text-start timestamp ${showTimestamp}">${UI_position} </td>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? '<b>nocturnal</b>' : ''
sendResult(++index, `No ${nocmig} ${species} detections found ${STATE.mode === 'explore' ? 'in the Archive' : ''} using the ${STATE.list} list.`, true)
const nocmig = STATE.detect.nocmig ? '<b>nocturnal</b>' : '';
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});
Expand Down

0 comments on commit 9c41972

Please sign in to comment.