source: trunk/web2/addons/job_monarch/js/jobgrid.js @ 549

Last change on this file since 549 was 549, checked in by ramonb, 16 years ago

job_monarch/overview.php:

job_monarch/libtoga.php:

job_monarch/js/jobgrid.js:

job_monarch/jobstore.php:

  • use session

job_monarch/templates/header.tpl:

job_monarch/image.php:

File size: 8.7 KB
Line 
1var JobsDataStore;
2var JobsColumnModel;
3var JobListingEditorGrid;
4var JobListingWindow;
5var JobProxy;
6var myfilters = { };
7var myparams = { };
8var ClusterImageArgs = { };
9
10var filterfields = [ "jid", "queue", "name", "owner" ];
11
12function makeArrayURL( somearr )
13{
14  filter_url = '';
15  filter_sep = '';
16
17  for( filtername in somearr )
18  {
19    filter_url = filter_url + filter_sep + filtername + '=' + somearr[filtername];
20    filter_sep = '&';
21  }
22
23  return filter_url;
24}
25
26
27function isset( somevar )
28{
29  try
30  {
31    if( eval( somevar ) ) { }
32  }
33  catch( err )
34  {
35    return false;
36  }
37  return true;
38}
39
40function inMyArray( arr, someval )
41{
42  for( arval in arr )
43  {
44    if( arval == someval )
45    {
46      return true;
47    }
48  }
49  return false;
50}
51
52function inMyArrayValues( arr, someval )
53{
54  for( arkey in arr )
55  {
56    if( arr[arkey] == someval )
57    {
58      return true;
59    }
60  }
61  return false;
62}
63
64function inMyArrayKeys( arr, someval )
65{
66  for( arkey in arr )
67  {
68    if( arkey == someval )
69    {
70      return true;
71    }
72  }
73  return false;
74}
75
76function joinMyArray( arr1, arr2 )
77{
78  for( arkey in arr2 )
79  {
80    arr1[arkey] = arr2[arkey];
81  }
82
83  return arr1;
84}
85
86function ClusterImageSelectHost( somehost )
87{
88
89  if( !inMyArrayKeys( myfilters, 'host' ) )
90  {
91    myfilters['host'] = somehost;
92  }
93  else
94  {
95    delete myfilters['host'];
96  }
97
98  ClusterImageArgs['view'] = 'big-clusterimage';
99
100  filt_url = makeArrayURL( myfilters );
101  imag_url = makeArrayURL( ClusterImageArgs );
102
103  document.getElementById( 'clusterimage' ).src = './image.php?' + filt_url + '&' + imag_url;
104
105  return false;
106}
107
108function initJobGrid() {
109
110  Ext.QuickTips.init();
111
112  function jobCellClick(grid, rowIndex, columnIndex, e)
113  {
114    var record = grid.getStore().getAt(rowIndex);  // Get the Record
115    var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
116    var data = record.get(fieldName);
117    var view = grid.getView();
118    var cell = view.getCell( rowIndex, columnIndex );
119
120    if( fieldName == 'owner' || fieldName == 'jid' || fieldName == 'status' || fieldName == 'queue' )
121    {
122      if( !isset( myfilters[fieldName] ) )
123      {
124        Ext.fly(cell).removeClass( 'filterenabled' );
125        Ext.fly(cell).addClass( 'filter' );
126
127        // Remove this filter
128        //
129        delete myfilters[fieldName];
130        delete myparams[fieldName];
131
132        // Respect any other parameters that may have been set outside filters
133        //
134        myparams = joinMyArray( myparams, myfilters );
135
136        // Can't be sure if there are enough pages for new filter: reset to page 1
137        //
138        myparams = joinMyArray( myparams, { start: 0, limit: 30 } );
139
140        grid.getStore().reload( { params: myparams } );
141      }
142      else
143      {
144        Ext.fly(cell).removeClass( 'filter' );
145        Ext.fly(cell).addClass( 'filterenabled' );
146
147        // Set filter for selected column to selected cell value
148        //
149        myfilters[fieldName] = data;
150
151        myparams = joinMyArray( myparams, myfilters );
152        myparams = joinMyArray( myparams, { start: 0, limit: 30 } );
153
154        grid.getStore().reload( { params: myparams } );
155      }
156    }
157  }
158
159  function jobCellRender( value, metadata, record, rowindex, colindex, store )
160  {
161    var fieldName = JobsColumnModel.getColumnById( colindex ).dataIndex;
162
163    if( fieldName == 'owner' || fieldName == 'jid' || fieldName == 'status' || fieldName == 'queue' )
164    {
165      if( myfilters[fieldName] != null )
166      {
167        metadata.css = 'filterenabled';
168      }
169      else
170      {
171        metadata.css = 'filter';
172      }
173    }
174    return value;
175  }
176
177  JobProxy = new Ext.data.HttpProxy({
178                url: 'jobstore.php',
179                method: 'POST'
180            });
181
182  JobsDataStore = new Ext.data.Store({
183      id: 'JobsDataStore',
184      proxy: JobProxy,
185      baseParams:{task: "LISTING"}, // this parameter is passed for any HTTP request
186      reader: new Ext.data.JsonReader({
187        root: 'results',
188        totalProperty: 'total',
189        id: 'id'
190      },[
191        {name: 'jid', type: 'int', mapping: 'jid'},
192        {name: 'status', type: 'string', mapping: 'status'},
193        {name: 'owner', type: 'string', mapping: 'owner'},
194        {name: 'queue', type: 'string', mapping: 'queue'},
195        {name: 'name', type: 'string', mapping: 'name'},
196        {name: 'requested_time', type: 'string', mapping: 'requested_time'},
197        //{name: 'requested_memory', type: 'string', mapping: 'requested_memory'},
198        {name: 'ppn', type: 'int', mapping: 'ppn'},
199        {name: 'nodect', type: 'int', mapping: 'nodect'},
200        {name: 'nodes', type: 'string', mapping: 'nodes'},
201        {name: 'queued_timestamp', type: 'string', mapping: 'queued_timestamp'},
202        {name: 'start_timestamp', type: 'string', mapping: 'start_timestamp'},
203        {name: 'runningtime', type: 'string', mapping: 'runningtime'}
204      ]),
205      sortInfo: {field: 'jid', direction: "ASC"},
206      remoteSort: true
207    });
208   
209  JobsColumnModel = new Ext.grid.ColumnModel(
210    [{
211        header: '#',
212        tooltip: 'Job id',
213        readOnly: true,
214        dataIndex: 'jid',
215        width: 50,
216        hidden: false,
217        renderer: jobCellRender
218      },{
219        header: 'S',
220        tooltip: 'Job status',
221        readOnly: true,
222        dataIndex: 'status',
223        width: 20,
224        hidden: false,
225        renderer: jobCellRender
226      },{
227        header: 'User',
228        tooltip: 'Owner of job',
229        readOnly: true,
230        dataIndex: 'owner',
231        width: 60,
232        hidden: false,
233        renderer: jobCellRender
234      },{
235        header: 'Queue',
236        tooltip: 'In which queue does this job reside',
237        readOnly: true,
238        dataIndex: 'queue',
239        width: 60,
240        hidden: false,
241        renderer: jobCellRender
242      },{
243        header: 'Name',
244        tooltip: 'Name of job',
245        readOnly: true,
246        dataIndex: 'name',
247        width: 100,
248        hidden: false
249      },{
250        header: 'Requested Time',
251        tooltip: 'Amount of requested time (wallclock)',
252        readOnly: true,
253        dataIndex: 'requested_time',
254        width: 100,
255        hidden: false
256      },{
257        header: 'Requested Memory',
258        tooltip: 'Amount of requested memory',
259        readOnly: true,
260        dataIndex: 'requested_memory',
261        width: 100,
262        hidden: true
263      },{
264        header: 'P',
265        tooltip: 'Number of processors per node (PPN)',
266        readOnly: true,
267        dataIndex: 'ppn',
268        width: 25,
269        hidden: false
270      },{
271        header: 'N',
272        tooltip: 'Number of nodes (hosts)',
273        readOnly: true,
274        dataIndex: 'nodect',
275        width: 25,
276        hidden: false
277      },{
278        header: 'Nodes',
279        readOnly: true,
280        dataIndex: 'nodes',
281        width: 100,
282        hidden: true
283      },{
284        header: 'Queued',
285        tooltip: 'At what time did this job enter the queue',
286        readOnly: true,
287        dataIndex: 'queued_timestamp',
288        width: 140,
289        hidden: false
290      },{
291        header: 'Started',
292        tooltip: 'At what time did this job enter the running status',
293        readOnly: true,
294        dataIndex: 'start_timestamp',
295        width: 140,
296        hidden: false
297      },{
298        header: 'Runningtime',
299        tooltip: 'How long has this job been in the running status',
300        readOnly: true,
301        dataIndex: 'runningtime',
302        width: 140,
303        hidden: false
304      }]
305    );
306    JobsColumnModel.defaultSortable= true;
307
308  JobListingEditorGrid =  new Ext.grid.EditorGridPanel({
309      id: 'JobListingEditorGrid',
310      store: JobsDataStore,
311      cm: JobsColumnModel,
312      enableColLock:false,
313      clicksToEdit:1,
314      loadMask: true,
315      selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
316      stripeRows: true,
317      bbar: new Ext.PagingToolbar({
318                pageSize: 30,
319                store: JobsDataStore,
320                displayInfo: true,
321                displayMsg: 'Displaying jobs {0} - {1} out of {2} jobs total found.',
322                emptyMsg: 'No jobs found to display'
323            }),
324      tbar: [ new Ext.app.SearchField({
325                                store: JobsDataStore,
326                                params: {start: 0, limit: 30},
327                                width: 200
328                    })
329      ]
330    });
331
332  ClusterImageWindow = new Ext.Window({
333      id: 'ClusterImageWindow',
334      title: 'Cluster Nodes Overview',
335      closable:true,
336      collapsible: true,
337      animCollapse: true,
338      width:100,
339      height:100,
340      y: 50,
341      plain:true,
342      shadow: true,
343      resizable: false,
344      shadowOffset: 10,
345      layout: 'fit'
346    });
347
348  JobListingWindow = new Ext.Window({
349      id: 'JobListingWindow',
350      title: 'Cluster Jobs Overview',
351      closable:true,
352      collapsible: true,
353      animCollapse: true,
354      maximizable: true,
355      y: 400,
356      width:900,
357      height:500,
358      plain:true,
359      shadow: true,
360      shadowOffset: 10,
361      layout: 'fit',
362      items: JobListingEditorGrid
363    });
364
365  JobListingEditorGrid.addListener( 'cellclick', jobCellClick );
366}
Note: See TracBrowser for help on using the repository browser.