From 9ec8195d0a7f4b7511ccab5ec329e785f2bf3791 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Fri, 26 Sep 2025 19:25:19 +1000 Subject: [PATCH] first pass of supprot functions to allow query/entry_list to drive pagination, and do not go back to the server to calc next/prev page --- internal/js/files_support.js | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/internal/js/files_support.js b/internal/js/files_support.js index 2def58a..17cfdea 100644 --- a/internal/js/files_support.js +++ b/internal/js/files_support.js @@ -316,3 +316,90 @@ function NoSel() { else return true } + +function handlePageOfData() +{ + // FIXME: this should get back a json'd array of entries, and I can/should + // use this to redraw the figures dynamically on the page +} + + +// Function to get the 'page' of entry ids out of entryList +function getPage(pageNumber) +{ + const startIndex = (pageNumber - 1) * howMany; + const endIndex = startIndex + howMany; + pageList = entryList.slice(startIndex, endIndex); + // FIXME: should POST here to get the data for new pl + return +} + +// Quick Function to check if we are on the first page +function isFirstPage(pageNumber) +{ + return pageNumber <= 1; +} + +// Function to check if we are on the last page +function isLastPage(pageNumber) +{ + const totalPages = Math.ceil(entryList.length / howMany); + return pageNumber >= totalPages; +} + +// given an id in the list, return which page we are on (page 1 is first page) +function getPageNumberForId(id) { + const idx = entryList.indexOf(id); + // should be impossible but jic + if (idx === -1) { + return -1; // or null, if you prefer + } + return Math.floor(idx / howMany) + 1; +} + +// if we are on first page, disable prev, it not ensure next is enabled +// if we are on last page, disable next, it not ensure prev is enabled +function resetNextPrevButtons() +{ + if ( isFirstPage( getPageNumberForId(pageList[0]) ) ) + $('.prev').prop('disabled', true).addClass('disabled'); + else + $('.prev').prop('disabled', false).removeClass('disabled'); + + if ( isLastPage( getPageNumberForId(pageList[0]) ) ) + $('.next').prop('disabled', true).addClass('disabled'); + else + $('.next').prop('disabled', false).removeClass('disabled'); +} + +// get list of eids for the next page, also make sure next/prev buttons make sense for page we are on +function nextPage() +{ + // pageList[0] is the first entry on this page + const currentPage=getPageNumberForId( pageList[0] ) + // should never happen / just return pageList unchanged + if ( currentPage === -1 || isLastPage( currentPage ) ) + { + console.log( "WARNING: seems first on pg=" + firstEntryOnPage + " of how many=" + howMany + " gives currentPage=" + currentPage + " and we cant go next page?" ) + return + } + getPage( currentPage+1 ) + resetNextPrevButtons() + return +} + +// get list of eids for the prev page, also make sure next/prev buttons make sense for page we are on +function prevPage() +{ + // pageList[0] is the first entry on this page + const currentPage=getPageNumberForId( pageList[0] ) + // should never happen / just return pageList unchanged + if (currentPage === 1 || currentPage === -1 ) + { + console.log( "WARNING: seems first on pg=" + firstEntryOnPage + " of how many=" + howMany + " gives currentPage=" + currentPage + " and we cant go prev page?" ) + return + } + getPage( currentPage-1 ) + resetNextPrevButtons() + return +}