removed use of last_entry_in_db (boolean) and replaced with use of current/first_eid/last_eid in PA_USER_STATE so it persists across reloads/back buttons, and allows full use of ajax data retrieval in the background for the viewer (so fullscreen stays across page loads), and the next/prev buttons are set on the image load, not after they have been pressed "one too many times"

This commit is contained in:
2022-01-27 14:27:52 +11:00
parent 08ca9b4e74
commit 55724ccd59
5 changed files with 64 additions and 33 deletions

View File

@@ -20,7 +20,7 @@ import re
import json
import datetime
from flask_login import login_required, current_user
from states import States
from states import States, PA_UserState
################################################################################
# Local Class imports
@@ -291,8 +291,15 @@ def GetEntries( OPT ):
# can only be 1 due to limit above
for l in last_entry:
OPT.last_eid = l.id
print( f"f={OPT.first_eid}, l={OPT.last_eid} -- STORE THESE in pa_user_state" )
print( f"c={OPT.current}, f={OPT.first_eid}, l={OPT.last_eid} -- STORE THESE in pa_user_state" )
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==OPT.path_type,PA_UserState.orig_ptype==OPT.orig_ptype,PA_UserState.orig_search_term==search_term).first()
pref.current=OPT.current
pref.first_eid=OPT.first_eid
pref.last_eid=OPT.last_eid
print( f"stored pref: {pref}" )
db.session.add(pref)
db.session.commit()
return all_entries
# if we are a view, then it will be of something else, e.g. a list of
@@ -564,7 +571,6 @@ def move_files():
@app.route("/viewlist", methods=["POST"])
def viewlist():
OPT=States( request )
OPT.last_entry_in_db=0
# Get next/prev set of data - e.g. if next set, then it will use orig_url
# to go forward how_many from offset and then use viewer.html to show that
# first obj of the new list of entries
@@ -576,7 +582,6 @@ def viewlist():
OPT.offset -= int(OPT.how_many)
entries=GetEntries( OPT )
# now flag we are at the last in db, to reset current below
OPT.last_entry_in_db=1
objs = {}
eids=""
resp={}
@@ -614,15 +619,19 @@ def viewlist():
current = int(lst[0])
if 'prev' in request.form:
current = int(lst[-1])
if OPT.last_entry_in_db:
# force this back to the last image of the last page - its the last in the DB, so set OPT for it
current = int(lst[-1])
OPT.last_entry_in_db=current
resp['current']=current
resp['first_eid']=OPT.first_eid
resp['last_eid']=OPT.last_eid
resp['eids']=eids
resp['offset']=OPT.offset
resp['last_entry_in_db']=OPT.last_entry_in_db
print( "DDP: SAVE PREF HERE TO GET NEW CURRENT AND FIX back button WITH view/XXX when you next/prev to different page" )
pref=PA_UserState.query.filter(PA_UserState.pa_user_dn==current_user.dn,PA_UserState.path_type==OPT.path_type,PA_UserState.view_eid==OPT.view_eid).first()
pref.current=current
print( f"stored pref: {pref}" )
db.session.add(pref)
db.session.commit()
return resp
@@ -630,7 +639,6 @@ def viewlist():
@app.route("/view/<id>", methods=["GET"])
def view(id):
OPT=States( request )
OPT.last_entry_in_db=0
objs = {}
entries=GetEntries( OPT )
eids=""