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

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

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

  • some window repositioning

job_monarch/conf.php:

  • remove DDD from dateformat
File size: 9.9 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    delete myparams['host'];
97  }
98
99  reloadClusterImage();
100  reloadJobStore();
101
102  return false;
103}
104
105function reloadJobStore()
106{
107  // Respect any other parameters that may have been set outside filters
108  //
109  myparams = joinMyArray( myparams, myfilters );
110
111  // Can't be sure if there are enough pages for new filter: reset to page 1
112  //
113  myparams = joinMyArray( myparams, { start: 0, limit: 30 } );
114
115  JobsDataStore.reload( { params: myparams } );
116}
117
118function addListener(element, type, expression, bubbling)
119{
120  bubbling = bubbling || false;
121  if(window.addEventListener)   { // Standard
122    element.addEventListener(type, expression, bubbling);
123    return true;
124  } else if(window.attachEvent) { // IE
125    element.attachEvent('on' + type, expression);
126    return true;
127  } else return false;
128}
129
130var ImageLoader = function( id, url )
131{
132  this.url = url;
133  this.image = document.getElementById( id );
134  this.loadEvent = null;
135};
136
137ImageLoader.prototype = {
138  load:function(){
139    var url = this.url;
140    var image = this.image;
141    var loadEvent = this.loadEvent;
142    addListener(this.image, 'load', function(e){
143      if(loadEvent != null){
144        loadEvent(url, image);
145      }
146    }, false);
147    this.image.src = this.url;
148  },
149  getImage:function(){
150    return this.image;
151  }
152};
153
154function reloadClusterImage()
155{
156  ClusterImageArgs['view'] = 'big-clusterimage';
157
158  filt_url = makeArrayURL( myfilters );
159  imag_url = makeArrayURL( ClusterImageArgs );
160  img_url = './image.php?' + filt_url + '&' + imag_url;
161
162  var newClusterImage = new ImageLoader( 'clusterimage', img_url );
163  newClusterImage.loadEvent = function( url, image ) {ClusterImageWindow.getBottomToolbar().clearStatus({useDefaults:true});}
164
165  ClusterImageWindow.getBottomToolbar().showBusy();
166  newClusterImage.load();
167}
168
169function initJobGrid() {
170
171  Ext.QuickTips.init();
172
173  function jobCellClick(grid, rowIndex, columnIndex, e)
174  {
175    var record = grid.getStore().getAt(rowIndex);  // Get the Record
176    var fieldName = grid.getColumnModel().getDataIndex(columnIndex);
177    var data = record.get(fieldName);
178    var view = grid.getView();
179    var cell = view.getCell( rowIndex, columnIndex );
180
181    if( fieldName == 'owner' || fieldName == 'jid' || fieldName == 'status' || fieldName == 'queue' )
182    {
183      if( inMyArrayKeys( myfilters, fieldName ) )
184      {
185        Ext.fly(cell).removeClass( 'filterenabled' );
186        Ext.fly(cell).addClass( 'filter' );
187
188        // Remove this filter
189        //
190        delete myfilters[fieldName];
191        delete myparams[fieldName];
192
193        reloadJobStore();
194        reloadClusterImage();
195      }
196      else
197      {
198        Ext.fly(cell).removeClass( 'filter' );
199        Ext.fly(cell).addClass( 'filterenabled' );
200
201        // Set filter for selected column to selected cell value
202        //
203        myfilters[fieldName] = data;
204
205        reloadJobStore();
206        reloadClusterImage();
207      }
208    }
209  }
210
211  function jobCellRender( value, metadata, record, rowindex, colindex, store )
212  {
213    var fieldName = JobsColumnModel.getColumnById( colindex ).dataIndex;
214
215    if( fieldName == 'owner' || fieldName == 'jid' || fieldName == 'status' || fieldName == 'queue' )
216    {
217      if( myfilters[fieldName] != null )
218      {
219        metadata.css = 'filterenabled';
220      }
221      else
222      {
223        metadata.css = 'filter';
224      }
225    }
226    return value;
227  }
228
229  JobProxy = new Ext.data.HttpProxy({
230                url: 'jobstore.php',
231                method: 'POST'
232            });
233
234  JobsDataStore = new Ext.data.Store({
235      id: 'JobsDataStore',
236      proxy: JobProxy,
237      baseParams:{task: "LISTING"}, // this parameter is passed for any HTTP request
238      reader: new Ext.data.JsonReader({
239        root: 'results',
240        totalProperty: 'total',
241        id: 'id'
242      },[
243        {name: 'jid', type: 'int', mapping: 'jid'},
244        {name: 'status', type: 'string', mapping: 'status'},
245        {name: 'owner', type: 'string', mapping: 'owner'},
246        {name: 'queue', type: 'string', mapping: 'queue'},
247        {name: 'name', type: 'string', mapping: 'name'},
248        {name: 'requested_time', type: 'string', mapping: 'requested_time'},
249        //{name: 'requested_memory', type: 'string', mapping: 'requested_memory'},
250        {name: 'ppn', type: 'int', mapping: 'ppn'},
251        {name: 'nodect', type: 'int', mapping: 'nodect'},
252        {name: 'nodes', type: 'string', mapping: 'nodes'},
253        {name: 'queued_timestamp', type: 'string', mapping: 'queued_timestamp'},
254        {name: 'start_timestamp', type: 'string', mapping: 'start_timestamp'},
255        {name: 'runningtime', type: 'string', mapping: 'runningtime'}
256      ]),
257      sortInfo: {field: 'jid', direction: "ASC"},
258      remoteSort: true
259    });
260   
261  JobsColumnModel = new Ext.grid.ColumnModel(
262    [{
263        header: '#',
264        tooltip: 'Job id',
265        readOnly: true,
266        dataIndex: 'jid',
267        width: 50,
268        hidden: false,
269        renderer: jobCellRender
270      },{
271        header: 'S',
272        tooltip: 'Job status',
273        readOnly: true,
274        dataIndex: 'status',
275        width: 20,
276        hidden: false,
277        renderer: jobCellRender
278      },{
279        header: 'User',
280        tooltip: 'Owner of job',
281        readOnly: true,
282        dataIndex: 'owner',
283        width: 60,
284        hidden: false,
285        renderer: jobCellRender
286      },{
287        header: 'Queue',
288        tooltip: 'In which queue does this job reside',
289        readOnly: true,
290        dataIndex: 'queue',
291        width: 60,
292        hidden: false,
293        renderer: jobCellRender
294      },{
295        header: 'Name',
296        tooltip: 'Name of job',
297        readOnly: true,
298        dataIndex: 'name',
299        width: 100,
300        hidden: false
301      },{
302        header: 'Requested Time',
303        tooltip: 'Amount of requested time (wallclock)',
304        readOnly: true,
305        dataIndex: 'requested_time',
306        width: 100,
307        hidden: false
308      },{
309        header: 'Requested Memory',
310        tooltip: 'Amount of requested memory',
311        readOnly: true,
312        dataIndex: 'requested_memory',
313        width: 100,
314        hidden: true
315      },{
316        header: 'P',
317        tooltip: 'Number of processors per node (PPN)',
318        readOnly: true,
319        dataIndex: 'ppn',
320        width: 25,
321        hidden: false
322      },{
323        header: 'N',
324        tooltip: 'Number of nodes (hosts)',
325        readOnly: true,
326        dataIndex: 'nodect',
327        width: 25,
328        hidden: false
329      },{
330        header: 'Nodes',
331        readOnly: true,
332        dataIndex: 'nodes',
333        width: 100,
334        hidden: true
335      },{
336        header: 'Queued',
337        tooltip: 'At what time did this job enter the queue',
338        readOnly: true,
339        dataIndex: 'queued_timestamp',
340        width: 120,
341        hidden: false
342      },{
343        header: 'Started',
344        tooltip: 'At what time did this job enter the running status',
345        readOnly: true,
346        dataIndex: 'start_timestamp',
347        width: 120,
348        hidden: false
349      },{
350        header: 'Runningtime',
351        tooltip: 'How long has this job been in the running status',
352        readOnly: true,
353        dataIndex: 'runningtime',
354        width: 140,
355        hidden: false
356      }]
357    );
358    JobsColumnModel.defaultSortable= true;
359
360  JobListingEditorGrid =  new Ext.grid.EditorGridPanel({
361      id: 'JobListingEditorGrid',
362      store: JobsDataStore,
363      cm: JobsColumnModel,
364      enableColLock:false,
365      clicksToEdit:1,
366      loadMask: true,
367      selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
368      stripeRows: true,
369      bbar: new Ext.PagingToolbar({
370                pageSize: 30,
371                store: JobsDataStore,
372                displayInfo: true,
373                displayMsg: 'Displaying jobs {0} - {1} out of {2} jobs total found.',
374                emptyMsg: 'No jobs found to display'
375            }),
376      tbar: [ new Ext.app.SearchField({
377                                store: JobsDataStore,
378                                params: {start: 0, limit: 30},
379                                width: 200
380                    })
381      ]
382    });
383
384  ClusterImageWindow = new Ext.Window({
385      id: 'ClusterImageWindow',
386      title: 'Cluster Nodes Overview',
387      closable:true,
388      collapsible: true,
389      animCollapse: true,
390      width:100,
391      height:100,
392      y: 15,
393      plain:true,
394      shadow: true,
395      resizable: false,
396      shadowOffset: 10,
397      layout: 'fit',
398      bbar: new Ext.StatusBar({
399                defaultText: 'Ready.',
400                id: 'basic-statusbar',
401                defaultIconCls: ''
402        })
403
404    });
405
406  JobListingWindow = new Ext.Window({
407      id: 'JobListingWindow',
408      title: 'Cluster Jobs Overview',
409      closable:true,
410      collapsible: true,
411      animCollapse: true,
412      maximizable: true,
413      y: 375,
414      width:860,
415      height:500,
416      plain:true,
417      shadow: true,
418      shadowOffset: 10,
419      layout: 'fit',
420      items: JobListingEditorGrid
421    });
422
423  JobListingEditorGrid.addListener( 'cellclick', jobCellClick );
424}
Note: See TracBrowser for help on using the repository browser.