viewer now works for files_ip, still have broken bits everywhere - files_rbp, change_opts, do I want a back button? lots of dead/old code, probably cam move more js into *_support, and do I want to keep files_support separate to view_support

This commit is contained in:
2025-09-30 00:29:11 +10:00
parent 0851b79e16
commit a0e06717ac
4 changed files with 477 additions and 228 deletions

View File

@@ -523,15 +523,19 @@ function drawPageOfFigures()
ecnt++
}
$('.figure').click( function(e) { DoSel(e, this ); SetButtonState(); return false; });
$('.figure').dblclick( CallViewRouteWrapper )
$('.figure').dblclick( function(e) { dblClickToViewEntry( $(this).attr('id') ) } )
// for dir, getDirEntries 2nd param is back (or "up" a dir)
$(".dir").click( function(e) { document.back_id=this.id; getDirEntries(this.id,false) } )
$(".back").click( function(e) { getDirEntries(this.id,true) } )
}
// Function to get the 'page' of entry ids out of entryList
function getPage(pageNumber)
function getPage(pageNumber,viewing_idx=0)
{
// before we do anything, disabled left/right arrows on viewer to stop
// getting another event before we have the data for the page back
$('#la').prop('disabled', true)
$('#ra').prop('disabled', true)
const startIndex = (pageNumber - 1) * OPT.howMany;
const endIndex = startIndex + OPT.howMany;
pageList = entryList.slice(startIndex, endIndex);
@@ -549,7 +553,13 @@ function getPage(pageNumber)
dataType: 'json', // Expect JSON response
success: function(res) {
document.entries=res
// add all the figures to files_div
drawPageOfFigures()
// noting we could have been in files_div, or viewer_div, update both jic
// and fix viewer_div - update viewing, arrows and image/video too
document.viewing=document.entries[viewing_idx]
resetNextPrevButtons()
ViewImageOrVideo()
},
error: function(xhr, status, error) {
console.error("Error:", error);

View File

@@ -87,11 +87,11 @@ function DrawImg()
// if we have faces, the enable the toggles, otherwise disable them
// and reset model select too
if( objs[current].faces )
if( document.viewing.faces )
{
$('#faces').attr('disabled', false)
$('#distance').attr('disabled', false)
$('#model').val( Number(objs[current].face_model) )
$('#model').val( Number(document.viewing.face_model) )
}
else
{
@@ -102,33 +102,33 @@ function DrawImg()
}
// okay, we want faces drawn so lets do it
if( $('#faces').prop('checked') && objs[current].faces )
if( $('#faces').prop('checked') && document.viewing.faces )
{
// draw rect on each face
for( i=0; i<objs[current].faces.length; i++ )
for( i=0; i<document.viewing.faces.length; i++ )
{
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 )
x = document.viewing.faces[i].x / ( im.width/canvas.width )
y = document.viewing.faces[i].y / ( im.height/canvas.height )
w = document.viewing.faces[i].w / ( im.width/canvas.width )
h = document.viewing.faces[i].h / ( im.height/canvas.height )
context.beginPath()
context.rect( x, y, w, h )
context.lineWidth = 2
// this face has an override so diff colour
if( objs[current].faces[i].override )
if( document.viewing.faces[i].override )
{
context.strokeStyle = 'blue'
DrawLabelOnFace( objs[current].faces[i].override.who )
DrawLabelOnFace( document.viewing.faces[i].override.who )
}
else
{
context.strokeStyle = 'green'
if( objs[current].faces[i].who )
if( document.viewing.faces[i].who )
{
str=objs[current].faces[i].who
str=document.viewing.faces[i].who
if( $('#distance').prop('checked') )
str += "("+objs[current].faces[i].distance+")"
str += "("+document.viewing.faces[i].distance+")"
DrawLabelOnFace( str )
}
}
@@ -156,13 +156,13 @@ function FaceToggle()
// also deals with fullsecreen if needed
function ViewImageOrVideo()
{
if( objs[current].type == 'Image' )
if( document.viewing.type.name == 'Image' )
{
im.src='../' + objs[current].url
im.src='../' + document.viewing.FullPathOnFS
$('#video_div').hide()
if( $('#fname_toggle').prop('checked' ) )
$('#img-cap').show()
$('#fname_i').html(PrettyFname(objs[current].url))
$('#fname_i').html(PrettyFname(document.viewing.FullPathOnFS))
$('#figure').show()
if( fullscreen )
$('#canvas').get(0).requestFullscreen()
@@ -170,11 +170,11 @@ function ViewImageOrVideo()
if( document.fullscreen )
document.exitFullscreen()
}
if( objs[current].type == 'Video' )
if( document.viewing.type.name == 'Video' )
{
$('#figure').hide()
$('#video').prop('src', '../' + objs[current].url )
$('#fname_v').html(PrettyFname(objs[current].url))
$('#video').prop('src', '../' + document.viewing.FullPathOnFS )
$('#fname_v').html(PrettyFname(document.viewing.FullPathOnFS))
if( $('#fname_toggle').prop('checked' ) )
$('#img-cap').hide()
ResizeVideo()
@@ -221,32 +221,32 @@ $(document).ready( function()
item_list = { not_a_face: { name: "Not a face", which_face: '-1' } }
for( i=0; i<objs[current].faces.length; i++ )
for( i=0; i<document.viewing.faces.length; i++ )
{
fx = objs[current].faces[i].x / ( im.width/canvas.width )
fy = objs[current].faces[i].y / ( im.height/canvas.height )
fw = objs[current].faces[i].w / ( im.width/canvas.width )
fh = objs[current].faces[i].h / ( im.height/canvas.height )
fx = document.viewing.faces[i].x / ( im.width/canvas.width )
fy = document.viewing.faces[i].y / ( im.height/canvas.height )
fw = document.viewing.faces[i].w / ( im.width/canvas.width )
fh = document.viewing.faces[i].h / ( im.height/canvas.height )
if( x >= fx && x <= fx+fw && y >= fy && y <= fy+fh )
{
if( objs[current].faces[i].override )
if( document.viewing.faces[i].override )
{
item_list['remove_force_match_override']={ 'name': 'Remove override for this face', 'which_face': i, 'id': objs[current].faces[i].id }
item_list['remove_force_match_override']={ 'name': 'Remove override for this face', 'which_face': i, 'id': document.viewing.faces[i].id }
}
else if( objs[current].faces[i].who )
else if( document.viewing.faces[i].who )
{
item_list['match']={ 'name': objs[current].faces[i].who, 'which_face': i, 'id': objs[current].faces[i].id }
item_list['match_add_refimg']={ 'name': 'Add this as refimg for ' + objs[current].faces[i].who,
'person_id': objs[current].faces[i].pid, 'who': objs[current].faces[i].who, 'which_face': i, 'id': objs[current].faces[i].id, }
item_list['wrong_person']={ 'name': 'wrong person', 'which_face': i, 'id': objs[current].faces[i].id }
item_list['match']={ 'name': document.viewing.faces[i].who, 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['match_add_refimg']={ 'name': 'Add this as refimg for ' + document.viewing.faces[i].who,
'person_id': document.viewing.faces[i].pid, 'who': document.viewing.faces[i].who, 'which_face': i, 'id': document.viewing.faces[i].id, }
item_list['wrong_person']={ 'name': 'wrong person', 'which_face': i, 'id': document.viewing.faces[i].id }
}
else
{
item_list['no_match_new_person']={ 'name': 'Add as reference image to NEW person', 'which_face': i, 'id': objs[current].faces[i].id }
item_list['no_match_new_refimg']={ 'name': 'Add as reference image to EXISTING person', 'which_face': i, 'id': objs[current].faces[i].id }
item_list['no_match_new_person']={ 'name': 'Add as reference image to NEW person', 'which_face': i, 'id': document.viewing.faces[i].id }
item_list['no_match_new_refimg']={ 'name': 'Add as reference image to EXISTING person', 'which_face': i, 'id': document.viewing.faces[i].id }
for( var el in NMO ) {
item_list['NMO_'+el]={'type_id': NMO[el].type_id, 'name': 'Override: ' + NMO[el].name, 'which_face': i, 'id': objs[current].faces[i].id }
item_list['NMO_'+el]={'type_id': NMO[el].type_id, 'name': 'Override: ' + NMO[el].name, 'which_face': i, 'id': document.viewing.faces[i].id }
}
}
delete item_list['not_a_face']
@@ -280,11 +280,11 @@ function OverrideForceMatch( person_id, key )
}
ofm='&person_id='+person_id+'&face_id='+item[key].id
$.ajax({ type: 'POST', data: ofm, url: '/add_force_match_override', success: function(data) {
objs[current].faces[item[key].which_face].override={}
objs[current].faces[item[key].which_face].override.who=data.person_tag
objs[current].faces[item[key].which_face].override.distance='N/A'
objs[current].faces[item[key].which_face].override.type_id=NMO[fm_idx].id
objs[current].faces[item[key].which_face].override.type_name=NMO[fm_idx].name
document.viewing.faces[item[key].which_face].override={}
document.viewing.faces[item[key].which_face].override.who=data.person_tag
document.viewing.faces[item[key].which_face].override.distance='N/A'
document.viewing.faces[item[key].which_face].override.type_id=NMO[fm_idx].id
document.viewing.faces[item[key].which_face].override.type_name=NMO[fm_idx].name
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
@@ -303,8 +303,8 @@ function CreatePersonAndRefimg( key )
+'&refimg_data='+item[key].refimg_data
$.ajax({ type: 'POST', data: d, url: '/match_with_create_person',
success: function(data) {
objs[current].faces[item[key].which_face].who=data.who
objs[current].faces[item[key].which_face].distance=data.distance
document.viewing.faces[item[key].which_face].who=data.who
document.viewing.faces[item[key].which_face].distance=data.distance
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
DrawImg()
@@ -318,8 +318,8 @@ function AddRefimgTo( person_id, key, search )
d='&face_id='+item[key].id+'&person_id='+person_id+'&refimg_data='+item[key].refimg_data+'&search='+search
$.ajax({ type: 'POST', data: d, url: '/add_refimg_to_person',
success: function(data) {
objs[current].faces[item[key].which_face].who=data.who
objs[current].faces[item[key].which_face].distance=data.distance
document.viewing.faces[item[key].which_face].who=data.who
document.viewing.faces[item[key].which_face].distance=data.distance
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
DrawImg()
@@ -367,15 +367,15 @@ function SearchForPerson(content, key, face_id, face_pos, type_id)
function RemoveOverrideForceMatch(face_pos)
{
if( objs[current].faces[face_pos].override )
who=objs[current].faces[face_pos].override.who
if( document.viewing.faces[face_pos].override )
who=document.viewing.faces[face_pos].override.who
else
who=objs[current].faces[face_pos].who
who=document.viewing.faces[face_pos].who
d='&face_id='+objs[current].faces[face_pos].id+'&person_tag='+who+'&file_eid='+current
d='&face_id='+document.viewing.faces[face_pos].id+'&person_tag='+who+'&file_eid='+current
$.ajax({ type: 'POST', data: d, url: '/remove_force_match_override',
success: function(data) {
delete objs[current].faces[face_pos].override
delete document.viewing.faces[face_pos].override
$('#dbox').modal('hide')
DrawImg()
CheckForJobs()
@@ -387,10 +387,10 @@ function RemoveOverrideForceMatch(face_pos)
function RemoveOverrideNoMatch(face_pos, type_id)
{
d='&face_id='+objs[current].faces[face_pos].id+'&type_id='+type_id
d='&face_id='+document.viewing.faces[face_pos].id+'&type_id='+type_id
$.ajax({ type: 'POST', data: d, url: '/remove_no_match_override',
success: function(data) {
delete objs[current].faces[face_pos].override
delete document.viewing.faces[face_pos].override
$('#dbox').modal('hide')
DrawImg()
CheckForJobs()
@@ -405,11 +405,11 @@ function AddNoMatchOverride(type_id, face_id, face_pos, type_id)
d='&type_id='+type_id+'&face_id='+face_id
$.ajax({ type: 'POST', data: d, url: '/add_no_match_override',
success: function(data) {
objs[current].faces[face_pos].override={}
objs[current].faces[face_pos].override.who=NMO[type_id].name
objs[current].faces[face_pos].override.distance='N/A'
objs[current].faces[face_pos].override.type_id=type_id
objs[current].faces[face_pos].override.type_name=NMO[type_id].name
document.viewing.faces[face_pos].override={}
document.viewing.faces[face_pos].override.who=NMO[type_id].name
document.viewing.faces[face_pos].override.distance='N/A'
document.viewing.faces[face_pos].override.type_id=type_id
document.viewing.faces[face_pos].override.type_name=NMO[type_id].name
$('#dbox').modal('hide')
$('#faces').prop('checked',true)
DrawImg()
@@ -457,17 +457,17 @@ function FaceDBox(key, item)
div+='</div><div class="col-6">'
if ( key == 'remove_force_match_override' )
{
if( objs[current].faces[face_pos].override.type_name == 'Manual match to existing person' )
div+='<div class="row col-12">remove this override (force match to: ' + objs[current].faces[face_pos].override.who + ')</div>'
if( document.viewing.faces[face_pos].override.type_name == 'Manual match to existing person' )
div+='<div class="row col-12">remove this override (force match to: ' + document.viewing.faces[face_pos].override.who + ')</div>'
else
div+='<div class="row col-12">remove this override (no match)</div>'
div+='<div class="row">'
div+='<button class="btn btn-outline-info col-6" type="button" onClick="$(\'#dbox\').modal(\'hide\'); return false">Cancel</button>'
div+='<button class="btn btn-outline-danger col-6" type="button" '
if( objs[current].faces[face_pos].override.type_name == 'Manual match to existing person' )
if( document.viewing.faces[face_pos].override.type_name == 'Manual match to existing person' )
div+='onClick="RemoveOverrideForceMatch(' +face_pos+ ')">Remove</button>'
else
div+='onClick="RemoveOverrideNoMatch(' +face_pos+','+objs[current].faces[face_pos].override.type_id+ ')">Remove</button>'
div+='onClick="RemoveOverrideNoMatch(' +face_pos+','+document.viewing.faces[face_pos].override.type_id+ ')">Remove</button>'
div+='</div>'
}
if ( key == 'no_match_new_person' )
@@ -559,3 +559,8 @@ function JoblogSearch()
}
})
}
function setVideoSource(newSrc) {
$('#videoSource').attr('src', newSrc);
$('#video')[0].load();
}