added first pass of viewing by folders, see TODO for next steps
This commit is contained in:
5
TODO
5
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
|
||||
|
||||
54
files.py
54
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/<filename>")
|
||||
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)
|
||||
|
||||
@@ -107,6 +107,8 @@
|
||||
<input type="hidden" id="search_how_many" name="how_many" value="">
|
||||
<input type="hidden" id="search_offset" name="offset" value="">
|
||||
<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 id="term" class="form-control mr-sm-2" type="search" placeholder="by file, date (YYYMMDD) or tag" aria-label="Search" name="term">
|
||||
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
|
||||
</form>
|
||||
@@ -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('')
|
||||
}
|
||||
</script>
|
||||
{%block script_content %}{% endblock script_content %}
|
||||
|
||||
@@ -9,11 +9,18 @@
|
||||
</div>
|
||||
|
||||
<div class="container-fluid">
|
||||
<form method="POST"">
|
||||
<form id="main_form" method="POST"">
|
||||
<input type="hidden" name="folders" id="folders" value="{{folders}}">
|
||||
<input type="hidden" name="cwd" id="cwd" value="{{cwd}}">
|
||||
{% if search_term is defined %}
|
||||
<input type="hidden" name="term" id="view_term" value="{{search_term}}">
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
{% if folders %}
|
||||
<div class="my-auto">
|
||||
<span class="alert alert-primary">In: {{cwd}}</span>
|
||||
</div class="col my-auto">
|
||||
{% endif %}
|
||||
<div class="input-group col-lg-4">
|
||||
{{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 @@
|
||||
<div class="row pl-3">
|
||||
{% endif %}
|
||||
{% for obj in entry_data %}
|
||||
{% if loop.index==1 and folders %}
|
||||
{% if cwd != 'static/storage' %}
|
||||
<figure class="px-1 dir" dir={{cwd|ParentPath}}>
|
||||
<span style="font-size:{{(size|int-22)/2}}" class="fa-stack">
|
||||
<i style="color:grey" class="fas fa-folder fa-stack-2x"></i>
|
||||
<i class="fas fa-level-up-alt fa-flip-horizontal fa-stack-1x fa-inverse"></i>
|
||||
</span>
|
||||
<figcaption class="figure-caption text-center">Back</figcaption>
|
||||
</figure class="figure">
|
||||
{% 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)) %}
|
||||
<figure id="{{obj.id}}" img="{{loop.index-1}}" class="figure mx-1" fname="{{obj.name}}" yr="{{obj.file_details[0].year}}" date="{{obj.file_details[0].year}}{{"%02d" % obj.file_details[0].month}}{{"%02d" % obj.file_details[0].day}}" details="{{obj.name}} (Date: {{obj.file_details[0].day}}/{{obj.file_details[0].month}}/{{obj.file_details[0].year}})">
|
||||
{% if obj.type.name=="Image" %}
|
||||
<a href="{{obj.in_dir[0].path_prefix}}/{{obj.name}}"><img class="thumb" height="{{size}}" src="data:image/jpeg;base64,{{obj.file_details[0].thumbnail}}"></img></a>
|
||||
@@ -131,6 +150,16 @@
|
||||
{% endif %}
|
||||
{# finding text distracting, <figcaption style="font-size:12px;" class="figure-caption text-center">{{obj.name}}</figcaption> #}
|
||||
</figure>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if folders %}
|
||||
{% if (cwd != obj.dir_details[0].path_prefix) and (obj.dir_details[0].path_prefix | TopLevelFolderOf(cwd)) %}
|
||||
<figure class="px-1 dir" dir={{obj.dir_details[0].path_prefix}}>
|
||||
<i style="font-size:{{size|int-22}};" class="fas fa-folder"></i>
|
||||
<figcaption class="figure-caption text-center">{{obj.name}}</figcaption>
|
||||
</figure class="figure">
|
||||
{% 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() } )
|
||||
} )
|
||||
</script>
|
||||
{% endblock script_content %}
|
||||
|
||||
Reference in New Issue
Block a user