From 1ece519a2aff1c4e352ec8287c6b7463d41c7039 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Tue, 6 Apr 2021 17:05:24 +1000 Subject: [PATCH] added first pass of viewing by folders, see TODO for next steps --- TODO | 5 +++- files.py | 54 ++++++++++++++++++++++++++++++++++++++------ templates/base.html | 12 ++++++++++ templates/files.html | 36 ++++++++++++++++++++++++++++- 4 files changed, 98 insertions(+), 9 deletions(-) diff --git a/TODO b/TODO index e847d01..741094b 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,12 @@ ## GENERAL + * storage_path viewing needs to be by folder / not a big grab bag of files (by default) + -- mostly done. Need to toggle the view if I want, and when viewing storage area, change single-click to be view file again, and right-click to be my context menu + * when we put files in recycle bin, they need to stay in the DB and just have their root/base path moved (so they can be view as per above/below) + - do I need a 'import/storage/recycle' path/dir 'type'? * doing actual file deletes needed again [DONE] - decided a recycle bin would be good [DONE] - could also allow undelete per file / show content as another Files->View and more like storage (i.e. show folders) * AddJobForLog can absorb DEBUGs, etc. in fact fix up logging in general - * storage_path viewing needs to be by folder / not a big grab bag of files (by default) * comment your code * do we need to make some funcs/code into OO? * need a way for page to show we are in import_path or storage_path diff --git a/files.py b/files.py index 45f07af..9441089 100644 --- a/files.py +++ b/files.py @@ -122,6 +122,13 @@ def ViewingOptions( request ): how_many="50" offset=0 size=128 + print( f"ViewingOptions( {request.method} )" ) + if 'files_sp' in request.path: + folders=True + cwd='static/storage' + else: + folders=False + cwd=None if request.method=="POST": noo=request.form['noo'] @@ -129,6 +136,9 @@ def ViewingOptions( request ): offset=int(request.form['offset']) grouping=request.form['grouping'] size = request.form['size'] + folders = request.form['folders'] + cwd = request.form['cwd'] + print( f"setting cwd basedon form: {cwd}" ) if 'prev' in request.form: offset -= int(how_many) if offset < 0: @@ -136,7 +146,7 @@ def ViewingOptions( request ): if 'next' in request.form: offset += int(how_many) - return noo, grouping, how_many, offset, size + return noo, grouping, how_many, offset, size, folders, cwd ################################################################################ # /file_list -> show detailed file list of files from import_path(s) @@ -151,7 +161,7 @@ def file_list_ip(): @app.route("/files_ip", methods=["GET", "POST"]) def files_ip(): - noo, grouping, how_many, offset, size = ViewingOptions( request ) + noo, grouping, how_many, offset, size, folders, cwd = ViewingOptions( request ) entries=[] # per import path, add entries to view @@ -165,16 +175,18 @@ def files_ip(): else: entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.like(prefix+'%')).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() - return render_template("files.html", page_title='View Files (Import Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size ) + return render_template("files.html", page_title='View Files (Import Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd ) ################################################################################ # /files -> show thumbnail view of files from storage_path ################################################################################ @app.route("/files_sp", methods=["GET", "POST"]) def files_sp(): - noo, grouping, how_many, offset, size = ViewingOptions( request ) + noo, grouping, how_many, offset, size, folders, cwd = ViewingOptions( request ) entries=[] + print( f"cwd={cwd}" ) + # per storage path, add entries to view settings=Settings.query.first() paths = settings.storage_path.split("#") @@ -183,10 +195,11 @@ def files_sp(): if noo == "Oldest": entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.like(prefix+'%')).order_by(File.year,File.month,File.day,Entry.name).offset(offset).limit(how_many).all() + entries+=Entry.query.join(Dir).join(EntryDirLink).filter(Dir.path_prefix.like(prefix+'%')).order_by(Entry.name).offset(offset).limit(how_many).all() else: entries+=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.like(prefix+'%')).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() - return render_template("files.html", page_title='View Files (Storage Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size ) + return render_template("files.html", page_title='View Files (Storage Path)', entry_data=entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd ) ################################################################################ # /search -> show thumbnail view of files from import_path(s) @@ -194,7 +207,15 @@ def files_sp(): @app.route("/search", methods=["GET","POST"]) def search(): - noo, grouping, how_many, offset, size = ViewingOptions( request ) + noo, grouping, how_many, offset, size, folders, cwd = ViewingOptions( request ) + + # seems html cant do boolean, but uses strings so convert + if folders == "False": + folders=False + if folders == "True": + folders=True + + print( f"folders={folders}, type={type(folders)}" ) file_data=Entry.query.join(File).filter(Entry.name.ilike(f"%{request.form['term']}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() dir_data=Entry.query.join(File).join(EntryDirLink).join(Dir).filter(Dir.path_prefix.ilike(f"%{request.form['term']}%")).order_by(File.year.desc(),File.month.desc(),File.day.desc(),Entry.name).offset(offset).limit(how_many).all() @@ -202,7 +223,7 @@ def search(): all_entries = file_data + dir_data + ai_data - return render_template("files.html", page_title='View Files', search_term=request.form['term'], entry_data=all_entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size ) + return render_template("files.html", page_title='View Files', search_term=request.form['term'], entry_data=all_entries, noo=noo, grouping=grouping, how_many=how_many, offset=offset, size=size, folders=folders, cwd=cwd ) ################################################################################ # /files/scannow -> allows us to force a check for new files @@ -298,3 +319,22 @@ def move_files(): @app.route("/static/") def custom_static(filename): return send_from_directory("static/", filename) + +############################################################################### +# This func creates a new filter in jinja2 to test to see if the Dir being +# checked, is a top-level folder of 'cwd' +################################################################################ +@app.template_filter('TopLevelFolderOf') +def _jinja2_filter_toplevelfolderof(path, cwd): + if os.path.dirname(path) == cwd: + return True + else: + return False + +############################################################################### +# This func creates a new filter in jinja2 to test to hand back the parent path +# from a given path +################################################################################ +@app.template_filter('ParentPath') +def _jinja2_filter_parentpath(path): + return os.path.dirname(path) diff --git a/templates/base.html b/templates/base.html index 03665b4..4f45a90 100644 --- a/templates/base.html +++ b/templates/base.html @@ -107,6 +107,8 @@ + + @@ -167,6 +169,16 @@ $('#search_size').val( $('#size').val() ) else $('#search_size').val(128) + + if( $('#folders').length ) + $('#search_folders').val( $('#folders').val() ) + else + $('#search_folders').val('False') + + if( $('#cwd').length ) + $('#search_cwd').val( $('#cwd').val() ) + else + $('#search_cwd').val('') } {%block script_content %}{% endblock script_content %} diff --git a/templates/files.html b/templates/files.html index 272fb83..caa1b49 100644 --- a/templates/files.html +++ b/templates/files.html @@ -9,11 +9,18 @@
-
+ + + {% if search_term is defined %} {% endif %}
+ {% if folders %} +
+ In: {{cwd}} +
+ {% endif %}
{{CreateSelect( "noo", noo, ["Oldest", "Newest"], "$('#offset').val(0)")|safe }} {{CreateSelect( "how_many", how_many, ["10", "25", "50", "75", "100", "150", "200", "500"])|safe }} @@ -89,6 +96,17 @@
{% endif %} {% for obj in entry_data %} + {% if loop.index==1 and folders %} + {% if cwd != 'static/storage' %} +
+ + + + +
Back
+
+ {% endif %} + {% endif %} {% if grouping == "Day" %} {% if last.printed != obj.file_details[0].day %} {% if last.printed > 0 %} @@ -118,6 +136,7 @@ {% endif %} {% endif %} {% if obj.type.name != "Directory" %} + {% if (not folders) or ((obj.in_dir[0].path_prefix+'/'+obj.name) | TopLevelFolderOf(cwd)) %}
{% if obj.type.name=="Image" %} @@ -131,6 +150,16 @@ {% endif %} {# finding text distracting,
{{obj.name}}
#}
+ {% endif %} + {% else %} + {% if folders %} + {% if (cwd != obj.dir_details[0].path_prefix) and (obj.dir_details[0].path_prefix | TopLevelFolderOf(cwd)) %} +
+ +
{{obj.name}}
+
+ {% endif %} + {% endif %} {% endif %} {% endfor %} {% if grouping == "None" %} @@ -206,6 +235,10 @@ function ChangeSize(clicked_button,sz) $(clicked_button).addClass('btn-info').removeClass('btn-outline-info') $('.thumb').attr( {height: sz, style: 'font-size:'+sz } ) $('#size').val(sz) + sz=sz-22 + $('.fa-folder').attr( {style: 'font-size:'+sz } ) + sz=sz/2 + $('.fa-stack').attr( {style: 'color:grey;font-size:'+sz} ) } // e == event (can see if shift/ctrl held down while left-clicking @@ -307,6 +340,7 @@ $(document).ready(function() { $('#prev').addClass('disabled') $('#prev').prop('disabled', true) } + $(".dir").click( function(e) { $('#cwd').val( $(this).attr('dir') ) ; $('#main_form').submit() } ) } ) {% endblock script_content %}