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:
6
TODO
6
TODO
@@ -1,13 +1,13 @@
|
|||||||
###
|
###
|
||||||
#
|
#
|
||||||
|
#
|
||||||
# consider how to better version jscript - across all html files, consistently
|
# 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)
|
# 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
|
# 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...
|
# 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], would need -> entrylist, pagelist, entries AND we need to consider if cache can be invalidated, then how do I know / do I care... I THINK not, as the data is all self-contained, only will go pear shaped if we get a new page, and then it shoudl get a new set of entry ids -- now, if they are not fully contained in entrylist, we have a problem -- IS that the condition I should check?
|
# 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
|
||||||
## the above needs thought, even without cache, I go back a dir, and its now deleted, or I go forward/back a page and the entry ids have changed is there any way this can bite me... I think only if flat view the next/prev page of ids has no content / unexpected content? get_dir_eids is a new hit each time, so it could fail for deleted folders, etc.
|
|
||||||
###
|
###
|
||||||
|
|
||||||
### major fix - go to everywhere I call GetEntries(), and redo the logic totally...
|
### major fix - go to everywhere I call GetEntries(), and redo the logic totally...
|
||||||
|
|||||||
19
files.py
19
files.py
@@ -313,7 +313,9 @@ def process_ids():
|
|||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# /get_dir_entries -> FIXME:
|
# /get_dir_entries:
|
||||||
|
# -> if back is false - returns list of eids inside this dir
|
||||||
|
# -> if back is true - returns list of eids inside the parent of this dir
|
||||||
################################################################################
|
################################################################################
|
||||||
@app.route("/get_dir_eids", methods=["POST"])
|
@app.route("/get_dir_eids", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@@ -325,17 +327,24 @@ def get_dir_entries():
|
|||||||
|
|
||||||
# if we are going back, find the parent id and use that instead
|
# if we are going back, find the parent id and use that instead
|
||||||
if back:
|
if back:
|
||||||
# find current dir
|
|
||||||
stmt=( select(EntryDirLink.dir_eid).filter(EntryDirLink.entry_id==dir_id) )
|
|
||||||
dir_id = db.session.execute(stmt).scalars().one_or_none()
|
|
||||||
# get parent of this dir, to go back
|
# get parent of this dir, to go back
|
||||||
stmt=( select(EntryDirLink.dir_eid).filter(EntryDirLink.entry_id==dir_id) )
|
stmt=( select(EntryDirLink.dir_eid).filter(EntryDirLink.entry_id==dir_id) )
|
||||||
dir_id = db.session.execute(stmt).scalars().one_or_none()
|
dir_id = db.session.execute(stmt).scalars().one_or_none()
|
||||||
|
if not dir_id:
|
||||||
|
# return valid as false, we need to let user know this is not an empty dir, it does not exist
|
||||||
|
return jsonify( valid=False, entry_list=[] )
|
||||||
|
|
||||||
|
# Just double-check this is still in the DB, in case it got deleted since client made view
|
||||||
|
stmt=( select(Entry.id).where(Entry.id==dir_id) )
|
||||||
|
ent_id = db.session.execute(stmt).scalars().one_or_none()
|
||||||
|
if not ent_id:
|
||||||
|
# return valid as false, we need to let user know this is not an empty dir, it does not exist
|
||||||
|
return jsonify( valid=False, entry_list=[] )
|
||||||
|
|
||||||
# get content of dir_id
|
# get content of dir_id
|
||||||
stmt=( select(Entry.id).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir_id) )
|
stmt=( select(Entry.id).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir_id) )
|
||||||
stmt=stmt.order_by(*order_map.get(noo) )
|
stmt=stmt.order_by(*order_map.get(noo) )
|
||||||
return jsonify( entry_list=db.session.execute(stmt).scalars().all() )
|
return jsonify( valid=True, entry_list=db.session.execute(stmt).scalars().all() )
|
||||||
|
|
||||||
# get Face override details
|
# get Face override details
|
||||||
def getFOT():
|
def getFOT():
|
||||||
|
|||||||
@@ -449,6 +449,11 @@ function getDirEntries(dir_id, back)
|
|||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(res) {
|
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
|
entryList=res.entry_list
|
||||||
pageList=entryList.slice(0, OPT.how_many)
|
pageList=entryList.slice(0, OPT.how_many)
|
||||||
// now go get actual data/entries
|
// now go get actual data/entries
|
||||||
@@ -468,6 +473,10 @@ function drawPageOfFigures()
|
|||||||
var last = { printed: null }
|
var last = { printed: null }
|
||||||
var ecnt=0
|
var ecnt=0
|
||||||
|
|
||||||
|
// something is up, let the user know
|
||||||
|
if( document.alert )
|
||||||
|
$('#figures').append( document.alert )
|
||||||
|
|
||||||
if( OPT.folders )
|
if( OPT.folders )
|
||||||
{
|
{
|
||||||
// it root_eid is 0, then no entries in this path - cant go up
|
// it root_eid is 0, then no entries in this path - cant go up
|
||||||
@@ -476,18 +485,23 @@ function drawPageOfFigures()
|
|||||||
gray="_gray"
|
gray="_gray"
|
||||||
back=""
|
back=""
|
||||||
cl=""
|
cl=""
|
||||||
|
back_id=0
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gray=""
|
gray=""
|
||||||
back="Back"
|
back="Back"
|
||||||
cl="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
|
// 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
|
// 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
|
// 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">
|
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}">
|
<svg class="svg" width="${OPT.size-22}" height="${OPT.size-22}">
|
||||||
<use xlink:href="internal/icons.svg#folder_back${gray}"/>
|
<use xlink:href="internal/icons.svg#folder_back${gray}"/>
|
||||||
</svg>
|
</svg>
|
||||||
@@ -517,6 +531,11 @@ function drawPageOfFigures()
|
|||||||
function getPageFileList(res, viewingIdx)
|
function getPageFileList(res, viewingIdx)
|
||||||
{
|
{
|
||||||
$('#file_list_div').empty()
|
$('#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 )
|
if( OPT.root_eid == 0 )
|
||||||
{
|
{
|
||||||
$('#file_list_div').append( `<span class="alert alert-danger p-2">No files in Path!</span>` )
|
$('#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={}
|
||||||
data.ids = pageList
|
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({
|
$.ajax({
|
||||||
type: 'POST', url: '/get_entries_by_ids',
|
type: 'POST', url: '/get_entries_by_ids',
|
||||||
data: JSON.stringify(data), contentType: 'application/json',
|
data: JSON.stringify(data), contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(res) {
|
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;
|
document.entries=res;
|
||||||
successCallback(res,viewingIdx)
|
successCallback(res,viewingIdx)
|
||||||
resetNextPrevButtons()
|
resetNextPrevButtons()
|
||||||
|
|||||||
Reference in New Issue
Block a user