made search a POST to /search be a redirect to a GET /search/<search_term> so that it works with back/forward buttons in the browser

This commit is contained in:
2022-01-19 22:40:47 +11:00
parent a2091f0194
commit 505a5fa813
4 changed files with 23 additions and 16 deletions

View File

@@ -238,8 +238,8 @@ def GetEntriesInFolderView( OPT, prefix ):
################################################################################
def GetEntries( OPT ):
entries=[]
if 'search_term' in request.form:
search_term=request.form['search_term']
if OPT.path_type == 'Search':
search_term=OPT.search_term
if 'AI:' in search_term:
search_term = search_term.replace('AI:','')
all_entries = Entry.query.join(File).join(FaceFileLink).join(Face).join(FaceRefimgLink).join(Refimg).join(PersonRefimgLink).join(Person).filter(Person.tag.ilike(f"%{search_term}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(OPT.offset).limit(OPT.how_many).all()
@@ -336,20 +336,30 @@ def files_rbp():
move_paths = MovePathDetails()
return render_template("files.html", page_title=f"View Files ({OPT.path_type} Path)", entry_data=entries, OPT=OPT, move_paths=move_paths )
################################################################################
# /search -> show thumbnail view of files from import_path(s)
# search -> GET version -> has search_term in the URL and is therefore able to
# be used even if the user hits the front/back buttons in the browser.
# func shows thumbnails of matching files.
################################################################################
@app.route("/search", methods=["GET","POST"])
@app.route("/search/<search_term>", methods=["GET"])
@login_required
def search():
def search(search_term):
OPT=Options( request )
OPT.search_term = search_term
# always show flat results for search to start with
OPT.folders=False
OPT.paths=None
entries=GetEntries( OPT )
move_paths = MovePathDetails()
return render_template("files.html", page_title='View Files', search_term=request.form['search_term'], entry_data=entries, OPT=OPT, move_paths=move_paths )
return render_template("files.html", page_title='View Files', search_term=search_term, entry_data=entries, OPT=OPT, move_paths=move_paths )
################################################################################
# /search -> POST version -> only used on form submit when you hit return. This
# form just redirects to a GET of /search/<search_term> to trip route above
################################################################################
@app.route("/search", methods=["POST"])
@login_required
def search_post():
return redirect( "/search/"+request.form['search_term'] )
################################################################################
# /files/scannow -> allows us to force a check for new files

View File

@@ -41,9 +41,7 @@
<div class="row">
{% for s in stats %}
<div class="col-1">
<form id="_{{s[0]}}" method="POST" action="{{url_for('search')}}">
<input type="hidden" name="search_term" value="AI:{{s[0]}}">
<a href="javascript:$('#_{{s[0]}}').submit()">{{s[0]}}</a></form>
<a href="javascript:st=$('#search_term').val(); document.location.href='/search/AI:{{s[0]}}'">{{s[0]}}</a>
</div>
<div class="col-1"><center>{{s[1]}}</center></div>
<div class="col-1"> </div>

View File

@@ -111,8 +111,8 @@
<input type="hidden" id="search_size" name="size" value="">
<input type="hidden" id="search_folders" name="folders" value="">
<input type="hidden" id="search_cwd" name="cwd" value="">
<input class="form-control" type="search" placeholder="by file, date (YYYMMDD) or tag" aria-label="Search" name="search_term">
<button class="btn btn-outline-success" type="submit">Search</button>
<input id="search_term" class="form-control" type="search" placeholder="by file, date (YYYMMDD) or tag" aria-label="Search" name="search_term">
<button class="btn btn-outline-success" onClick="javascript:st=$('#search_term').val(); document.location.href='/search/'+st" type="button">Search</button>
</form>
<div class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-bs-toggle="dropdown" aria-expanded="false">

View File

@@ -12,9 +12,8 @@
<tr><td><a href="{{url_for('person', id=person.id )}}">{{person.tag}}</td>
<td>
{% if person.num_matches %}
<form id="_{{person.tag}}" method="POST" action="{{url_for('search')}}">
<input type="hidden" name="search_term" value="AI:{{person.tag}}">
<a href="javascript:$('#_{{person.tag}}').submit()">{{person.num_matches}} matches</a></form>
<a href="javascript:st=$('#search_term').val(); document.location.href='/search/AI:{{person.tag}}'">
{{person.num_matches}} matches</a>
{% else %}
No matches
{% endif %}