diff --git a/TODO b/TODO index f37200b..88405ff 100644 --- a/TODO +++ b/TODO @@ -1,13 +1,11 @@ ### # -# # consider how to better version jscript - across all html files, consistently # mtime, didnt work anyway, my phone still wont pick up the change, it was adding any ?v= changed this (once) # # 5 think I killed pa_job_manager without passing an eid to a transform job, shouldn't crash # SHOULD JUST get AI to help clean-up and write defensive code here... # -# could cache getPage into document.page[x], then check if it exists, if so, don't go back to server for all the data, page[x], can just store document.entries ### ### major fix - go to everywhere I call GetEntries(), and redo the logic totally... diff --git a/internal/js/files_support.js b/internal/js/files_support.js index de0bd2a..5a8a90a 100644 --- a/internal/js/files_support.js +++ b/internal/js/files_support.js @@ -562,6 +562,29 @@ function getPageFileList(res, viewingIdx) $('#file_list_div').append(html) } +// wrapper function as we want to handle real DB query success, but also do the +// same when we just use cache +function getEntriesByIdSuccessHandler(res,pageNumber,successCallback,viewingIdx) +{ + if( res.length != pageList.length ) + document.alert="WARNING: something in data has changed since viewing this page (likely someone deleted content in another view), strongly suggest a page reload to get the latest data" + + document.entries=res; + // cache this + document.page[pageNumber]=res + successCallback(res,viewingIdx) + resetNextPrevButtons() + // if search, disable folders + if( OPT.search_term ) + $('#folders').prop('disabled', 'disabled').removeClass('border-info').addClass('border-secondary').removeClass('text-info').addClass('text-secondary'); + else if( document.entries.length == 0 ) + { + html=`No files in Path` + $('#file_list_div').append(html) + $('#figures').append(html) + } +} + // Function to get the 'page' of entry ids out of entryList function getPage(pageNumber, successCallback, viewingIdx=0) { @@ -579,28 +602,18 @@ function getPage(pageNumber, successCallback, viewingIdx=0) // assume nothing wrong, but if the data goes odd, then this will be non-null and displayed later (cant add here, as later code does .empty() of file divs) document.alert=null + // see if we can use cache, and dont reload from DB + if( !OPT.folders && document.page.length && document.page[pageNumber] ) + { + getEntriesByIdSuccessHandler( document.page[pageNumber], pageNumber, successCallback, viewingIdx ) + return + } $.ajax({ type: 'POST', url: '/get_entries_by_ids', data: JSON.stringify(data), contentType: 'application/json', dataType: 'json', - success: function(res) { - if( res.length != pageList.length ) - document.alert="WARNING: something in data has changed since viewing this page (likely someone deleted content in another view), strongly suggest a page reload to get the latest data" - - document.entries=res; - successCallback(res,viewingIdx) - resetNextPrevButtons() - // if search, disable folders - if( OPT.search_term ) - $('#folders').prop('disabled', 'disabled').removeClass('border-info').addClass('border-secondary').removeClass('text-info').addClass('text-secondary'); - else if( document.entries.length == 0 ) - { - html=`No files in Path` - $('#file_list_div').append(html) - $('#figures').append(html) - } - }, + success: function(res) { getEntriesByIdSuccessHandler( res, pageNumber, successCallback, viewingIdx ) }, error: function(xhr, status, error) { console.error("Error:", error); } }); return } @@ -824,3 +837,4 @@ $.contextMenu({ // finally, for files_ip/files_sp/files_rbp - set click inside document (NOT an entry) to remove seln $(document).on('click', function(e) { $('.highlight').removeClass('highlight') ; SetButtonState() }); +document.page=[]