reverted partial client side back button logic, but also now tested / validated if somehow we are in a flat view and ask for entries and dont get all of them back, or we are in folder view and we try to go into a folder or back up a folder and we get no data as someone deleted it since we made the view, so then show appropriate client-side errors

This commit is contained in:
2025-10-12 16:02:21 +11:00
parent e3f6b416ce
commit b61f048dec
3 changed files with 43 additions and 9 deletions

View File

@@ -449,6 +449,11 @@ function getDirEntries(dir_id, back)
contentType: 'application/json',
dataType: 'json',
success: function(res) {
if( res.valid === false )
{
$('#figures').html( "<alert class='alert alert-danger'>ERROR! directory has changed since you loaded this view. You have to reload and reset your view (probably someone deleted the directory or its parent since you loaded this page)" )
return
}
entryList=res.entry_list
pageList=entryList.slice(0, OPT.how_many)
// now go get actual data/entries
@@ -468,6 +473,10 @@ function drawPageOfFigures()
var last = { printed: null }
var ecnt=0
// something is up, let the user know
if( document.alert )
$('#figures').append( document.alert )
if( OPT.folders )
{
// it root_eid is 0, then no entries in this path - cant go up
@@ -476,18 +485,23 @@ function drawPageOfFigures()
gray="_gray"
back=""
cl=""
back_id=0
}
else
{
gray=""
back="Back"
cl="back"
if( document.entries.length > 0 )
back_id = document.entries[0].in_dir.eid
else
back_id = document.back_id
}
// 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.entries[0].id}" ecnt="0" class="${cl} entry m-1" type="Directory">
<figure id="${back_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>
@@ -517,6 +531,11 @@ function drawPageOfFigures()
function getPageFileList(res, viewingIdx)
{
$('#file_list_div').empty()
// something is up, let the user know
if( document.alert )
$('#file_list_div').append( '<div class="row">' + document.alert + '</div>' )
if( OPT.root_eid == 0 )
{
$('#file_list_div').append( `<span class="alert alert-danger p-2">No files in Path!</span>` )
@@ -558,11 +577,17 @@ function getPage(pageNumber, successCallback, viewingIdx=0)
data={}
data.ids = pageList
// 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
$.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="<alert class='alert alert-warning'>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</alert>"
document.entries=res;
successCallback(res,viewingIdx)
resetNextPrevButtons()