aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorGravatar Thomas Petazzoni <thomas.petazzoni@bootlin.com>2018-11-01 10:41:32 +0100
committerGravatar Thomas Petazzoni <thomas.petazzoni@bootlin.com>2018-11-01 12:08:51 +0100
commit098888e2e9a6cca1a359242a6f9cf9f21f69286b (patch)
tree392332db8bf5c55326952f9836747e8801fc75ca /web
parent3ba26de8eb92595929e08aa696babbbf574b5852 (diff)
downloadbuildroot-test-098888e2e9a6cca1a359242a6f9cf9f21f69286b.tar.gz
buildroot-test-098888e2e9a6cca1a359242a6f9cf9f21f69286b.tar.bz2
web: rework filtering logic
This makes the code shorter, and will allow to fix the next/previous links to keep the filters. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Diffstat (limited to 'web')
-rw-r--r--web/funcs.inc.php48
-rw-r--r--web/index.php45
2 files changed, 39 insertions, 54 deletions
diff --git a/web/funcs.inc.php b/web/funcs.inc.php
index d7b1321..784b142 100644
--- a/web/funcs.inc.php
+++ b/web/funcs.inc.php
@@ -47,36 +47,38 @@ function bab_total_results_count()
return $ret[0];
}
+$status_map = array(
+ "OK" => 0,
+ "NOK" => 1,
+ "TIMEOUT" => 2,
+);
+
/*
* Returns an array containing the build results starting from $start,
* and limited to $count items. The items starting with $start=0 are
* the most recent build results.
*/
-function bab_get_results($start=0, $count=100, $filter_status=-1, $filter_arch="", $filter_reason="", $filter_submitter="", $filter_libc="", $filter_static="", $filter_subarch="", $filter_branch="")
+function bab_get_results($start=0, $count=100, $filters = array())
{
+ global $status_map;
$db = new db();
- $where_parts = array();
- if ($filter_status != -1)
- $where_parts[] = " status=" . $db->quote_smart($filter_status) . " ";
- if ($filter_arch != "")
- $where_parts[] = " arch=" . $db->quote_smart($filter_arch) . " ";
- if ($filter_reason != '')
- $where_parts[] = " reason like " . $db->quote_smart($filter_reason) . " ";
- if ($filter_submitter != '')
- $where_parts[] = " submitter=" . $db->quote_smart($filter_submitter) . " ";
- if ($filter_libc != '')
- $where_parts[] = " libc=" . $db->quote_smart($filter_libc) . " ";
- if ($filter_static != '')
- $where_parts[] = " static=" . $db->quote_smart($filter_static) . " ";
- if ($filter_subarch != '')
- $where_parts[] = " subarch=" . $db->quote_smart($filter_subarch) . " ";
- if ($filter_branch != '')
- $where_parts[] = " branch=" . $db->quote_smart($filter_branch) . " ";
- if (count($where_parts)) {
- $condition = "where " . implode("and", $where_parts);
- } else {
- $condition = "";
- }
+
+ $sql_filters = implode(' and ', array_map(
+ function ($v, $k) use ($db, $status_map) {
+ if ($k == "reason")
+ return sprintf("%s like %s", $k, $db->quote_smart($v));
+ else if ($k == "status")
+ return sprintf("%s=%s", $k, $db->quote_smart($status_map[$v]));
+ else
+ return sprintf("%s=%s", $k, $db->quote_smart($v));
+ },
+ $filters,
+ array_keys($filters)
+ ));
+
+ if (count($filters))
+ $condition = "where " . $sql_filters;
+
$sql = "select * from results $condition order by builddate desc limit $start, $count;";
$ret = $db->query($sql);
if ($ret == FALSE) {
diff --git a/web/index.php b/web/index.php
index 25423d5..0612643 100644
--- a/web/index.php
+++ b/web/index.php
@@ -23,6 +23,8 @@ function format_duration($seconds_count)
return "$hours$minutes$seconds";
}
+$filters = array();
+
/* When no start is given, or start is a crazy value (not an integer),
just default to start=0 */
if (! isset($_GET['start']) || ! preg_match("/^[0-9]*$/", $_GET['start']))
@@ -38,50 +40,31 @@ else
if ($step > 250)
$step = 250;
-$filter_status = -1;
-if (isset ($_GET['status'])) {
- if ($_GET['status'] == 'OK')
- $filter_status = 0;
- else if ($_GET['status'] == 'NOK')
- $filter_status = 1;
- else if ($_GET['status'] == 'TIMEOUT')
- $filter_status = 2;
-}
+$valid_status = array("OK", "NOK", "TIMEOUT");
+
+if (isset ($_GET['status']) && in_array($_GET['status'], $valid_status))
+ $filters["status"] = $_GET['status'];
if (isset($_GET['arch']) && preg_match("/^[a-z0-9_]*$/", $_GET['arch']))
- $filter_arch = $_GET['arch'];
-else
- $filter_arch = "";
+ $filters["arch"] = $_GET['arch'];
if (isset($_GET['branch']) && preg_match("/^[a-z0-9_\.]*$/", $_GET['branch']))
- $filter_branch = $_GET['branch'];
-else
- $filter_branch = "";
+ $filters["branch"] = $_GET['branch'];
if (isset($_GET['reason']) && preg_match("/^[A-Za-z0-9_%\+\.\-]*$/", $_GET['reason']))
- $filter_reason = $_GET['reason'];
-else
- $filter_reason = "";
+ $filters["reason"] = $_GET['reason'];
if (isset($_GET['libc']) && preg_match("/^[a-z]*$/", $_GET['libc']))
- $filter_libc = $_GET['libc'];
-else
- $filter_libc = "";
+ $filters["libc"] = $_GET['libc'];
if (isset($_GET['static']) && preg_match("/^[0-1]$/", $_GET['static']))
- $filter_static = $_GET['static'];
-else
- $filter_static = "";
+ $filters["static"] = $_GET['static'];
if (isset($_GET['subarch']) && preg_match("/^[A-Za-z0-9_\+\.\-]*$/", $_GET['subarch']))
- $filter_subarch = $_GET['subarch'];
-else
- $filter_subarch = "";
+ $filters["subarch"] = $_GET['subarch'];
if (isset ($_GET['submitter']))
- $filter_submitter = urldecode($_GET['submitter']);
-else
- $filter_submitter = "";
+ $filters["submitter"] = urldecode($_GET['submitter']);
bab_header("Buildroot tests");
@@ -91,7 +74,7 @@ echo "<tr class=\"header\">";
echo "<td>Date</td><td>Duration</td><td>Status</td><td>Commit ID</td><td>Submitter</td><td>Arch/Subarch</td><td>Failure reason</td><td>Libc</td><td>Static?</td><td>Data</td>";
echo "</tr>";
-$results = bab_get_results($start, $step, $filter_status, $filter_arch, $filter_reason, $filter_submitter, $filter_libc, $filter_static, $filter_subarch, $filter_branch);
+$results = bab_get_results($start, $step, $filters);
while ($current = mysqli_fetch_object($results)) {