Changeset 538


Ignore:
Timestamp:
07/11/08 11:05:46 (16 years ago)
Author:
ramonb
Message:

job_monarch/js/jobgrid.js,
job_monarch/templates/header.tpl:

  • added searchField

job_monarch/jobstore.php:

  • added quickSearchJobs
Location:
trunk/web2/addons/job_monarch
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/web2/addons/job_monarch/jobstore.php

    r537 r538  
    77// Supplied by ExtJS when DataStore has remoteSort: true
    88//
    9 $sortfield              = $_POST["sort"];
    10 $sortorder              = $_POST["dir"]; // ASC or DESC
     9$sortfield              = isset($_POST['sort'] ) ? $_POST["sort"] : "jid";
     10$sortorder              = isset($_POST['dir'] ) ? $_POST["dir"] : "ASC"; // ASC or DESC
     11
     12// Search query from ext.SearchField
     13//
     14$query                  = isset($_POST['query']) ? $_POST['query'] : null;
    1115
    1216global $c, $clustername, $cluster;
     
    1923$pend   = (int) $_POST['limit'];
    2024
     25//echo $pend.'p ';
    2126// Need to fool Ganglia here: or it won't parse XML for our cluster
    2227//
     
    5358        $task = $HTTP_POST_VARS['task'];
    5459}
    55 
    56 //getList();
    5760
    5861switch($task)
     
    6467        echo "{failure:true}";
    6568        break;
     69}
     70
     71function quickSearchJobs( $jobs, $query )
     72{
     73        $searchresults  = array();
     74
     75        foreach( $jobs as $jobid => $jobattrs )
     76        {
     77                if( $query != null )
     78                {
     79                        if( strpos( $jobattrs['jid'], $query ) !== false )
     80                        {
     81                                $searchresults[$jobid]  = $jobattrs;
     82                        }
     83                        if( strpos( $jobattrs['owner'], $query ) !== false )
     84                        {
     85                                $searchresults[$jobid]  = $jobattrs;
     86                        }
     87                        if( strpos( $jobattrs['queue'], $query ) !== false )
     88                        {
     89                                $searchresults[$jobid]  = $jobattrs;
     90                        }
     91                        if( strpos( $jobattrs['name'], $query ) !== false )
     92                        {
     93                                $searchresults[$jobid]  = $jobattrs;
     94                        }
     95                }
     96        }
     97
     98        return $searchresults;
    6699}
    67100
     
    181214{
    182215        global $jobs, $hearbeat, $pstart, $pend;
    183         global $sortfield, $sortorder;
    184 
    185         $job_count      = count( $jobs );
     216        global $sortfield, $sortorder, $query;
     217
     218        $job_count              = count( $jobs );
    186219
    187220        if( $job_count == 0 )
    188221        {
    189                 echo 'crap({"total":"0", "results":""})';
     222                echo '({"total":"0", "results":""})';
    190223                return 0;
    191224        }
    192225
    193         $jobresults     = array();
    194 
    195         $cur_job        = 0;
    196 
    197 
    198         // sorteer jobs op sortorder en sortfield
    199 
    200         //if( $pstart > 0 ) {
    201         //echo $pstart;
    202         //echo $pend; }
    203 
     226        $jobresults             = array();
     227
     228        $cur_job                = 0;
    204229
    205230        $sorted_jobs            = sortJobs( $jobs, $sortfield, $sortorder );
    206231
    207         $result_count           = count( $sorted_jobs );
     232        if( $query != null )
     233        {
     234                $jobs                   = quickSearchJobs( $jobs, $query );
     235        }
     236        $result_count           = count( $jobs );
    208237
    209238        foreach( $sorted_jobs as $jobid => $jobattrs )
     
    214243                //}
    215244
    216                 if( ( $cur_job < $pstart ) || ( ($cur_job - $pstart) >= $pend ) )
    217                 {
    218                         $cur_job = $cur_job + 1;
     245                if( ! array_key_exists( $jobid, $jobs ) )
     246                {
    219247                        continue;
    220248                }
    221249
     250                $jr                     = array();
    222251                $jr['jid']              = strval( $jobid );
    223252                $jr['status']           = $jobs[$jobid]['status'];
     
    261290                }
    262291
    263                 $cur_job                = $cur_job + 1;
     292                if( ( $cur_job < $pstart ) || ( ($cur_job - $pstart) >= $pend ) )
     293                {
     294                        $cur_job        = $cur_job + 1;
     295                        continue;
     296                }
     297                else
     298                {
     299                        $cur_job        = $cur_job + 1;
     300                }
    264301
    265302                $jobresults[]           = $jr;
     
    273310}
    274311
    275 // Encodes a SQL array into a JSON formated string
     312// Encodes a SQL array into a JSON formated string: so that Javascript may understand it
     313//
    276314function JEncode( $arr )
    277315{
    278         if (version_compare(PHP_VERSION,"5.2","<"))
     316        if( version_compare( PHP_VERSION, "5.2", "<" ) )
    279317        {   
    280                 require_once("./JSON.php"); //if php<5.2 need JSON class
    281 
    282                 $json   = new Services_JSON();//instantiate new json object
    283                 $data   = $json->encode($arr);  //encode the data in json format
     318                require_once( "./JSON.php" );           //if php<5.2 need JSON class
     319
     320                $json   = new Services_JSON();          //instantiate new json object
     321                $data   = $json->encode( $arr );        //encode the data in json format
    284322        }
    285323        else
    286324        {
    287                 $data   = json_encode($arr);  //encode the data in json format
     325                $data   = json_encode( $arr );          //encode the data in json format
    288326        }
    289327
  • trunk/web2/addons/job_monarch/js/jobgrid.js

    r537 r538  
    149149                store: JobsDataStore,
    150150                displayInfo: true
    151             })
     151            }),
     152      tbar: [ new Ext.app.SearchField({
     153                                store: JobsDataStore,
     154                                params: {start: 0, limit: 30},
     155                                width: 200
     156                    })
     157      ]
    152158    });
    153159
  • trunk/web2/addons/job_monarch/templates/header.tpl

    r537 r538  
    1111<script type="text/javascript" src="./lib/extjs/ext-all.js"></script>
    1212<script type="text/javascript" src="./lib/extjs/ext-all-debug.js"></script>
    13 
     13<script type="text/javascript" src="./lib/extjs/searchfield.js"></script>
    1414<script type="text/javascript" src="./js/jobgrid.js"></script>
    1515<script type="text/javascript">
Note: See TracChangeset for help on using the changeset viewer.