handle going into Dirs and back from Dirs by doing logic of parent dir on server side, only return eids, and get normal code to handle rendering, no specific get_dir_entries route -> its not get_dir_eids, and the rest is normal code. Much cleaner/simpler. At this point I think the major rewrite it functional, commiting before more testing and then merge code and removed firstEntryOnPage bug (its now pageList[0])

This commit is contained in:
2025-10-12 13:14:53 +11:00
parent cb5ff7e985
commit 0ac0eedef9
3 changed files with 23 additions and 23 deletions

View File

@@ -440,21 +440,19 @@ function getDirEntries(dir_id, back)
data={}
data.dir_id=dir_id
data.back=back
data.noo=OPT.noo
$.ajax({
type: 'POST',
url: '/get_dir_entries',
url: '/get_dir_eids',
data: JSON.stringify(data),
contentType: 'application/json',
dataType: 'json',
success: function(res) {
document.entries=res
// rebuild entryList/pageList as each dir comes with new entries
entryList=res.map(obj => obj.id);
entryList=res.entry_list
pageList=entryList.slice(0, OPT.how_many)
if( back )
document.back_id = res[0].in_dir.eid
drawPageOfFigures()
// now go get actual data/entries
getPage(1,getPageFigures)
},
error: function(xhr, status, error) {
console.error("Error:", error);
@@ -472,7 +470,8 @@ function drawPageOfFigures()
if( OPT.folders )
{
if( (document.entries.length && document.entries[0].in_dir.rel_path == '' ) || OPT.root_eid == 0 )
// it root_eid is 0, then no entries in this path - cant go up
if( OPT.root_eid == 0 || (document.entries.length && document.entries[0].in_dir.eid == OPT.root_eid ) )
{
gray="_gray"
back=""
@@ -485,8 +484,10 @@ function drawPageOfFigures()
cl="back"
}
// back button, if gray/back decide if we see grayed out folder and/or the name of the folder we go back to
// with clas "back" this gets a different click handler which flags server to return data by 'going back/up' in dir tree
// we give the server the id of the first item on the page so it can work out how to go back
html=`<div class="col col-auto g-0 m-1">
<figure id="${document.back_id}" ecnt="0" class="${cl} entry m-1" type="Directory">
<figure id="${document.entries[0].id}" ecnt="0" class="${cl} entry m-1" type="Directory">
<svg class="svg" width="${OPT.size-22}" height="${OPT.size-22}">
<use xlink:href="internal/icons.svg#folder_back${gray}"/>
</svg>
@@ -630,7 +631,7 @@ function nextPage(successCallback)
// should never happen / just return pageList unchanged
if ( currentPage === -1 || isLastPage( currentPage ) )
{
console.error( "WARNING: seems first on pg=" + firstEntryOnPage + " of how many=" + OPT.how_many + " gives currentPage=" + currentPage + " and we cant go next page?" )
console.error( "WARNING: seems first on pg=" + pageList[0] + " of how many=" + OPT.how_many + " gives currentPage=" + currentPage + " and we cant go next page?" )
return
}
getPage( currentPage+1, successCallback )
@@ -645,7 +646,7 @@ function prevPage(successCallback)
// should never happen / just return pageList unchanged
if (currentPage === 1 || currentPage === -1 )
{
console.error( "WARNING: seems first on pg=" + firstEntryOnPage + " of how many=" + OPT.how_many + " gives currentPage=" + currentPage + " and we cant go prev page?" )
console.error( "WARNING: seems first on pg=" + pageList[0] + " of how many=" + OPT.how_many + " gives currentPage=" + currentPage + " and we cant go prev page?" )
return
}
getPage( currentPage-1, successCallback )
@@ -694,7 +695,6 @@ function changeOPT(successCallback) {
OPT.folders=( OPT.folders == 'True' )
OPT.how_many=parseInt(OPT.how_many)
$('.how_many_text').html( `&nbsp;${OPT.how_many} files&nbsp;` )
OPT.root_eid=parseInt(OPT.root_eid)
OPT.size=parseInt(OPT.size)
getPage(1,successCallback)
}