complete rewrite of viewer, videos need to be fixed. Otherwise, viewer now loads entry data for all "how_many" images on the screen, and allows prev/next movement between images without a DB load for the current page of images, then as required, it will retrieve the prev/next "how_many" from the database via /viewlist route, and go back into view/<id> of the appropriate new image of the new list. Also prevents going below 0 and beyond end of DB for the first time.

This commit is contained in:
2021-08-27 23:38:31 +10:00
parent 652a89161d
commit 1d3caf17de
6 changed files with 419 additions and 357 deletions

View File

@@ -107,7 +107,7 @@
<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" type="search" placeholder="by file, date (YYYMMDD) or tag" aria-label="Search" name="term">
<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>
</form>
</div class="navbar-nav">

View File

@@ -2,26 +2,26 @@
<div class="container-fluid">
<h3 class="offset-2">{{page_title}}</h3>
<form id="main_form" method="POST">
<input id="offset" type="hidden" name="offset" value="{{offset}}">
<input id="offset" type="hidden" name="offset" value="{{OPT['offset']}}">
<input id="grouping" type="hidden" name="grouping" value="">
<input id="size" type="hidden" name="size" value="">
<input id="cwd" type="hidden" name="cwd" value="">
<input id="folders" type="hidden" name="folders" value="False">
<div class="col col-auto">
<div class="input-group">
{{CreateSelect( "noo", noo, ["Oldest", "Newest","A to Z", "Z to A"], "$('#offset').val(0)", "rounded-start py-1 my-1")|safe }}
{{CreateSelect( "how_many", how_many, ["10", "25", "50", "75", "100", "150", "200", "500"], "", "rounded-end py-1 my-1" )|safe }}
{{CreateSelect( "noo", OPT['noo'], ["Oldest", "Newest","A to Z", "Z to A"], "$('#offset').val(0)", "rounded-start py-1 my-1")|safe }}
{{CreateSelect( "how_many", OPT['how_many'], ["10", "25", "50", "75", "100", "150", "200", "500"], "", "rounded-end py-1 my-1" )|safe }}
<div class="mb-1 col my-auto d-flex justify-content-center">
{% set prv_disabled="" %}
{% if offset|int == 0 %}
{% if OPT['offset']|int == 0 %}
{% set prv_disabled="disabled" %}
{% endif %}
<button id="prev" {{prv_disabled}} name="prev" class="prev sm-txt btn btn-outline-secondary">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#prev"/></svg>
</button>
<span class="sm-txt my-auto">&nbsp;{{how_many}} files&nbsp;</span>
<span class="sm-txt my-auto">&nbsp;{{OPT['how_many']}} files&nbsp;</span>
{% set nxt_disabled="" %}
{% if entry_data|length < how_many|int %}
{% if entry_data|length < OPT['how_many']|int %}
{% set nxt_disabled="disabled" %}
{% endif %}
<button id="next" {{nxt_disabled}} name="next" class="next sm-txt btn btn-outline-secondary">

View File

@@ -6,38 +6,38 @@
<div class="container-fluid">
<form id="main_form" method="POST">
<input type="hidden" name="cwd" id="cwd" value="{{cwd}}">
<input type="hidden" name="cwd" id="cwd" value="{{OPT['cwd']}}">
{% if search_term is defined %}
<input type="hidden" name="term" id="view_term" value="{{search_term}}">
<input type="hidden" name="search_term" id="view_term" value="{{search_term}}">
{% endif %}
<div class="d-flex row mb-2">
{% if folders %}
{% if OPT['folders'] %}
<div class="my-auto col col-auto">
<span class="alert alert-primary py-2">
{% if "files_ip" in request.url %}
<svg width="20" height="20" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#import"/></svg>
{% set tmp_path=cwd | replace( "static/Import", "" ) + "/" %}
{% set tmp_path=OPT['cwd'] | replace( "static/Import", "" ) + "/" %}
{% elif "files_sp" in request.url %}
<svg width="20" height="20" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#db"/></svg>
{% set tmp_path=cwd | replace( "static/Storage", "" ) + "/" %}
{% set tmp_path=OPT['cwd'] | replace( "static/Storage", "" ) + "/" %}
{% elif "files_rbp" in request.url %}
<svg width="20" height="20" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#trash"/></svg>
{% set tmp_path=cwd | replace( "static/Bin", "" ) + "/" %}
{% set tmp_path=OPT['cwd'] | replace( "static/Bin", "" ) + "/" %}
{% endif %}
{{tmp_path}}</span>
</div class="col my-auto">
{% endif %}
<div class="col col-auto">
<div class="input-group">
{{CreateSelect( "noo", noo, ["Oldest", "Newest","A to Z", "Z to A"], "$('#offset').val(0)", "rounded-start py-2")|safe }}
{{CreateSelect( "how_many", how_many, ["10", "25", "50", "75", "100", "150", "200", "500"])|safe }}
{% if folders %}
<input type="hidden" name="grouping" id="grouping" value="{{grouping}}">
{{CreateFoldersSelect( folders, "rounded-end" )|safe }}
{{CreateSelect( "noo", OPT['noo'], ["Oldest", "Newest","A to Z", "Z to A"], "$('#offset').val(0)", "rounded-start py-2")|safe }}
{{CreateSelect( "how_many", OPT['how_many'], ["10", "25", "50", "75", "100", "150", "200", "500"])|safe }}
{% if OPT['folders'] %}
<input type="hidden" name="grouping" id="grouping" value="{{OPT['grouping']}}">
{{CreateFoldersSelect( OPT['folders'], "rounded-end" )|safe }}
{% else %}
{{CreateFoldersSelect( folders )|safe }}
{{CreateFoldersSelect( OPT['folders'] )|safe }}
<span class="sm-txt my-auto btn btn-outline-info disabled border-top border-bottom">grouped by:</span>
{{CreateSelect( "grouping", grouping, ["None", "Day", "Week", "Month"], "", "rounded-end")|safe }}
{{CreateSelect( "grouping", OPT['grouping'], ["None", "Day", "Week", "Month"], "", "rounded-end")|safe }}
{% endif %}
</div class="input-group">
</div class="col">
@@ -50,9 +50,9 @@
<button id="prev" name="prev" class="prev sm-txt btn btn-outline-secondary">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#prev"/></svg>
</button>
<span class="sm-txt my-auto">&nbsp;{{how_many}} files&nbsp;</span>
<span class="sm-txt my-auto">&nbsp;{{OPT['how_many']}} files&nbsp;</span>
{% set nxt_disabled="" %}
{% if entry_data|length < how_many|int %}
{% if entry_data|length < OPT['how_many']|int %}
{% set nxt_disabled="disabled" %}
{% endif %}
<button id="next" {{nxt_disabled}} name="next" class="next sm-txt btn btn-outline-secondary">
@@ -72,31 +72,31 @@
</div>
<div class="d-flex col col-auto justify-content-end">
<div class="btn-group">
{% if size == "64" %}
{% if OPT['size'] == "64" %}
{% set bt="btn-info text-white" %}
{% else %}
{% set bt="btn-outline-info" %}
{% endif %}
<button id="64" class="px-2 sm-txt sz-but btn {{bt}}" onClick="ChangeSize(this,64); return false;">XS</button>
{% if size == "96" %}
{% if OPT['size'] == "96" %}
{% set bt="btn-info text-white" %}
{% else %}
{% set bt="btn-outline-info" %}
{% endif %}
<button id="96" class="px-2 sm-txt sz-but btn {{bt}}" onClick="ChangeSize(this,96); return false;">S</button>
{% if size == "128" %}
{% if OPT['size'] == "128" %}
{% set bt="btn-info text-white" %}
{% else %}
{% set bt="btn-outline-info" %}
{% endif %}
<button id="128" class="px-2 sm-txt sz-but btn {{bt}}" onClick="ChangeSize(this,128); return false;">M</button>
{% if size == "192" %}
{% if OPT['size'] == "192" %}
{% set bt="btn-info text-white" %}
{% else %}
{% set bt="btn-outline-info" %}
{% endif %}
<button id="192" class="px-2 sm-txt sz-but btn {{bt}}" onClick="ChangeSize(this,192); return false;">L</button>
{% if size == "256" %}
{% if OPT['size'] == "256" %}
{% set bt="btn-info text-white" %}
{% else %}
{% set bt="btn-outline-info" %}
@@ -104,8 +104,8 @@
<button id="256" class="px-2 sm-txt sz-but btn {{bt}}" onClick="ChangeSize(this,256); return false;">XL</button>
</div class="btn-group">
</div class="col">
<input id="offset" type="hidden" name="offset" value="{{offset}}">
<input id="size" type="hidden" name="size" value="{{size}}">
<input id="offset" type="hidden" name="offset" value="{{OPT['offset']}}">
<input id="size" type="hidden" name="size" value="{{OPT['size']}}">
</div class="form-row">
{% set eids=namespace( str="" ) %}
{# gather all the file eids and collect them in case we go gallery mode #}
@@ -120,59 +120,59 @@
<div class="row ms-2">
{% set last = namespace(printed=0) %}
{# rare event of empty folder, still need to show back button #}
{% if folders and entry_data|length == 0 %}
{% if cwd != root %}
<figure id="_back" class="dir entry m-1" ecnt="1" dir="{{cwd|ParentPath}}" type="Directory">
<svg class="svg" width="{{size|int-22}}" height="{{size|int-22}}"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back"/></svg>
{% if OPT['folders'] and entry_data|length == 0 %}
{% if OPT['cwd'] != OPT['root'] %}
<figure id="_back" class="dir entry m-1" ecnt="1" dir="{{OPT['cwd']|ParentPath}}" type="Directory">
<svg class="svg" width="{{OPT['size']|int-22}}" height="{{OPT['size']|int-22}}"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back"/></svg>
<figcaption class="figure-caption text-center">Back</figcaption>
</figure class="figure">
<script>f=$('#_back'); w=f.find('svg').width(); f.find('figcaption').width(w);</script>
{% else %}
<div class="col col-auto g-0 m-1">
<svg class="svg" width="{{size|int-22}}" height="{{size|int-22}}"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back_gray"/></svg>
<svg class="svg" width="{{OPT['size']|int-22}}" height="{{OPT['size']|int-22}}"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back_gray"/></svg>
</div>
{% endif %}
{% endif %}
{% for obj in entry_data %}
{% if loop.index==1 and folders %}
{% if cwd != root %}
<figure class="col col-auto g-0 dir entry m-1" ecnt="{{loop.index}}" dir="{{cwd|ParentPath}}" type="Directory">
<svg class="svg" width="{{size|int-22}}" height="{{size|int-22}}" fill="currentColor">
{% if loop.index==1 and OPT['folders'] %}
{% if OPT['cwd'] != OPT['root'] %}
<figure class="col col-auto g-0 dir entry m-1" ecnt="{{loop.index}}" dir="{{OPT['cwd']|ParentPath}}" type="Directory">
<svg class="svg" width="{{OPT['size']|int-22}}" height="{{OPT['size']|int-22}}" fill="currentColor">
<use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back"/></svg>
<figcaption class="svg_cap figure-caption text-center">Back</figcaption>
</figure class="figure">
{% else %}
{# create an even lighter-grey, unclickable back button - so folders dont jump around when you go into them #}
<div class="col col-auto g-0 m-1">
<svg class="svg" width="{{size|int-22}}" height="{{size|int-22}}"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back_gray"/></svg>
<svg class="svg" width="{{OPT['size']|int-22}}" height="{{OPT['size']|int-22}}"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#folder_back_gray"/></svg>
</div>
{% endif %}
{% endif %}
{% if not folders and obj.type.name == "Directory" %}
{% if not OPT['folders'] and obj.type.name == "Directory" %}
{% continue %}
{% endif %}
{% if grouping == "Day" %}
{% if OPT['grouping'] == "Day" %}
{% if last.printed != obj.file_details.day %}
<div class="row ps-3"><h6>Day: {{obj.file_details.day}} of {{obj.file_details.month}}/{{obj.file_details.year}}</h6></div>
{% set last.printed = obj.file_details.day %}
{% endif %}
{% elif grouping == "Week" %}
{% elif OPT['grouping'] == "Week" %}
{% if last.printed != obj.file_details.woy %}
<div class="row ps-3"><h6>Week #: {{obj.file_details.woy}} of {{obj.file_details.year}}</h6></div>
{% set last.printed = obj.file_details.woy %}
{% endif %}
{% elif grouping == "Month" %}
{% elif OPT['grouping'] == "Month" %}
{% if last.printed != obj.file_details.month %}
<div class="row ps-3"><h6>Month: {{obj.file_details.month}} of {{obj.file_details.year}}</h6></div>
{% set last.printed = obj.file_details.month %}
{% endif %}
{% endif %}
{% if obj.type.name != "Directory" %}
{% if (not folders) or ((obj.in_dir.in_path.path_prefix+'/'+obj.in_dir.rel_path+'/'+obj.name) | TopLevelFolderOf(cwd)) %}
{% if (not OPT['folders']) or ((obj.in_dir.in_path.path_prefix+'/'+obj.in_dir.rel_path+'/'+obj.name) | TopLevelFolderOf(OPT['cwd'])) %}
<figure id="{{obj.id}}" ecnt="{{loop.index}}" class="col col-auto g-0 figure entry m-1" path_type="{{obj.in_dir.in_path.type.name}}" size="{{obj.file_details.size_mb}}" hash="{{obj.file_details.hash}}" in_dir="{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}" fname="{{obj.name}}" yr="{{obj.file_details.year}}" date="{{obj.file_details.year}}{{"%02d" % obj.file_details.month}}{{"%02d" % obj.file_details.day}}" pretty_date="{{obj.file_details.day}}/{{obj.file_details.month}}/{{obj.file_details.year}}" type="{{obj.type.name}}">
{% if obj.type.name=="Image" %}
<div style="position:relative; width:100%">
<a href="{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}/{{obj.name}}"><img class="thumb" height="{{size}}" src="data:image/jpeg;base64,{{obj.file_details.thumbnail}}"></img></a>
<a href="{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}/{{obj.name}}"><img class="thumb" height="{{OPT['size']}}" src="data:image/jpeg;base64,{{obj.file_details.thumbnail}}"></img></a>
{% if search_term is defined %}
<div style="position:absolute; bottom: 0px; left: 2px;">
<svg width="16" height="16" fill="white"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#{{LocationIcon(obj)}}"/></svg>
@@ -184,7 +184,7 @@
</div>
{% elif obj.type.name == "Video" %}
<div style="position:relative; width:100%">
<a href="{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}/{{obj.name}}"><img class="thumb" style="display:block" height="{{size}}" src="data:image/jpeg;base64,{{obj.file_details.thumbnail}}"></img></a>
<a href="{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}/{{obj.name}}"><img class="thumb" style="display:block" height="{{OPT['size']}}" src="data:image/jpeg;base64,{{obj.file_details.thumbnail}}"></img></a>
<div style="position:absolute; top: 0px; left: 2px;">
<svg width="16" height="16" fill="white"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#film"/></svg>
</div>
@@ -198,16 +198,16 @@
</figure>
{% endif %}
{% else %}
{% if folders %}
{% if OPT['folders'] %}
{% if obj.dir_details.rel_path | length %}
{% set dirname=obj.dir_details.in_path.path_prefix+'/'+obj.dir_details.rel_path %}
{% else %}
{% set dirname=obj.dir_details.in_path.path_prefix %}
{% endif %}
{# if this dir is the toplevel of the cwd, show the folder icon #}
{% if dirname| TopLevelFolderOf(cwd) %}
{% if dirname| TopLevelFolderOf(OPT['cwd']) %}
<figure class="col col-auto g-0 figure dir entry m-1" id={{obj.id}} ecnt={{loop.index}} dir="{{dirname}}" type="Directory">
<svg class="svg" width="{{size|int-22}}" height="{{size|int-22}}" fill="currentColor">
<svg class="svg" width="{{OPT['size']|int-22}}" height="{{OPT['size']|int-22}}" fill="currentColor">
<use xlink:href="{{url_for('internal', filename='icons.svg')}}#Directory"/></svg>
<figcaption class="svg_cap figure-caption text-center text-wrap text-break">{{obj.name}}</figcaption>
</figure class="figure">
@@ -220,13 +220,13 @@
</div>
<div class="container-fluid">
<form id="nav_form" method="POST"">
<input type="hidden" name="cwd" id="cwd" value="{{cwd}}">
<input type="hidden" name="cwd" id="cwd" value="{{OPT['cwd']}}">
<div class="row">
<div class="col my-auto d-flex justify-content-center">
<button onClick="$.each( $('#main_form').serializeArray() , function( index, value ) { $('#nav_form').append( '<input type=hidden name=' + value['name'] +' value='+value['value'] + '>' ); })" id="prev" name="prev" class="prev sm-txt btn btn-outline-secondary">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#prev"/></svg>
</button>
<span class="sm-txt my-auto">&nbsp;{{how_many}} files&nbsp;</span>
<span class="sm-txt my-auto">&nbsp;{{OPT['how_many']}} files&nbsp;</span>
<button onClick="$.each( $('#main_form').serializeArray() , function( index, value ) { $('#nav_form').append( '<input type=hidden name=' + value['name'] +' value='+value['value'] + '>' ); });" id="next" {{nxt_disabled}} name="next" class="next sm-txt btn btn-outline-secondary">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#next"/></svg>
</button>
@@ -242,13 +242,32 @@
$('.figure').click( function(e) { DoSel(e, this ); SetButtonState(); return false; });
$(document).on('click', function(e) { $('.highlight').removeClass('highlight') ; SetButtonState() });
$('.figure').dblclick(
function() {
s='<form id="_fm" method="POST" action="/view/' + $(this).attr("id");
s+='"><input type="hidden" name="eids" value="'+$("#eids").val() + '"></form>'
$(s).appendTo('body').submit(); }
);
function CallViewRouteWrapper()
{
CallViewRoute( $(this).attr("id") )
}
function CallViewRoute(id)
{
s='<form id="_fm" method="POST" action="/view/' + id + '">'
s+='<input type="hidden" name="eids" value="'+$("#eids").val() + '">'
s+='<input type="hidden" name="noo" value="{{OPT['noo']}}">'
s+='<input type="hidden" name="cwd" value="{{OPT['cwd']}}">'
s+='<input type="hidden" name="root" value="{{OPT['root']}}">'
s+='<input type="hidden" name="size" value="{{OPT['size']}}">'
s+='<input type="hidden" name="grouping" value="{{OPT['grouping']}}">'
s+='<input type="hidden" name="offset" value="{{OPT['offset']}}">'
s+='<input type="hidden" name="folders" value="{{OPT['folders']}}">'
s+='<input type="hidden" name="how_many" value="{{OPT['how_many']}}">'
s+='<input type="hidden" name="orig_url" value="{{request.path}}">'
{% if search_term is defined %}
s+='<input type="hidden" name="search_term" value="{{search_term}}">'
{% endif %}
s+='</form>'
$(s).appendTo('body').submit();
}
$('.figure').dblclick( CallViewRouteWrapper )
// different context menu on files
$.contextMenu({
@@ -307,11 +326,7 @@ $.contextMenu({
return {
callback: function( key, options) {
if( key == "details" ) { DetailsDBox() }
if( key == "view" ) {
s='<form id="_fm" method="POST" action="/view/' + $(this).attr("id");
s+='"><input type="hidden" name="eids" value="'+$("#eids").val() + '"></form>'
$(s).appendTo('body').submit();
}
if( key == "view" ) { CallViewRoute( $(this).attr('id') ) }
if( key == "move" ) { MoveDBox() }
if( key == "del" ) { DelDBox('Delete') }
if( key == "undel") { DelDBox('Restore') }
@@ -329,7 +344,7 @@ $.contextMenu({
$(document).ready(function() {
if( {{offset}} == 0 )
if( {{OPT['offset']}} == 0 )
{
$('.prev').addClass('disabled')
$('.prev').prop('disabled', true)

View File

@@ -21,6 +21,33 @@
var grayscale=0
var throbber=0
var objs=[]
var current={{current}}
var eids="{{eids}}"
var eid_lst=eids.split(",")
{% for id in objs %}
e=new Object()
e.name = "{{objs[id].name}}"
e.url = "{{objs[id].FullPathOnFS()}}"
{% if objs[id].file_details.faces %}
e.face_model="{{objs[id].file_details.faces[0].facefile_lnk.model_used}}"
{% endif %}
e.faces=[]
{% for face in objs[id].file_details.faces %}
data = {
'x': '{{face.locn[3]}}', 'y': '{{face.locn[0]}}',
'w': '{{face.locn[1]-face.locn[3]}}', 'h':'{{face.locn[2]-face.locn[0]}}'
}
{% if face.refimg %}
data['who']='{{face.refimg.person.tag}}'
data['distance']="{{face.refimg_lnk.face_distance|round(2)}}"
{% endif %}
e.faces.push( data )
{% endfor %}
objs[{{id}}]=e
{% endfor %}
function NewWidth()
{
w_r=im.width/(window.innerWidth*gap)
@@ -61,20 +88,48 @@
else
$('#throbber').hide();
// show (or not) the whole figcaption with fname in it - based on state of fname_toggle
if( $('#fname_toggle').prop('checked' ) )
{
$('.figcaption').attr('style', 'display:show' )
// reset fname for new image (if navigated left/right to get here)
$('#fname').html(objs[current].name)
}
else
$('.figcaption').attr('style', 'display:none' )
// if we have faces, the enable the toggles, otherwise disable them
// and reset model select too
if( objs[current].faces.length )
{
$('#faces').attr('disabled', false)
$('#distance').attr('disabled', false)
$('#model').val( Number(objs[current].face_model) )
}
else
{
$('#faces').attr('disabled', true)
$('#distance').attr('disabled', true)
// if no faces, then model is N/A (always 1st element - or 0 in select)
$('#model').val(0)
}
// okay, we want faces drawn so lets do it
if( $('#faces').prop('checked') )
{
// draw rect on each face
for( i=0; i<faces.length; i++ )
for( i=0; i<objs[current].faces.length; i++ )
{
x = faces[i].x / ( im.width/canvas.width )
y = faces[i].y / ( im.height/canvas.height )
w = faces[i].w / ( im.width/canvas.width )
h = faces[i].h / ( im.height/canvas.height )
x = objs[current].faces[i].x / ( im.width/canvas.width )
y = objs[current].faces[i].y / ( im.height/canvas.height )
w = objs[current].faces[i].w / ( im.width/canvas.width )
h = objs[current].faces[i].h / ( im.height/canvas.height )
context.beginPath()
context.rect( x, y, w, h )
context.lineWidth = 2
context.strokeStyle = 'green'
if( faces[i].who )
if( objs[current].faces[i].who )
{
// finish face box, need to clear out new settings for
// transparent backed-name tag
@@ -83,9 +138,9 @@
context.lineWidth = 0.1
context.font = "30px Arial"
context.globalAlpha = 0.6
str=faces[i].who
str=objs[current].faces[i].who
if( $('#distance').prop('checked') )
str += "("+faces[i].distance+")"
str += "("+objs[current].faces[i].distance+")"
bbox = context.measureText(str);
f_h=bbox.fontBoundingBoxAscent
@@ -109,8 +164,8 @@
context.font = "14px Arial"
context.textAlign = "center"
context.fillStyle = "black"
context.fillText( 'x=' + faces[i].x + ', y=' + faces[i].y, x+w/2, y-2)
context.fillText( 'x=' + faces[i].x + ', y=' + faces[i].y, x+w/2, y-2)
context.fillText( 'x=' + objs[current].faces[i].x + ', y=' + objs[current].faces[i].y, x+w/2, y-2)
context.fillText( 'x=' + objs[current].faces[i].x + ', y=' + objs[current].faces[i].y, x+w/2, y-2)
}
*/
context.stroke();
@@ -129,128 +184,133 @@
DrawImg()
}
function CallViewListRoute(dir)
{
s='<form id="_fmv" method="POST" action="/viewlist">'
s+='<input type="hidden" name="eids" value="'+$("#eids").val() + '">'
s+='<input type="hidden" name="noo" value="{{OPT['noo']}}">'
s+='<input type="hidden" name="cwd" value="{{OPT['cwd']}}">'
s+='<input type="hidden" name="root" value="{{OPT['root']}}">'
s+='<input type="hidden" name="size" value="{{OPT['size']}}">'
s+='<input type="hidden" name="grouping" value="{{OPT['grouping']}}">'
s+='<input type="hidden" name="offset" value="{{OPT['offset']}}">'
s+='<input type="hidden" name="folders" value="{{OPT['folders']}}">'
s+='<input type="hidden" name="how_many" value="{{OPT['how_many']}}">'
s+='<input type="hidden" name="orig_url" value="{{request.path}}">'
s+='<input type="hidden" name="' + dir + '" value="1">'
{% if search_term is defined %}
s+='<input type="hidden" name="search_term" value="{{search_term}}">'
{% endif %}
s+='</form>'
$(s).appendTo('body')
$('#_fmv').submit();
}
</script>
<div id="viewer" class="container-fluid">
{% set max=eids.split(',')|length %}
<input type="hidden" name="eids" value={{eids}}>
<div class="row">
{% if eids.find(obj.id|string) > 0 %}
<form id="prev" class="col col-auto" action="/viewprev" method="POST">
<input id="current" type="hidden" name="current" value="{{obj.id}}">
<input type="hidden" name="eids" value="{{eids}}">
<input id="prev_fname" type="hidden" name="fname" value="">
<input id="prev_faces" type="hidden" name="faces" value="">
<input id="prev_distance" type="hidden" name="distance" value="">
<button title="Show previous image" class="btn btn-outline-info h-75" id="la"
<button title="Show previous image" class="col-auto btn btn-outline-info px-2" style="padding: 10%" id="la"
onClick="
$('#prev_fname').val($('#fname').prop('checked'))
$('#prev_faces').val($('#faces').prop('checked'))
$('#prev_distance').val($('#distance').prop('checked'))
cidx = eid_lst.indexOf(current.toString())
prev=cidx-1
if( prev < 0 )
{
if( {{OPT['offset']}} )
{
CallViewListRoute('prev')
return
}
else
{
$('#la').attr('disabled', true )
prev=0
}
}
$('#ra').attr('disabled', false )
current=eid_lst[prev]
im.src='http://mara.ddp.net:5000/' + objs[current].url
">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#prev"/></svg>
</button>
</form id="prev">
{% endif %}
{% if obj.type.name == "Image" %}
<figure class="col col-auto border border-info rounded m-0 p-1" id="figure">
<canvas id="canvas"></canvas>
<img id="throbber" src="{{url_for('internal', filename='throbber.gif')}}" style="display:none;">
{% if objs[current].type.name == "Image" %}
<figure class="col col-auto border border-info rounded m-0 p-1" id="figure">
<canvas id="canvas"></canvas>
<img id="throbber" src="{{url_for('internal', filename='throbber.gif')}}" style="display:none;">
<script>
var im=new Image();
im.onload=DrawImg
im.src="http://mara.ddp.net:5000/" + objs[current].url
var context = canvas.getContext('2d')
window.addEventListener('resize', DrawImg, false);
</script>
<figcaption class="figure-caption text-center text-wrap text-break"><span id="fname">{{objs[current].name}}</span></figcaption>
</figure>
{% elif objs[current].type.name == "Video" %}
<video id="_v" controls>
<source src="http://mara.ddp.net:5000/{{objs[current].FullPathOnFS()}}" type="video/mp4">
Your browser does not support the video tag.
</video>
<script>
var im=new Image();
im.onload=DrawImg
im.src="/{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}/{{obj.name}}"
var faces=[]
{% for face in obj.file_details.faces %}
data = {
'x': '{{face.locn[3]}}', 'y': '{{face.locn[0]}}',
'w': '{{face.locn[1]-face.locn[3]}}', 'h':'{{face.locn[2]-face.locn[0]}}'
}
{% if face.refimg %}
data['who']='{{face.refimg.person.tag}}'
data['distance']="{{face.refimg_lnk.face_distance|round(2)}}"
data['model']="{{face.facefile_lnk.model_used}}"
{% endif %}
faces.push( data )
{% endfor %}
var context = canvas.getContext('2d')
window.addEventListener('resize', DrawImg, false);
window.addEventListener('resize', ResizeVideo, false);
ResizeVideo()
</script>
<figcaption class="figure-caption text-center text-wrap text-break"
{% if sels['fname']=='false' %}
style="display:none"
{% endif %}
>{{obj.name}}
</figcaption>
</figure>
{% elif obj.type.name == "Video" %}
<video id="_v" controls>
<source src="/{{obj.in_dir.in_path.path_prefix}}/{{obj.in_dir.rel_path}}/{{obj.name}}" type="video/mp4">
Your browser does not support the video tag.
</video>
<script>
window.addEventListener('resize', ResizeVideo, false);
ResizeVideo()
</script>
{% endif %}
{% for eid in eids.split(',') %}
{% if loop.index == max-1 %}
{% if eid|int != obj.id %}
<form id="next" class="col col-auto" action="/viewnext" method="POST">
<input type="hidden" name="current" value="{{obj.id}}">
<input type="hidden" name="eids" value="{{eids}}">
<input id="next_fname" type="hidden" name="fname" value="">
<input id="next_faces" type="hidden" name="faces" value="">
<input id="next_distance" type="hidden" name="distance" value="">
<button title="Show next image" class="col col-auto btn btn-outline-info h-75" id="ra"
onClick="
$('#next_fname').val($('#fname').prop('checked'))
$('#next_faces').val($('#faces').prop('checked'))
$('#next_distance').val($('#distance').prop('checked'))
">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#next"/></svg>
</button>
</form id="next">
{% endif %}
{% endif %}
{% endfor %}
<button title="Show next image" class="col-auto btn btn-outline-info px-2" style="padding: 10%" id="ra"
onClick="
{% if 'last_entry_in_db' in OPT %}
if( current == {{OPT['last_entry_in_db']}} )
{
$('#ra').attr('disabled', true )
return
}
{% endif %}
cidx = eid_lst.indexOf(current.toString())
if( cidx < eid_lst.length-1 )
{
current=eid_lst[cidx+1]
im.src='http://mara.ddp.net:5000/' + objs[current].url
$('#la').attr('disabled', false )
}
else
{
{# only go next route if list contains as many elements as we asked to display... can be more than how_many on any page in reality, as its really how_many per dir? #}
if( eid_lst.length >= {{OPT['how_many']}} )
CallViewListRoute('next')
}
">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#next"/></svg>
</button>
</div id="/form-row">
{# use this for color of toggles: https://www.codeply.com/p/4sL9uhevwJ #}
<div class="row">
{# this whole div, just takes up the same space as the left button and is hidden for alignment only #}
<div class="col col-auto">
<button class="btn btn-outline-info" disabled style="visibility:hidden">
<div class="col-auto px-0">
<button class="btn btn-outline-info px-2" disabled style="visibility:hidden">
<svg width="16" height="16" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#next"/></svg>
</button>
</div>
<span class="col col-auto my-auto">Show:</span>
<span class="col-auto my-auto">Show:</span>
<div title="Toggle showing filename" class="d-flex form-check form-switch border border-info rounded col col-auto my-auto py-1 justify-content-center ps-5">
<input class="form-check-input" type="checkbox" id="fname" onChange="$('.figure-caption').toggle()"
{% if sels['fname']=='true' %} checked {% endif %} >
<label class="form-check-label ps-1" for="fname">Filename</label>
<input class="form-check-input" type="checkbox" id="fname_toggle" onChange="$('.figure-caption').toggle()" checked>
<label class="form-check-label ps-1" for="fname_toggle">Filename</label>
</div>
<div title="Toggle showing matched faces" class="d-flex form-check form-switch border border-info rounded col col-auto my-auto py-1 justify-content-center ps-5">
<input class="form-check-input" type="checkbox" onChange="FaceToggle()" id="faces"
{% if not obj.file_details.faces %} disabled {% endif %}
{% if sels['faces']=='true' %} checked {% endif %}
>
<input class="form-check-input" type="checkbox" onChange="FaceToggle()" id="faces">
<label class="form-check-label ps-1" for="faces">Faces</label>
</div>
<div title="Toggle showing 'distance' on matched faces" class="d-flex form-check form-switch border border-info rounded col col-auto my-auto py-1 justify-content-center ps-5">
<input class="form-check-input" type="checkbox" onChange="DrawImg()" id="distance"
{% if not obj.file_details.faces or sels['faces']=='false' %} disabled {% endif %}
{% if sels['distance']=='true' %} checked {% endif %}
>
<input class="form-check-input" type="checkbox" onChange="DrawImg()" id="distance">
<label class="form-check-label ps-1" for="distance">Distance</label>
</div>
<div title="Change the model used to detect faces" class="col col-auto my-auto">
AI Model:
{% if not obj.file_details.faces %}
{{CreateSelect( "model", 0, ["N/A", "normal", "slow/accurate"], "", "rounded norm-txt", [0,1,2])|safe }}
{% else %}
{{CreateSelect( "model", obj.file_details.faces[0].facefile_lnk.model_used, ["normal", "slow/accurate"], "", "rounded norm-txt", [1,2])|safe }}
{% endif %}
{# can use 0 as default, it will be (re)set correctly in DrawImg() anyway #}
{{CreateSelect( "model", 0, ["N/A", "normal", "slow/accurate"], "", "rounded norm-txt", [0,1,2])|safe }}
</div>
<div class="col col-auto pt-1">
<button class="btn btn-outline-info p-1" title="Rotate by 90 degrees" onClick="Transform(90)">
@@ -268,7 +328,7 @@
<button class="btn btn-outline-info p-1" title="Flip vertically" onClick="Transform('flipv')">
<svg width="28" height="28" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#flip_v"/></svg>
</button>
<button class="btn btn-outline-info p-1" title="View in Fullscreen mode" onClick="document.getElementById('canvas').requestFullscreen()">
<button class="btn btn-outline-info p-1" title="View in Fullscreen mode" onClick="$('#prev_fullscreen').val('true'); $('#next_fullscreen').val('true'); document.getElementById('canvas').requestFullscreen()">
<svg width="28" height="28" fill="currentColor"><use xlink:href="{{url_for('internal', filename='icons.svg')}}#fullscreen"/></svg>
</button>
</div>
@@ -300,5 +360,8 @@ $( document ).keydown(function(event) {
return; // Quit when this doesn't handle the key event.
}
});
{% if OPT['fullscreen']=='true' %}
$( document ).ready ( function() { document.getElementById('canvas').requestFullscreen() } )
{% endif %}
</script>
{% endblock script_content %}