Index: trunk/web2/addons/job_monarch/jobstore.php
===================================================================
--- trunk/web2/addons/job_monarch/jobstore.php (revision 537)
+++ trunk/web2/addons/job_monarch/jobstore.php (revision 538)
@@ -7,6 +7,10 @@
// Supplied by ExtJS when DataStore has remoteSort: true
//
-$sortfield = $_POST["sort"];
-$sortorder = $_POST["dir"]; // ASC or DESC
+$sortfield = isset($_POST['sort'] ) ? $_POST["sort"] : "jid";
+$sortorder = isset($_POST['dir'] ) ? $_POST["dir"] : "ASC"; // ASC or DESC
+
+// Search query from ext.SearchField
+//
+$query = isset($_POST['query']) ? $_POST['query'] : null;
global $c, $clustername, $cluster;
@@ -19,4 +23,5 @@
$pend = (int) $_POST['limit'];
+//echo $pend.'p ';
// Need to fool Ganglia here: or it won't parse XML for our cluster
//
@@ -53,6 +58,4 @@
$task = $HTTP_POST_VARS['task'];
}
-
-//getList();
switch($task)
@@ -64,4 +67,34 @@
echo "{failure:true}";
break;
+}
+
+function quickSearchJobs( $jobs, $query )
+{
+ $searchresults = array();
+
+ foreach( $jobs as $jobid => $jobattrs )
+ {
+ if( $query != null )
+ {
+ if( strpos( $jobattrs['jid'], $query ) !== false )
+ {
+ $searchresults[$jobid] = $jobattrs;
+ }
+ if( strpos( $jobattrs['owner'], $query ) !== false )
+ {
+ $searchresults[$jobid] = $jobattrs;
+ }
+ if( strpos( $jobattrs['queue'], $query ) !== false )
+ {
+ $searchresults[$jobid] = $jobattrs;
+ }
+ if( strpos( $jobattrs['name'], $query ) !== false )
+ {
+ $searchresults[$jobid] = $jobattrs;
+ }
+ }
+ }
+
+ return $searchresults;
}
@@ -181,29 +214,25 @@
{
global $jobs, $hearbeat, $pstart, $pend;
- global $sortfield, $sortorder;
-
- $job_count = count( $jobs );
+ global $sortfield, $sortorder, $query;
+
+ $job_count = count( $jobs );
if( $job_count == 0 )
{
- echo 'crap({"total":"0", "results":""})';
+ echo '({"total":"0", "results":""})';
return 0;
}
- $jobresults = array();
-
- $cur_job = 0;
-
-
- // sorteer jobs op sortorder en sortfield
-
- //if( $pstart > 0 ) {
- //echo $pstart;
- //echo $pend; }
-
+ $jobresults = array();
+
+ $cur_job = 0;
$sorted_jobs = sortJobs( $jobs, $sortfield, $sortorder );
- $result_count = count( $sorted_jobs );
+ if( $query != null )
+ {
+ $jobs = quickSearchJobs( $jobs, $query );
+ }
+ $result_count = count( $jobs );
foreach( $sorted_jobs as $jobid => $jobattrs )
@@ -214,10 +243,10 @@
//}
- if( ( $cur_job < $pstart ) || ( ($cur_job - $pstart) >= $pend ) )
- {
- $cur_job = $cur_job + 1;
+ if( ! array_key_exists( $jobid, $jobs ) )
+ {
continue;
}
+ $jr = array();
$jr['jid'] = strval( $jobid );
$jr['status'] = $jobs[$jobid]['status'];
@@ -261,5 +290,13 @@
}
- $cur_job = $cur_job + 1;
+ if( ( $cur_job < $pstart ) || ( ($cur_job - $pstart) >= $pend ) )
+ {
+ $cur_job = $cur_job + 1;
+ continue;
+ }
+ else
+ {
+ $cur_job = $cur_job + 1;
+ }
$jobresults[] = $jr;
@@ -273,17 +310,18 @@
}
-// Encodes a SQL array into a JSON formated string
+// Encodes a SQL array into a JSON formated string: so that Javascript may understand it
+//
function JEncode( $arr )
{
- if (version_compare(PHP_VERSION,"5.2","<"))
+ if( version_compare( PHP_VERSION, "5.2", "<" ) )
{
- require_once("./JSON.php"); //if php<5.2 need JSON class
-
- $json = new Services_JSON();//instantiate new json object
- $data = $json->encode($arr); //encode the data in json format
+ require_once( "./JSON.php" ); //if php<5.2 need JSON class
+
+ $json = new Services_JSON(); //instantiate new json object
+ $data = $json->encode( $arr ); //encode the data in json format
}
else
{
- $data = json_encode($arr); //encode the data in json format
+ $data = json_encode( $arr ); //encode the data in json format
}
Index: trunk/web2/addons/job_monarch/js/jobgrid.js
===================================================================
--- trunk/web2/addons/job_monarch/js/jobgrid.js (revision 537)
+++ trunk/web2/addons/job_monarch/js/jobgrid.js (revision 538)
@@ -149,5 +149,11 @@
store: JobsDataStore,
displayInfo: true
- })
+ }),
+ tbar: [ new Ext.app.SearchField({
+ store: JobsDataStore,
+ params: {start: 0, limit: 30},
+ width: 200
+ })
+ ]
});
Index: trunk/web2/addons/job_monarch/templates/header.tpl
===================================================================
--- trunk/web2/addons/job_monarch/templates/header.tpl (revision 537)
+++ trunk/web2/addons/job_monarch/templates/header.tpl (revision 538)
@@ -11,5 +11,5 @@
-
+