revamp whole EA flow. Server created EAs when we do certain jobs (transform, delete_files, restore_files), then instead of faking amendments in the jscript, get job creation to return EA from job ORM, then check is now generic for end of any amendment job, and when it finishes, use that to clear our amendments in document, and redraw through normal UI code. No smarts in client, all driven by state from server, and if we reload a page mid jobs, it has required state, and because an amendment job is still progressing, it runs check code again

This commit is contained in:
2025-10-25 18:21:28 +11:00
parent d3ae9b788f
commit 9bdd9d5b78
6 changed files with 236 additions and 171 deletions

View File

@@ -2,75 +2,26 @@
// can only have 1 ammendment per image, its grayed out for other changes
function removeAmendment( id )
{
document.amendments=document.amendments.filter(obj => obj.eid !== id)
console.log( 'removing amendment for: ' + id )
document.amendments=document.amendments.filter(obj => obj.eid !== id)
}
// POST to a check URL, that will tell us if the transformation has completed,
// if not, try again in 1 second... If it has finished then reset the thumbnail
// to full colour, put it back to being an entry and reset the thumbnail to the
// newly created one that was sent back in the response to the POST
function handleTransformFiles(data,id,job_id)
// If Transform job has finished then reset relevant document.entries
// with updated from DB, remove the amendment and redraw image
function handleTransformImageJobCompleted(job, entry)
{
if( data.finished )
{
id=parseInt(id)
idx = entryList.indexOf(id)
// replace data for this entry now its been transformed
document.entries[idx]=data.entry
// update cache too
// document.page[getPageNumberForId(id)][howFarIntoPageCache(id)]=data.entry
// FIXME: for now just invalidate whole cache
document.page.length=0
removeAmendment( id )
// redraw into figure html in dom
last={ 'printed': 'not required' }
html = createFigureHtml( data.entry, last, 9999 )
$('#'+id).replaceWith( html )
return false;
}
else
{
setTimeout( function() { CheckTransformJob(id,job_id,handleTransformFiles) }, 1000,id, job_id );
}
}
removeAmendment( entry.id )
// update viewer and files* views, in case we view/go up without a new page load
// force reload with timestamped version of im.src
im.src=im.src + '?t=' + new Date().getTime();
DrawImg()
// POST to a check URL, that will tell us if the transformation has completed,
// if not, try again in 1 second... If it has finished then reset the image
// to full colour
function handleTransformViewing(data,id,job_id)
{
if( data.finished )
{
// stop throbber, remove grayscale & then force reload with timestamped version of im.src
im.src=im.src + '?t=' + new Date().getTime();
removeAmendment( id )
return false;
}
else
{
setTimeout( function() { CheckTransformJob(id,job_id,handleTransformViewing) }, 1000,id, job_id );
}
}
// POST to a check URL, that will tell us if the transformation has completed,
// if not, try again in 1 second... If it has finished then reset the thumbnail
// to full colour, put it back to being an entry and reset the thumbnail to the
// newly created one that was sent back in the response to the POST
function CheckTransformJob(id,job_id,successCallback)
{
CheckForJobs()
$.ajax( { type: 'POST', data: '&job_id='+job_id, url: '/check_transform_job',
success: function(res) { successCallback(res,id,job_id); } } )
}
// function to add data for document.amendment based on id and amt
// used when we transform several images in files_*, or single image in viewer
function addTransformAmendment(id,amt)
{
am={}
am.eid=parseInt(id)
am.type = document.amendTypes.filter(obj => obj.job_name === 'transform_image:'+amt )[0]
document.amendments.push(am)
idx = entryList.indexOf(entry.id)
// replace data for this entry now its been transformed
document.entries[idx]=entry
// redraw into figure html in dom
html = createFigureHtml( entry )
$('#'+entry.id).replaceWith( html )
}
// for each highlighted image, POST the transform with amt (90, 180, 270,
@@ -81,15 +32,13 @@ function addTransformAmendment(id,amt)
function Transform(amt)
{
// we are in the viewer with 1 image only...
if( document.viewing )
if( $('#viewer_div').length && ! $('#viewer_div').hasClass('d-none') )
{
post_data = '&amt='+amt+'&id='+document.viewing.id
// POST /transform for image, grayscale the image, add throbber, & start checking for end of job
$.ajax({ type: 'POST', data: post_data, url: '/transform', success: function(data) {
addTransformAmendment(document.viewing.id, amt)
DrawImg();
CheckTransformJob(document.viewing.id,data.job_id,handleTransformViewing);
return false;
processAmendments(data.job.amendments)
checkForAmendmentJobToComplete(data.job.id)
} })
}
else
@@ -98,13 +47,8 @@ function Transform(amt)
post_data = '&amt='+amt+'&id='+e.id
// POST /transform for image, grayscale the thumbnail, add throbber, & start checking for end of job
$.ajax({ type: 'POST', data: post_data, url: '/transform', success: function(data){
addTransformAmendment(e.id, amt)
last={ 'printed': 'not required' }
idx = pageList.indexOf(parseInt(e.id))
html = createFigureHtml( document.entries[idx], last, 9999 )
$('#'+e.id).replaceWith( html )
CheckTransformJob(e.id,data.job_id,handleTransformFiles);
return false;
processAmendments(data.job.amendments)
checkForAmendmentJobToComplete(data.job.id)
} })
} )
}