From f30ca16552e94961f4ee1be544eb1b7546b63fbf Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Thu, 15 Jul 2021 20:23:02 +1000 Subject: [PATCH] added viewnext and viewprev routes and plumbed these in to the file viewer code. Viewer code now works has a prev/next button, and handles videos --- TODO | 6 ++- files.py | 31 ++++++++++++ templates/files.html | 43 ++++++++++++----- templates/viewer.html | 108 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 174 insertions(+), 14 deletions(-) create mode 100644 templates/viewer.html diff --git a/TODO b/TODO index 10e373e..20feac4 100644 --- a/TODO +++ b/TODO @@ -1,8 +1,9 @@ ## GENERAL - * allow rotate of image (permanently on FS, so its right everywhere) + * file browser: + - maybe back feature/button? - * improve photo browser -> view file, rather than just allowing browser to show image + * allow rotate of image (permanently on FS, so its right everywhere) * face locations: START FORM SCRATCH so all images have face_locn data @@ -16,6 +17,7 @@ * refimg - remove AI menu from top-level -> make a sub-of Person, and just have Match or AI + * remove dirs after the duplicate cleanup removes all its content * fix up logging in general * comment your code * more OO goodness :) diff --git a/files.py b/files.py index 51b6348..2b8dce3 100644 --- a/files.py +++ b/files.py @@ -450,6 +450,37 @@ def move_files(): st.SetMessage( f"Created Job #{job.id} to move selected file(s)") return render_template("base.html") +@app.route("/viewnext", methods=["GET","POST"]) +@login_required +def viewnext(): + if request.method=="POST": + id = request.form['current'] + eids=request.form['eids'] + lst = eids.split(',') + new_id = lst[lst.index(id)+1] + obj = Entry.query.join(File).filter(Entry.id==new_id).first() + return render_template("viewer.html", obj=obj, eids=eids) + +@app.route("/viewprev", methods=["GET","POST"]) +@login_required +def viewprev(): + if request.method=="POST": + id = request.form['current'] + eids=request.form['eids'] + lst = eids.split(',') + new_id = lst[lst.index(id)-1] + obj = Entry.query.join(File).filter(Entry.id==new_id).first() + return render_template("viewer.html", obj=obj, eids=eids) + +@app.route("/view/", methods=["GET","POST"]) +@login_required +def view_img(id): + obj = Entry.query.join(File).filter(Entry.id==id).first() + if request.method=="POST": + eids=request.form['eids'] + else: + eids='' + return render_template("viewer.html", obj=obj, eids=eids) ################################################################################ # /static -> returns the contents of any file referenced inside /static. diff --git a/templates/files.html b/templates/files.html index 8affac7..330d7c0 100644 --- a/templates/files.html +++ b/templates/files.html @@ -111,6 +111,14 @@ + {% set eids=namespace( str="" ) %} + {# gather all the file eids and collect them in case we go gallery mode #} + {% for obj in entry_data %} + {% if obj.type.name != "Directory" %} + {% set eids.str = eids.str + obj.id|string +"," %} + {% endif %} + {% endfor %} + {% set last = namespace(printed=0) %} @@ -122,7 +130,7 @@ {% if folders and entry_data|length == 0 %} {% if cwd != root %}
- + @@ -130,7 +138,7 @@
{% else %} {# create an even lighter-grey, unclickable back button - so folders dont jump around when you go into them #} - + @@ -140,7 +148,7 @@ {% if loop.index==1 and folders %} {% if cwd != root %}
- + @@ -148,7 +156,7 @@
{% else %} {# create an even lighter-grey, unclickable back button - so folders dont jump around when you go into them #} - + @@ -193,7 +201,7 @@ {% if search_term is defined %}
- +
{% endif %} @@ -201,11 +209,11 @@
- +
{% if search_term is defined %}
- +
{% endif %}
@@ -223,7 +231,7 @@ {# if this dir is the toplevel of the cwd, show the folder icon #} {% if dirname| TopLevelFolderOf(cwd) %}
- +
{{obj.name}}
{% endif %} @@ -382,12 +390,12 @@ function ChangeSize(clicked_button,sz) { $('.sz-but.btn-info').removeClass('btn-info').addClass('btn-outline-info') $(clicked_button).addClass('btn-info').removeClass('btn-outline-info') - $('.thumb').attr( {height: sz, style: 'font-size:'+sz } ) + $('.thumb').attr( {height: sz, style: 'font-size:'+sz+'px' } ) $('#size').val(sz) sz=sz-22 - $('.fa-folder').attr( {style: 'font-size:'+sz } ) + $('.fa-folder').attr( {style: 'font-size:'+sz+'px' } ) sz=sz/2 - $('.fa-stack').attr( {style: 'color:grey;font-size:'+sz} ) + $('.fa-stack').attr( {style: 'color:grey;font-size:'+sz+'px'} ) } // e == event (can see if shift/ctrl held down while left-clicking @@ -488,6 +496,13 @@ function NoSel() { $('.figure').click( function(e) { DoSel(e, this ); SetButtonState(); return false; }); $(document).on('click', function(e) { $('.highlight').removeClass('highlight') ; SetButtonState() }); +$('.figure').dblclick( + function() { + s='
' + $(s).appendTo('body').submit(); } + ); + // different context menu on files $.contextMenu({ @@ -529,7 +544,11 @@ $.contextMenu({ return { callback: function( key, options) { if( key == "details" ) { DetailsDBox() } - if( key == "view" ) { document.location.href = $(this).find('a').attr('href'); } + if( key == "view" ) { + s='
' + $(s).appendTo('body').submit(); + } if( key == "move" ) { MoveDBox() } if( key == "del" ) { DelDBox('Delete') } if( key == "undel" ) { DelDBox('Restore') } diff --git a/templates/viewer.html b/templates/viewer.html new file mode 100644 index 0000000..9fbcd9d --- /dev/null +++ b/templates/viewer.html @@ -0,0 +1,108 @@ +{% extends "base.html" %} {% block main_content %} + + +
+ {% set max=eids.split(',')|length %} +
+
+ +
+ {% if eids.find(obj.id|string) > 0 %} +
+ + + +
+ {% endif %} + {% if obj.type.name == "Image" %} +
+ + +
{{obj.name}}
+
+ {% elif obj.type.name == "Video" %} + + + {% endif %} + + {% for eid in eids.split(',') %} + {% if loop.index == max-1 %} + {% if eid|int != obj.id %} +
+ + + +
+ {% endif %} + {% endif %} + {% endfor %} +
+
+ + +{% endblock main_content %}