From: "Liam McLoughlin" <hexxeh@hexxeh.net> To: gentoo-commits@lists.gentoo.org Subject: [gentoo-commits] proj/gentoaster:webui commit in: web/ Date: Sat, 6 Aug 2011 00:14:13 +0000 (UTC) [thread overview] Message-ID: <d1be7277d54b8d01eba1cfa30bf844b2536c93fc.hexxeh@gentoo> (raw) commit: d1be7277d54b8d01eba1cfa30bf844b2536c93fc Author: Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net> AuthorDate: Sat Aug 6 00:13:08 2011 +0000 Commit: Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net> CommitDate: Sat Aug 6 00:13:50 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoaster.git;a=commit;h=d1be7277 Progress bar is now AJAXified! --- web/ajax.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 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">
WARNING: multiple messages have this Message-ID (diff)
From: "Liam McLoughlin" <hexxeh@hexxeh.net> To: gentoo-commits@lists.gentoo.org Subject: [gentoo-commits] proj/gentoaster:master commit in: web/ Date: Fri, 12 Aug 2011 23:18:00 +0000 (UTC) [thread overview] Message-ID: <d1be7277d54b8d01eba1cfa30bf844b2536c93fc.hexxeh@gentoo> (raw) Message-ID: <20110812231800.H7Lgi7abLl5Fw1u4iPrdgem5TPLJMTBz00iqp0OWMsg@z> (raw) commit: d1be7277d54b8d01eba1cfa30bf844b2536c93fc Author: Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net> AuthorDate: Sat Aug 6 00:13:08 2011 +0000 Commit: Liam McLoughlin <hexxeh <AT> hexxeh <DOT> net> CommitDate: Sat Aug 6 00:13:50 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoaster.git;a=commit;h=d1be7277 Progress bar is now AJAXified! --- web/ajax.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 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">
next reply other threads:[~2011-08-06 0:14 UTC|newest] Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-08-06 0:14 Liam McLoughlin [this message] 2011-08-12 23:18 ` [gentoo-commits] proj/gentoaster:master commit in: web/ Liam McLoughlin -- strict thread matches above, loose matches on Subject: below -- 2011-08-12 23:17 Liam McLoughlin 2011-08-02 17:22 ` [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin 2011-08-12 23:17 [gentoo-commits] proj/gentoaster:master " Liam McLoughlin 2011-07-28 1:08 ` [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin 2011-08-12 23:17 [gentoo-commits] proj/gentoaster:master " Liam McLoughlin 2011-07-27 22:13 ` [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin 2011-08-12 23:17 [gentoo-commits] proj/gentoaster:master " Liam McLoughlin 2011-07-27 20:04 ` [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin 2011-08-12 23:17 [gentoo-commits] proj/gentoaster:master " Liam McLoughlin 2011-07-24 2:43 ` [gentoo-commits] proj/gentoaster:webui " Liam McLoughlin 2011-08-04 21:04 Liam McLoughlin 2011-08-02 17:31 Liam McLoughlin 2011-07-28 1:12 Liam McLoughlin 2011-07-28 1:02 Liam McLoughlin 2011-07-28 0:56 Liam McLoughlin 2011-07-27 22:11 Liam McLoughlin 2011-07-27 22:11 Liam McLoughlin 2011-07-27 22:04 Liam McLoughlin 2011-07-27 22:02 Liam McLoughlin 2011-07-27 20:25 Liam McLoughlin 2011-07-27 20:11 Liam McLoughlin 2011-07-15 19:59 Liam McLoughlin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=d1be7277d54b8d01eba1cfa30bf844b2536c93fc.hexxeh@gentoo \ --to=hexxeh@hexxeh.net \ --cc=gentoo-commits@lists.gentoo.org \ --cc=gentoo-dev@lists.gentoo.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox