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:
3
TODO
3
TODO
@@ -3,9 +3,6 @@
|
||||
# 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)
|
||||
#
|
||||
# 4 TEST everything (don't forget keybindings,e.g. delete)
|
||||
# going up from folder view shows different order?
|
||||
#
|
||||
# 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...
|
||||
###
|
||||
|
||||
19
files.py
19
files.py
@@ -313,28 +313,31 @@ def process_ids():
|
||||
|
||||
|
||||
################################################################################
|
||||
# /get_dir_entries -> show thumbnail view of files from import_path(s)
|
||||
# /get_dir_entries -> FIXME:
|
||||
################################################################################
|
||||
@app.route("/get_dir_entries", methods=["POST"])
|
||||
@app.route("/get_dir_eids", methods=["POST"])
|
||||
@login_required
|
||||
def get_dir_entries():
|
||||
data = request.get_json() # Parse JSON body
|
||||
dir_id = data.get('dir_id', []) # Extract list of ids
|
||||
back = data.get('back', False) # Extract back boolean
|
||||
noo = data.get('noo', "A to Z") # Extract noo ordering
|
||||
|
||||
# if we are going back, find the parent id and use that instead
|
||||
if back:
|
||||
# find current dir
|
||||
stmt=( select(EntryDirLink.dir_eid).filter(EntryDirLink.entry_id==dir_id) )
|
||||
dir_id = db.session.execute(stmt).scalars().all() [0]
|
||||
dir_id = db.session.execute(stmt).scalars().one_or_none()
|
||||
# get parent of this dir, to go back
|
||||
stmt=( select(EntryDirLink.dir_eid).filter(EntryDirLink.entry_id==dir_id) )
|
||||
dir_id = db.session.execute(stmt).scalars().one_or_none()
|
||||
|
||||
# get content of dir_id
|
||||
stmt=( select(Entry.id).join(EntryDirLink).filter(EntryDirLink.dir_eid==dir_id) )
|
||||
ids=db.session.execute(stmt).scalars().all()
|
||||
entries_schema = EntrySchema(many=True)
|
||||
entries = Entry.query.filter(Entry.id.in_(ids)).all()
|
||||
return jsonify(entries_schema.dump(entries))
|
||||
stmt=stmt.order_by(*order_map.get(noo) )
|
||||
return jsonify( entry_list=db.session.execute(stmt).scalars().all() )
|
||||
|
||||
# get Face overrid details
|
||||
# get Face override details
|
||||
def getFOT():
|
||||
stmt = select(FaceOverrideType)
|
||||
fot=db.session.execute(stmt).scalars().all()
|
||||
|
||||
@@ -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( ` ${OPT.how_many} files ` )
|
||||
OPT.root_eid=parseInt(OPT.root_eid)
|
||||
OPT.size=parseInt(OPT.size)
|
||||
getPage(1,successCallback)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user