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:
25
states.py
25
states.py
@@ -31,9 +31,12 @@ class PA_UserState(db.Model):
|
||||
# only used if view and orig_ptype was search
|
||||
orig_search_term = db.Column(db.String, unique=False, nullable=False )
|
||||
orig_url = db.Column(db.String, unique=False, nullable=False )
|
||||
current = db.Column(db.Integer)
|
||||
first_eid = db.Column(db.Integer)
|
||||
last_eid = db.Column(db.Integer)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<pa_user_dn: {self.pa_user_dn}, path_type: {self.path_type}, noo: {self.noo}, grouping: {self.grouping}, how_many: {self.how_many}, st_offset: {self.st_offset}, size: {self.size}, folders: {self.folders}, root: {self.root}, cwd: {self.cwd}, view_eid: {self.view_eid}, orig_ptype: {self.orig_ptype}, orig_search_term: {self.orig_search_term}, orig_url: {self.orig_url}>"
|
||||
return f"<pa_user_dn: {self.pa_user_dn}, path_type: {self.path_type}, noo: {self.noo}, grouping: {self.grouping}, how_many: {self.how_many}, st_offset: {self.st_offset}, size: {self.size}, folders: {self.folders}, root: {self.root}, cwd: {self.cwd}, view_eid: {self.view_eid}, orig_ptype: {self.orig_ptype}, orig_search_term: {self.orig_search_term}, orig_url: {self.orig_url}, current={self.current}, first_eid={self.first_eid}, last_eid={self.last_eid}>"
|
||||
|
||||
|
||||
################################################################################
|
||||
@@ -46,8 +49,9 @@ class States(PA):
|
||||
self.path_type=''
|
||||
self.url = request.path
|
||||
self.view_eid = None
|
||||
self.first_eid = 0
|
||||
self.last_eid = 0
|
||||
self.current=0
|
||||
self.first_eid=0
|
||||
self.last_eid=0
|
||||
|
||||
print( f"States() - path={request.path}, ref={request.referrer}" )
|
||||
|
||||
@@ -135,6 +139,10 @@ class States(PA):
|
||||
self.orig_search_term=pref.orig_search_term
|
||||
self.orig_url = pref.orig_url
|
||||
self.view_eid = pref.view_eid
|
||||
self.current = pref.current
|
||||
print( f"from existing pref, set self.first_eid to {pref.first_eid}" )
|
||||
self.first_eid = pref.first_eid
|
||||
self.last_eid = pref.last_eid
|
||||
else:
|
||||
# retreive defaults from 'PAUser' where defaults are stored
|
||||
u=PAUser.query.filter(PAUser.dn==current_user.dn).one()
|
||||
@@ -208,13 +216,16 @@ class States(PA):
|
||||
self.offset=0
|
||||
if 'next' in request.form:
|
||||
self.offset += int(self.how_many)
|
||||
if 'current' in request.form:
|
||||
self.current = int(request.form['current'])
|
||||
|
||||
# now save pref
|
||||
if not pref:
|
||||
# insert new pref for this combo (might be a new search or view, or first time for a path)
|
||||
pref=PA_UserState( pa_user_dn=current_user.dn, path_type=self.path_type, view_eid=self.view_eid, noo=self.noo, grouping=self.grouping, how_many=self.how_many,
|
||||
st_offset=self.offset, size=self.size, folders=self.folders, root=self.root, cwd=self.cwd,
|
||||
orig_ptype=self.orig_ptype, orig_search_term=self.orig_search_term, orig_url=self.orig_url )
|
||||
pref=PA_UserState( pa_user_dn=current_user.dn, path_type=self.path_type, view_eid=self.view_eid, noo=self.noo,
|
||||
grouping=self.grouping, how_many=self.how_many, st_offset=self.offset, size=self.size, folders=self.folders,
|
||||
root=self.root, cwd=self.cwd, orig_ptype=self.orig_ptype, orig_search_term=self.orig_search_term,
|
||||
orig_url=self.orig_url, current=self.current, first_eid=self.first_eid, last_eid=self.last_eid )
|
||||
else:
|
||||
# update this pref with the values calculated above (most likely from POST to form)
|
||||
pref.pa_user_dn=current_user.dn
|
||||
@@ -231,6 +242,8 @@ class States(PA):
|
||||
pref.orig_ptype = self.orig_ptype
|
||||
pref.orig_search_term = self.orig_search_term
|
||||
pref.orig_url = self.orig_url
|
||||
pref.current = self.current
|
||||
# first_eid and last_eid wont change in this func, set only in GetEntries()
|
||||
|
||||
db.session.add(pref)
|
||||
db.session.commit()
|
||||
|
||||
Reference in New Issue
Block a user