forked from science-ation/science-ation
convert judges scheduler status AJAX to JQuery
This commit is contained in:
parent
8e650a104d
commit
1a2fc19fca
@ -29,7 +29,6 @@ ogram; see the file COPYING. If not, write to
|
|||||||
'Administration' => 'admin/index.php',
|
'Administration' => 'admin/index.php',
|
||||||
'Judges' => 'admin/judges.php')
|
'Judges' => 'admin/judges.php')
|
||||||
);
|
);
|
||||||
require_once("../ajax.inc.php");
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -41,46 +40,29 @@ var avgtimeperpercent=0;
|
|||||||
var remainingpercent=0;
|
var remainingpercent=0;
|
||||||
var remainingtime=0;
|
var remainingtime=0;
|
||||||
|
|
||||||
function updateStatus()
|
$(document).ready(function() {
|
||||||
{
|
updateStatus();
|
||||||
document.getElementById('updatestatus').innerHTML="Updating...";
|
});
|
||||||
|
|
||||||
|
function updateStatus() {
|
||||||
var url="judges_scheduler_status_output.php";
|
var url="judges_scheduler_status_output.php";
|
||||||
http.open("GET",url,true);
|
$("#updatestatus").html("Updating...");
|
||||||
http.readystate=0;
|
$.get(url,null,function(data) {
|
||||||
http.onreadystatechange=handleResponse;
|
var obj=data.split(":");
|
||||||
http.send(null);
|
$("#schedulerstatus").html(obj[1]);
|
||||||
}
|
if(obj[0]=="-1") {
|
||||||
|
$("#schedulerpercent").html("100%");
|
||||||
function clearUpdatingMessage()
|
$("#updatestatus").html("Scheduling Complete");
|
||||||
{
|
$("#schedulereta").html("Complete");
|
||||||
document.getElementById('updatestatus').innerHTML="Waiting...";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleResponse()
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
|
|
||||||
if(http.readyState==4)
|
|
||||||
{
|
|
||||||
var obj=http.responseText.split(":");
|
|
||||||
document.getElementById('schedulerstatus').innerHTML=obj[1];
|
|
||||||
if(obj[0]=="-1")
|
|
||||||
{
|
|
||||||
document.getElementById('schedulerpercent').innerHTML="100%";
|
|
||||||
document.getElementById('updatestatus').innerHTML="Scheduling Complete";
|
|
||||||
document.getElementById('schedulereta').innerHTML="Complete";
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
$("#schedulerpercent").html(obj[0]+"%");
|
||||||
document.getElementById('schedulerpercent').innerHTML=obj[0]+"%";
|
|
||||||
setTimeout('updateStatus()',5000);
|
setTimeout('updateStatus()',5000);
|
||||||
document.getElementById('updatestatus').innerHTML="Updating... Done!";
|
$("#updatestatus").html("Updating... Done!");
|
||||||
setTimeout('clearUpdatingMessage()',500);
|
setTimeout('clearUpdatingMessage()',500);
|
||||||
|
|
||||||
var currentTime=new Date();
|
var currentTime=new Date();
|
||||||
if(starttime==0)
|
if(starttime==0) {
|
||||||
{
|
|
||||||
starttime=currentTime.getTime();
|
starttime=currentTime.getTime();
|
||||||
startpercent=obj[0];
|
startpercent=obj[0];
|
||||||
}
|
}
|
||||||
@ -91,32 +73,61 @@ function handleResponse()
|
|||||||
remainingpercent=100-obj[0];
|
remainingpercent=100-obj[0];
|
||||||
remainingtime=remainingpercent*avgtimeperpercent;
|
remainingtime=remainingpercent*avgtimeperpercent;
|
||||||
if(remainingtime && obj[0]>0)
|
if(remainingtime && obj[0]>0)
|
||||||
document.getElementById('schedulereta').innerHTML=Math.round(remainingtime/1000)+" seconds";
|
$("#schedulereta").html(format_duration(Math.round(remainingtime/1000)));
|
||||||
else
|
else
|
||||||
document.getElementById('schedulereta').innerHTML="Calculating...";
|
$("#schedulereta").html("Calculating...");
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
|
||||||
catch(e)
|
|
||||||
{
|
|
||||||
alert('caught error'+e);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearUpdatingMessage() {
|
||||||
|
$("#updatestatus").html("Waiting...");
|
||||||
|
}
|
||||||
|
|
||||||
|
function format_duration(seconds) {
|
||||||
|
/*
|
||||||
|
'1 year|:count years' => 31536000,
|
||||||
|
'1 week|:count weeks' => 604800,
|
||||||
|
'1 day|:count days' => 86400,
|
||||||
|
'1 hour|:count hours' => 3600,
|
||||||
|
'1 min|:count min' => 60,
|
||||||
|
'1 sec|:count sec' => 1);
|
||||||
|
*/
|
||||||
|
|
||||||
|
var s=seconds;
|
||||||
|
var output=s+':';
|
||||||
|
if(s>86400) {
|
||||||
|
var days=Math.floor(s/86400)
|
||||||
|
s-=days*86400;
|
||||||
|
output+=days+' days ';
|
||||||
|
}
|
||||||
|
if(s>3600) {
|
||||||
|
var hours=Math.floor(s/3600)
|
||||||
|
s-=hours*3600;
|
||||||
|
output+=hours+' hours ';
|
||||||
|
}
|
||||||
|
if(s>60) {
|
||||||
|
var minutes=Math.floor(s/60)
|
||||||
|
s-=minutes*60;
|
||||||
|
output+=minutes+' minutes ';
|
||||||
|
}
|
||||||
|
output+=s+' seconds ';
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?
|
<?
|
||||||
if($config['judge_scheduler_percent']=="-1")
|
if($config['judge_scheduler_percent']=="-1") {
|
||||||
{
|
|
||||||
echo i18n("The judge scheduler is not currently running");
|
echo i18n("The judge scheduler is not currently running");
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
echo "<a href=\"judges_schedulerconfig.php\">".i18n("Judges Scheduler Configuration")."</a>";
|
echo "<a href=\"judges_schedulerconfig.php\">".i18n("Judges Scheduler Configuration")."</a>";
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
echo "<table>";
|
echo "<table>";
|
||||||
echo "<tr><td>".i18n("Scheduler status").":</td><td><div id=\"schedulerstatus\" style=\"font-weight: bold;\"></div></td></tr>";
|
echo "<tr><td>".i18n("Scheduler status").":</td><td><div id=\"schedulerstatus\" style=\"font-weight: bold;\"></div></td></tr>";
|
||||||
echo "<tr><td>".i18n("Scheduler percent").":</td><td><div id=\"schedulerpercent\" style=\"font-weight: bold;\"></div></td></tr>";
|
echo "<tr><td>".i18n("Scheduler percent").":</td><td><div id=\"schedulerpercent\" style=\"font-weight: bold;\"></div></td></tr>";
|
||||||
@ -134,10 +145,6 @@ echo "<br />";
|
|||||||
echo "<a href=\"reports.php\">".i18n("Print/Export Reports")."</a>";
|
echo "<a href=\"reports.php\">".i18n("Print/Export Reports")."</a>";
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
echo "<br />";
|
echo "<br />";
|
||||||
P
|
|
||||||
?>
|
|
||||||
<script type="text/javascript">updateStatus()</script>
|
|
||||||
<?
|
|
||||||
}
|
}
|
||||||
send_footer();
|
send_footer();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user