diff options
author | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-08-06 01:13:08 +0100 |
---|---|---|
committer | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-08-06 01:13:50 +0100 |
commit | d1be7277d54b8d01eba1cfa30bf844b2536c93fc (patch) | |
tree | 190594491e2130879c686341dee655d2d9e2ce68 | |
parent | Add email notification support (diff) | |
download | gentoaster-d1be7277d54b8d01eba1cfa30bf844b2536c93fc.tar.gz gentoaster-d1be7277d54b8d01eba1cfa30bf844b2536c93fc.tar.bz2 gentoaster-d1be7277d54b8d01eba1cfa30bf844b2536c93fc.zip |
Progress bar is now AJAXified!
-rw-r--r-- | web/ajax.php | 72 | ||||
-rw-r--r-- | web/status.php | 36 |
2 files changed, 98 insertions, 10 deletions
diff --git a/web/ajax.php b/web/ajax.php new file mode 100644 index 0000000..105c893 --- /dev/null +++ b/web/ajax.php @@ -0,0 +1,72 @@ +<?php + + // Gentoaster web interface AJAX remote + // Licensed under GPL v3, see COPYING file + + require_once "config.php"; + + $buildID = filter_input(INPUT_GET, "uuid", FILTER_UNSAFE_RAW); + + + $db = new mysqli( + MYSQL_HOSTNAME, + MYSQL_USERNAME, + MYSQL_PASSWORD, + MYSQL_DATABASE + ); + + if (mysqli_connect_errno()) { + die("Could not connect to database ".mysqli_connect_error()); + } + + $stmt = $db->prepare("SELECT handle FROM builds WHERE id = ?"); + $stmt->bind_param("s", $buildID); + $stmt->execute(); + $stmt->store_result(); + if ($stmt->num_rows == 1) { + $stmt->bind_result($handle); + $stmt->fetch(); + $stmt->close(); + $client = new GearmanClient(); + $client->addServer(); + + $status = $client->jobStatus($handle); + if ($status[0]) { + if ($status[3] != 0) { + // in progress + $ret = array("status" => 1, "num" => $status[2], "den" => $status[3]); + } else { + // not yet processed + $ret = array("status" => 2); + } + } else { + $query = "SELECT returncode, result ". + "FROM builds WHERE id = ?"; + $stmt = $db->prepare($query); + $stmt->bind_param("s", $buildID); + $stmt->execute(); + $stmt->bind_result($returncode, $result); + $stmt->fetch(); + $stmt->close(); + if ($returncode !== null) { + if ($returncode == 0) { + // finished + $ret = array("status" => 0); + } else { + // returned with non-zero status code + $ret = array("status" => 3); + } + } else { + // failed + $ret = array("status" => 4); + } + } + } else { + // job not found + $ret = array("status" => -1); + } + + $db->close(); + + echo json_encode($ret); +?>
\ No newline at end of file diff --git a/web/status.php b/web/status.php index ab57a1e..69e8afc 100644 --- a/web/status.php +++ b/web/status.php @@ -49,7 +49,7 @@ if ($status[3] != 0) { $percentage = ceil($status[2]/$status[3]*100); $bres = "Your build is currently running". - " and is ".$percentage."% complete"; + " and is <span id=\"percent\">".$percentage."</span>% complete"; $inprogress = true; } else { $bres = "Task has not yet been processed"; @@ -113,15 +113,31 @@ href="css/ui-lightness/jquery-ui-1.8.14.custom.css"> <script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script> <script type="text/javascript" src="/js/jquery-ui-1.8.14.js"></script> - <?php - if ($inprogress) { - echo '<script> - $(document).ready(function() { - $("#progressbar").progressbar({ value: '.$percentage.' }); - }); - </script>'; - } - ?> + <?php if ($inprogress) { ?> + <script> + var UUID = "<?php echo $buildID; ?>"; + + $(document).ready(function() { + $("#progressbar").progressbar({ value: <?php echo $percentage; ?> }); + }); + + function bar_update() { + $.getJSON('ajax.php?uuid='+UUID, function(data) { + if(data.status == 1) { + percent = Math.floor((data.num/data.den)*100); + $("#progressbar").progressbar({ value: percent }); + $("#percent").html(percent); + } else { + window.location.reload(); + } + }); + setTimeout("bar_update();", 3000); + } + + bar_update(); + </script> + <?php } ?> + </head> <body> <div id="container"> |