renamed toast.js to jobs.js and moved Job related calls to jobs.py form files.py AND get job.py to allow job_mgr msgs to go to F/E via a POST of /checkforjobs (picked up in templates/base.html). move files also calls new CheckForJobs() to pick up when move job finishes without needing a page reload
This commit is contained in:
@@ -64,7 +64,7 @@ function MoveSubmit()
|
||||
// reorder the images via ecnt again, so highlighting can work
|
||||
document.mf_id=0; $('.figure').each( function() { $(this).attr('ecnt', document.mf_id ); document.mf_id++ } )
|
||||
$('#dbox').modal('hide')
|
||||
$.ajax({ type: 'POST', data: $('#mv_fm').serialize(), url: '/move_files', success: function(data){ st=Object; st.message="Created <a class='link-light' href=/job/" + data.job_id + ">Job #" + data.job_id + "</a> to move selected file(s)"; st.alert="success"; StatusMsg(st); return false; } })
|
||||
$.ajax({ type: 'POST', data: $('#mv_fm').serialize(), url: '/move_files', success: function(data){ st=Object; st.message="Created <a class='link-light' href=/job/" + data.job_id + ">Job #" + data.job_id + "</a> to move selected file(s)"; st.alert="success"; StatusMsg(st); CheckForJobs(); return false; } })
|
||||
}
|
||||
|
||||
// show the DBox for a move file, includes all thumbnails of selected files to move
|
||||
|
||||
103
internal/js/jobs.js
Normal file
103
internal/js/jobs.js
Normal file
@@ -0,0 +1,103 @@
|
||||
// create a bs toast in the status_container
|
||||
// can reuse any that are hidden, OR, create a new one by appending as needed (so we can have 2+ toasts on screen)
|
||||
function StatusMsg(st)
|
||||
{
|
||||
console.log( 'StatusMsg() -> ' + st.alert + ': ' + st.message )
|
||||
// look for any '.hide' and '.toast'
|
||||
if( $('.toast.hide').length !== 0 )
|
||||
{
|
||||
// as there may be more than 1 and as bs toast deals with ordering on screen, so just grab first()
|
||||
tid=$('.toast.hide').first().attr('id')
|
||||
// reset body, and the text-* and bg-* class for success, danger, etc.
|
||||
$('#'+tid ).find( '.toast-body').html(st.message)
|
||||
$('#'+tid ).removeClass( function( index, className ) { return (className.match( /(^|\s)(bg-|text-)\S+/g) || []).join(' ') } )
|
||||
$('#'+tid ).addClass( 'bg-' + st.alert )
|
||||
// get rid of white on button (if its there)
|
||||
$('#'+tid ).find( 'button' ).removeClass('btn-close-white')
|
||||
if( st.alert == "success" || st.alert == "danger" )
|
||||
{
|
||||
$('#'+tid ).addClass( 'text-white' )
|
||||
$('#'+tid ).find( 'button' ).addClass('btn-close-white')
|
||||
}
|
||||
// show the popup (by default it fades)
|
||||
$('#'+tid ).toast("show")
|
||||
}
|
||||
else
|
||||
{
|
||||
// find the id of the 'last' toast (either there are none, or they are all visible [note: we are in the else already])
|
||||
tmp=$('.toast').last().attr('id')
|
||||
// if none, there are no toasts at all, so make '#1'
|
||||
if( tmp== '' )
|
||||
tid=1
|
||||
else
|
||||
{
|
||||
// skip 'st' at front of DOM id, and then increment to get id for new one
|
||||
tid=tmp.substr(2)
|
||||
tid++
|
||||
}
|
||||
// make new div, include st.alert as background colour, and st.message as toast body
|
||||
div='<div id="st' + tid + '" class="toast hide align-items-center border-0'
|
||||
if( st.alert == "success" || st.alert == "danger" )
|
||||
div += ' text-white'
|
||||
div += ' bg-' + st.alert
|
||||
div += `" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
`
|
||||
div += st.message
|
||||
div += `
|
||||
</div>
|
||||
<button type="button" class="btn-close me-2 m-auto
|
||||
`
|
||||
if( st.alert == "success" || st.alert == "danger" )
|
||||
div =+ ' btn-close-white'
|
||||
div += `
|
||||
" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
// can be appended straight after st1 as the .toast("show") deals with display ordering
|
||||
$('#st1').append(div)
|
||||
// show the popup (by default it fades)
|
||||
$('#st' + tid ).toast("show")
|
||||
}
|
||||
}
|
||||
|
||||
// this will make the active jobs badge red with a > 0 value, or navbar colours
|
||||
// if 0 (effectively hiding it, but leaving the same width)
|
||||
function SetActiveJobsBadge(num_jobs)
|
||||
{
|
||||
if( num_jobs > 0 )
|
||||
$('#num_active_jobs').removeClass("invisible")
|
||||
else
|
||||
$('#num_active_jobs').addClass("invisible")
|
||||
$('#num_active_jobs').html(num_jobs)
|
||||
}
|
||||
|
||||
// this function is called either when we load and PA page and active jobs > 0
|
||||
// OR, when a new job is created in the F/E and therefore active jobs > 0
|
||||
// it keeps looking to see if the pa_job_manager has sent a response (via the DB)
|
||||
// if so, it handles the response(s) with toast()s and updates the active job
|
||||
// badge in the navbar. If all jobs are complete it stops calling itself
|
||||
// after a 1 second timeout
|
||||
function CheckForJobs()
|
||||
{
|
||||
$.ajax(
|
||||
{
|
||||
type: 'POST', url: '/checkforjobs',
|
||||
success: function(data) {
|
||||
data.sts.forEach(
|
||||
function(el)
|
||||
{
|
||||
StatusMsg(el)
|
||||
}
|
||||
)
|
||||
SetActiveJobsBadge(data.num_active_jobs)
|
||||
if( data.num_active_jobs > 0 )
|
||||
{
|
||||
setTimeout( function() { CheckForJobCompletion() }, 1000 );
|
||||
}
|
||||
},
|
||||
} )
|
||||
return false;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
// create a bs toast in the status_container
|
||||
function StatusMsg(st)
|
||||
{
|
||||
// look for first '.hide' in #status_container (there may be more than 1)
|
||||
if( $('.toast.hide').length !== 0 )
|
||||
{
|
||||
tid=$('.toast.hide').first().attr('id')
|
||||
$('#'+tid ).find( '.toast-body').html(st.message)
|
||||
$('#'+tid ).removeClass( function( index, className ) { return (className.match( /(^|\s)bg-\S+/g) || []).join(' ') } )
|
||||
$('#'+tid ).addClass( 'bg-' + st.alert )
|
||||
$('#'+tid ).toast("show")
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp=$('.toast').last().attr('id')
|
||||
if( tmp== '' )
|
||||
tid=1
|
||||
else
|
||||
{
|
||||
// skip 'st'
|
||||
tid=tmp.substr(2)
|
||||
tid++
|
||||
}
|
||||
div='<div id="st' + tid + '" class="toast hide align-items-center text-white border-0 bg-' + st.alert
|
||||
div += `" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
`
|
||||
div += st.message
|
||||
div += `
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
// can be appended straight after st1 as the .toast("show") deals with display ordering
|
||||
$('#st1').append(div)
|
||||
$('#st' + tid ).toast("show")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user