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
|
# 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)
|
||||||
#
|
#
|
||||||
# 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
|
# 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...
|
||||||
###
|
###
|
||||||
|
|||||||
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
|
@login_required
|
||||||
def get_dir_entries():
|
def get_dir_entries():
|
||||||
data = request.get_json() # Parse JSON body
|
data = request.get_json() # Parse JSON body
|
||||||
dir_id = data.get('dir_id', []) # Extract list of ids
|
dir_id = data.get('dir_id', []) # Extract list of ids
|
||||||
back = data.get('back', False) # Extract back boolean
|
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 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) )
|
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
|
# 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) )
|
||||||
ids=db.session.execute(stmt).scalars().all()
|
stmt=stmt.order_by(*order_map.get(noo) )
|
||||||
entries_schema = EntrySchema(many=True)
|
return jsonify( entry_list=db.session.execute(stmt).scalars().all() )
|
||||||
entries = Entry.query.filter(Entry.id.in_(ids)).all()
|
|
||||||
return jsonify(entries_schema.dump(entries))
|
|
||||||
|
|
||||||
# get Face overrid details
|
# get Face override details
|
||||||
def getFOT():
|
def getFOT():
|
||||||
stmt = select(FaceOverrideType)
|
stmt = select(FaceOverrideType)
|
||||||
fot=db.session.execute(stmt).scalars().all()
|
fot=db.session.execute(stmt).scalars().all()
|
||||||
|
|||||||
@@ -440,21 +440,19 @@ function getDirEntries(dir_id, back)
|
|||||||
data={}
|
data={}
|
||||||
data.dir_id=dir_id
|
data.dir_id=dir_id
|
||||||
data.back=back
|
data.back=back
|
||||||
|
data.noo=OPT.noo
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
url: '/get_dir_entries',
|
url: '/get_dir_eids',
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
document.entries=res
|
entryList=res.entry_list
|
||||||
// rebuild entryList/pageList as each dir comes with new entries
|
|
||||||
entryList=res.map(obj => obj.id);
|
|
||||||
pageList=entryList.slice(0, OPT.how_many)
|
pageList=entryList.slice(0, OPT.how_many)
|
||||||
if( back )
|
// now go get actual data/entries
|
||||||
document.back_id = res[0].in_dir.eid
|
getPage(1,getPageFigures)
|
||||||
drawPageOfFigures()
|
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
@@ -472,7 +470,8 @@ function drawPageOfFigures()
|
|||||||
|
|
||||||
if( OPT.folders )
|
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"
|
gray="_gray"
|
||||||
back=""
|
back=""
|
||||||
@@ -485,8 +484,10 @@ function drawPageOfFigures()
|
|||||||
cl="back"
|
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
|
// 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">
|
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}">
|
<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>
|
||||||
@@ -630,7 +631,7 @@ function nextPage(successCallback)
|
|||||||
// should never happen / just return pageList unchanged
|
// should never happen / just return pageList unchanged
|
||||||
if ( currentPage === -1 || isLastPage( currentPage ) )
|
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
|
return
|
||||||
}
|
}
|
||||||
getPage( currentPage+1, successCallback )
|
getPage( currentPage+1, successCallback )
|
||||||
@@ -645,7 +646,7 @@ function prevPage(successCallback)
|
|||||||
// should never happen / just return pageList unchanged
|
// should never happen / just return pageList unchanged
|
||||||
if (currentPage === 1 || currentPage === -1 )
|
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
|
return
|
||||||
}
|
}
|
||||||
getPage( currentPage-1, successCallback )
|
getPage( currentPage-1, successCallback )
|
||||||
@@ -694,7 +695,6 @@ function changeOPT(successCallback) {
|
|||||||
OPT.folders=( OPT.folders == 'True' )
|
OPT.folders=( OPT.folders == 'True' )
|
||||||
OPT.how_many=parseInt(OPT.how_many)
|
OPT.how_many=parseInt(OPT.how_many)
|
||||||
$('.how_many_text').html( ` ${OPT.how_many} files ` )
|
$('.how_many_text').html( ` ${OPT.how_many} files ` )
|
||||||
OPT.root_eid=parseInt(OPT.root_eid)
|
|
||||||
OPT.size=parseInt(OPT.size)
|
OPT.size=parseInt(OPT.size)
|
||||||
getPage(1,successCallback)
|
getPage(1,successCallback)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user