Blame view

js/app/models/BkgJobNode.js 11.9 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/** 
 * Project  : AMDA-NG4
 * Name     : BkgJobNode.js
 * @class   amdaModel.BkgJobNode
 * @extends amdaModel.AmdaNode
 * @brief   Basic Model of Node corresponding to Amda processes in background
 * @author  elena
 * @version $Id: BkgJobNode.js 1963 2013-12-06 17:50:37Z elena $
16035364   Benjamin Renard   First commit
9
10
11
 */

Ext.define('amdaModel.BkgJobNode', {
6bfa699d   Elena.Budnik   Statistics -> Stats
12
		extend: 'amdaModel.ExecutableNode',		
6bfa699d   Elena.Budnik   Statistics -> Stats
13
		action : null,
16035364   Benjamin Renard   First commit
14
    
6bfa699d   Elena.Budnik   Statistics -> Stats
15
16
17
18
19
20
		statics: {       	 	 
			nodeType: 'bkgWorks',
			JOB_TYPES: {
				PLOT: 'request',//'plot',
				CONDITION: 'condition',
				DOWNLOAD: 'download',
2e7079bb   Benjamin Renard   First implementat...
21
				STATISTICS: 'statistic'
6bfa699d   Elena.Budnik   Statistics -> Stats
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
			},
			JOB_ROOT_NODE: {
				PLOT: 'bkgPlot-treeRootNode',
				CONDITION: 'bkgSearch-treeRootNode',
				DOWNLOAD: 'bkgDown-treeRootNode',
				STATISTICS: 'bkgStatistics-treeRootNode'
			},
			RES_ROOT_NODE: {
				PLOT: 'resPlot-treeRootNode',
				CONDITION: 'resSearch-treeRootNode',
				DOWNLOAD:  'resDown-treeRootNode',
				STATISTICS: 'resStatistics-treeRootNode'
			},
			STATUS_LIST: {
				IN_PROGRESS: 'in_progress',
				DONE: 'done',
				ERROR: 'error' 
			}	                     
		},
		fields: [ 
a038d0e2   Elena.Budnik   redmine #5687
42
			// name, id, moduleId, object > from parent 
6bfa699d   Elena.Budnik   Statistics -> Stats
43
44
45
46
47
48
49
50
51
52
53
			{ name : 'jobType', type : 'string' },
			{ name : 'processId', type : 'string' },
			{ name : 'status', type : 'string' },
			{ name : 'percentDone', type : 'string', defaultValue : '0' },
			{ name : 'start', type: 'date' },
			// { name : 'duration', type: 'int' , defaultValue: -1}
			{ name : 'stop', type: 'date', defaultValue: null },
			{ name : 'rawname', type: 'string'},
			{ name : 'tabId', type: 'string'},
			{ name : 'info', type: 'string'}
		],
16035364   Benjamin Renard   First commit
54

6bfa699d   Elena.Budnik   Statistics -> Stats
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
		constructor : function(config)
		{  
			this.callParent(arguments);
			this.set('ownerTreeId', amdaUI.ExplorerUI.JOB_TAB.TREE_ID);   
			
			if (this.isLeaf()) 
			{
				switch (this.get('status')) 
				{
					case amdaModel.BkgJobNode.STATUS_LIST.ERROR: 
						//     this.set('status' ,amdaModel.BkgJobNode.STATUS_LIST.ERROR);
						this.set('iconCls','icon-error'); 
						break;             
					case amdaModel.BkgJobNode.STATUS_LIST.DONE:
						// set status
a038d0e2   Elena.Budnik   redmine #5687
70
						// this.set('status',amdaModel.BkgJobNode.STATUS_LIST.DONE);              
6bfa699d   Elena.Budnik   Statistics -> Stats
71
72
73
74
75
76
77
78
						this.set('iconCls','icon-done');
						break;          
					default : 
						this.set('percentDone',this.get('status')); 
						this.set('status',amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS);		  
						this.set('iconCls','icon-pend');			      
				}
				
a038d0e2   Elena.Budnik   redmine #5687
79
80
81
				if (!this.get('processId') && this.get('id'))
					this.set('processId', this.get('id'));
				
6bfa699d   Elena.Budnik   Statistics -> Stats
82
83
84
85
				if (config) this.set('jobType', config.jobType);
				else this.set('jobType',this.get('jobType'));
			}     
		},
16035364   Benjamin Renard   First commit
86
  
6bfa699d   Elena.Budnik   Statistics -> Stats
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
		getAllContextMenuItems: function()
		{
			if (this.get('status') == amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS)       
				return [
				{
					fnId : 'leaf-deleteNode',
					text : 'Stop/Delete Job'
				}/*, {
					fnId : 'leaf-showNode',
					text : 'Show Job Details'
				}, {
					fnId : 'leaf-renameNode',
					text : 'Rename Job'   
				}*/];
			else
				return [{
					fnId : 'leaf-editNode',
					text : 'Show Result' 
				},{
					fnId : 'leaf-deleteNode',
					text : 'Delete Result'
				}/*, {
					fnId : 'leaf-renameNode',
					text : 'Rename Result' 
				}*/];		
		},
16035364   Benjamin Renard   First commit
113

6bfa699d   Elena.Budnik   Statistics -> Stats
114
115
116
117
118
119
120
		getMultiContextMenuItems: function()
		{
			return [{
				fnId : 'mult-deleteMulti',
				text : 'Delete Results'
			}];
		},
16035364   Benjamin Renard   First commit
121
        
6bfa699d   Elena.Budnik   Statistics -> Stats
122
123
124
		onMenuItemClick : function(menu, item, event) 
		{
			var fnId = Ext.util.Format.substr(item.fnId, 5, item.fnId.length);
29c449bb   Elena.Budnik   format + redmine ...
125
126
         
			switch (fnId) {
6bfa699d   Elena.Budnik   Statistics -> Stats
127
128
129
130
131
132
133
134
135
136
137
138
139
				case 'deleteNode':      
					this.deleteJob();
					this.deleteNode();  
					break;					
				case 'showNode':  
					//alert('Show details pid ' + this.get('pid')); 
					alert('NOT IMPLEMENTED YET');
					break;    	
				case 'renameNode':  
					// alert('rename pid ' + this.get('pid')); 
					alert('NOT IMPLEMENTED YET');
					// this.renameNode(); 
					break; 						
29c449bb   Elena.Budnik   format + redmine ...
140
141
142
143
				case 'editNode':   
					// create object if it doesn't exist (tree load)	  
					// TODO use data model ?  	
					if (!this.get('object')) {
6bfa699d   Elena.Budnik   Statistics -> Stats
144
						AmdaAction.getObject(this.get('id'), this.get('nodeType'), this.getObjectCallback, this);		  
29c449bb   Elena.Budnik   format + redmine ...
145
146
					}
					else {
6bfa699d   Elena.Budnik   Statistics -> Stats
147
						var isInteractive = false;
29c449bb   Elena.Budnik   format + redmine ...
148
						var isNewTab = true;
6bfa699d   Elena.Budnik   Statistics -> Stats
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
						this.editNode(isNewTab, isInteractive);
					}
					break; 	        
				case 'deleteMulti':							
					var selectedNodes = this.myGetOwnerTree().getSelectionModel().selected.items;
					if (selectedNodes.length > 0) 
					{
						Ext.Array.each(selectedNodes,function(item, index){
								item.deleteJob();
								item.deleteNode();
						});
					}
					break;            
				default:
					break;
			}   
		},
16035364   Benjamin Renard   First commit
166
        
6bfa699d   Elena.Budnik   Statistics -> Stats
167
168
169
170
171
172
173
174
175
		deleteJob :  function() 
		{
			if (this.get('status') == amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS) 
			{
				amdaDesktop.JobsMgr.jobsInProgress--;          
				if (amdaDesktop.JobsMgr.jobsInProgress == 0 && amdaDesktop.JobsMgr.updateStatus)                      
					Ext.TaskManager.stop(amdaDesktop.JobsMgr.updateStatus);
				
				amdaDesktop.JobsMgr.updateStatus = null;
16035364   Benjamin Renard   First commit
176
                    
6bfa699d   Elena.Budnik   Statistics -> Stats
177
178
179
180
181
				switch (this.get('jobType')) 
				{
					case 'condition' : var type = 'Data Mining '; break;
					case 'request' : var type = 'Plot '; break;   
					case 'download' : var type = 'Download '; break;
2e7079bb   Benjamin Renard   First implementat...
182
					case 'statistic' : var type = 'Statistics '; break;
6bfa699d   Elena.Budnik   Statistics -> Stats
183
184
185
186
187
188
189
					default: var type = 'unknown';    
				}
				
				var message = Ext.Date.format(new Date(), 'd-m-Y H:i:s: ') + ': '+ type + ' '+this.get('text') + ' killed';
				myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id, true, function (module) {
					module.addLogMessage(message); 
				});
e511f2cc   elena   stat node
190
			}
6bfa699d   Elena.Budnik   Statistics -> Stats
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
			//delete fieldset from Result Module if it is open       
			else {
				var me = this;
				myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id, true, function (module) {
					if (module && module.linkedNodes) 
					{                 
						module.linkedNodes.each(function(item, index)
						{                     
							if (me.get('id') == item.get('id')) {                 
									module.removeLinkedNode(item, index);
									return false;
							}
						}, this);                      
					}
				});
			} 
		},	
16035364   Benjamin Renard   First commit
208
    
29c449bb   Elena.Budnik   format + redmine ...
209
210
		getObjectCallback : function(result,remoteEvent){
			var t = remoteEvent.getTransaction();        
6bfa699d   Elena.Budnik   Statistics -> Stats
211
			//AKKA - Rework of the result treatment for the integration with the new kernel
29c449bb   Elena.Budnik   format + redmine ...
212
			if (!remoteEvent.status) {
6bfa699d   Elena.Budnik   Statistics -> Stats
213
214
215
				myDesktopApp.errorMsg('Internal error during download request');
				return;
			}
16035364   Benjamin Renard   First commit
216
 	   	
29c449bb   Elena.Budnik   format + redmine ...
217
			if (!result.success) {
6bfa699d   Elena.Budnik   Statistics -> Stats
218
219
220
				myDesktopApp.errorMsg(result.message);
				return;
			}
16035364   Benjamin Renard   First commit
221
        
6bfa699d   Elena.Budnik   Statistics -> Stats
222
			var obj = null;
29c449bb   Elena.Budnik   format + redmine ...
223
224
			
			switch (this.get('jobType')) {
6bfa699d   Elena.Budnik   Statistics -> Stats
225
226
227
228
229
230
				case 'condition' : 
					obj = Ext.create('amdaModel.Search',
							{name: result.name,
							resultId : result.result,
							folderId : result.folder});
					break;
2e7079bb   Benjamin Renard   First implementat...
231
232
				case 'statistic' : 
					obj = Ext.create('amdaModel.Statistic',
6bfa699d   Elena.Budnik   Statistics -> Stats
233
234
235
236
237
							{name: result.name,
							resultId : result.result,
							folderId : result.folder});
					break;
				case 'request' : 
29c449bb   Elena.Budnik   format + redmine ...
238
					obj = Ext.create('amdaPlotObj.PlotRequestObject',
6bfa699d   Elena.Budnik   Statistics -> Stats
239
240
241
242
243
244
245
246
247
248
249
250
							{name: result.name, format: result.format,
							resultId : result.result,
							folderId : result.folder}); 
					break;   
				case 'download' : 
					obj = Ext.create('amdaModel.Download',
							{name: result.name,
							compression: result.compression,
							resultId : result.result,
							folderId : result.folder}); 
					break;
			}
16035364   Benjamin Renard   First commit
251
        	
29c449bb   Elena.Budnik   format + redmine ...
252
			if (!obj){
6bfa699d   Elena.Budnik   Statistics -> Stats
253
254
				myDesktopApp.errorMsg("Unknown job type");
				return;
29c449bb   Elena.Budnik   format + redmine ...
255
			}
16035364   Benjamin Renard   First commit
256
        
6bfa699d   Elena.Budnik   Statistics -> Stats
257
258
			// set parameter into node
			this.set('object',obj);
16035364   Benjamin Renard   First commit
259
        
6bfa699d   Elena.Budnik   Statistics -> Stats
260
			var isInteractive = false;
29c449bb   Elena.Budnik   format + redmine ...
261
262
			var isNewTab = true;
			
6bfa699d   Elena.Budnik   Statistics -> Stats
263
264
			this.editNode(isNewTab, isInteractive);	   
		},
16035364   Benjamin Renard   First commit
265
 
6bfa699d   Elena.Budnik   Statistics -> Stats
266
		// Show Result 
29c449bb   Elena.Budnik   format + redmine ...
267
		editNode : function(isNewTab, isInteractive) {
6bfa699d   Elena.Budnik   Statistics -> Stats
268
			var me = this;
29c449bb   Elena.Budnik   format + redmine ...
269
			if (isInteractive) {
6bfa699d   Elena.Budnik   Statistics -> Stats
270
271
272
273
274
275
276
277
278
279
				myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id, true, function(module) {
					if (isNewTab) {	 
						module.setLinkedNode(me); 
					}	
					module.createWindow();
				});
			}
			else 
			{
				myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id, true, function(module) {
29c449bb   Elena.Budnik   format + redmine ...
280
281
282
					if (isNewTab) {	
						module.setLinkedNode(me);
					}
6bfa699d   Elena.Budnik   Statistics -> Stats
283
284
285
286
					module.createWindow();
				});
			}
		},
16035364   Benjamin Renard   First commit
287
  
6bfa699d   Elena.Budnik   Statistics -> Stats
288
289
290
291
292
293
294
295
		createJobNode: function(isResult)
		{       
			// if ownerTree panel is not active
			if (this.myGetOwnerTree().ownerCt.getActiveTab() !== this.myGetOwnerTree()) {
				// set ownerTree panel as the active tab
				this.myGetOwnerTree().ownerCt.setActiveTab(this.myGetOwnerTree());
				// to enable selection of this node his ownerTree must have a view
			}
16035364   Benjamin Renard   First commit
296
        
6bfa699d   Elena.Budnik   Statistics -> Stats
297
298
299
300
301
302
303
			var rootNode = this.getRootNode(isResult);
			// expand the corresponding rootNode
			if (rootNode.parentNode) {
				if (!rootNode.parentNode.isExpanded()) {
					rootNode.parentNode.expand(false);
				}
			}  
16035364   Benjamin Renard   First commit
304
        
6bfa699d   Elena.Budnik   Statistics -> Stats
305
306
307
308
309
310
311
312
313
314
315
316
317
318
			if (!rootNode.isExpanded())  {                                                        
				rootNode.expand(false, function(){
					if (!this.parentNode) {
						nodeFantom = rootNode.findChild('id',this.get('id'));  
						if (nodeFantom) {                                    
							nodeFantom.remove();
							rootNode.appendChild(this);
						}
					}                        
				}, this);                                                        
			}
			else {                
				rootNode.appendChild(this);
			}                                                                                                   
16035364   Benjamin Renard   First commit
319
                
6bfa699d   Elena.Budnik   Statistics -> Stats
320
321
322
323
324
325
326
327
			// select the new node                  
			this.myGetOwnerTree().getSelectionModel().select(this);
			if (!isResult)
			{
				switch (this.get('jobType')) {
					case 'condition' : var type = 'Data Mining '; break;
					case 'request' : var type = 'Plot '; break;   
					case 'download' : var type = 'Download '; break;
2e7079bb   Benjamin Renard   First implementat...
328
					case 'statistic' : var type = 'Statistics '; break;
6bfa699d   Elena.Budnik   Statistics -> Stats
329
330
331
332
333
334
335
					default: var type = 'unknown';    
				}
				myDesktopApp.infoMsg('Your request is still running and has been assigned the name '+this.get('text')+' -- Check Jobs in Progress');
				var message = Ext.Date.format(new Date(), 'd-m-Y H:i:s: ')+ type + ' '+this.get('text')+ ' created';
				myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id, true, function (module) {
					module.addLogMessage(message);
				});
16035364   Benjamin Renard   First commit
336
	    
6bfa699d   Elena.Budnik   Statistics -> Stats
337
338
339
340
341
342
343
344
345
346
347
				amdaDesktop.JobsMgr.jobsInProgress++;          	 
				if (!amdaDesktop.JobsMgr.updateStatus)
				{
					amdaDesktop.JobsMgr.updateStatus =  
						Ext.TaskManager.start({
							run : amdaDesktop.JobsMgr.getStatus,
							interval : amdaDesktop.JobsMgr.interval 
						});
				}
			}
		},
16035364   Benjamin Renard   First commit
348
    
6bfa699d   Elena.Budnik   Statistics -> Stats
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
		//override amdaModel.AmdaNode.getRootNode method
		getRootNode: function(isResult)
		{    
			if (!this.get('rootNode'))
			{
				var rootNodeId;
				if (!isResult) 
				{
					switch(this.get('jobType'))
					{
						case amdaModel.BkgJobNode.JOB_TYPES.PLOT:		   
							rootNodeId = amdaModel.BkgJobNode.JOB_ROOT_NODE.PLOT;
						break;
						case amdaModel.BkgJobNode.JOB_TYPES.CONDITION:		   
							rootNodeId = amdaModel.BkgJobNode.JOB_ROOT_NODE.CONDITION;
						break;
						case amdaModel.BkgJobNode.JOB_TYPES.DOWNLOAD:		    
							rootNodeId = amdaModel.BkgJobNode.JOB_ROOT_NODE.DOWNLOAD;
						break;
						case amdaModel.BkgJobNode.JOB_TYPES.STATISTICS:                   
							rootNodeId = amdaModel.BkgJobNode.JOB_ROOT_NODE.STATISTICS;
						break;
						default:
						break;
					}
				}
				else 
				{
					switch(this.get('jobType'))
					{
						case amdaModel.BkgJobNode.JOB_TYPES.PLOT:		   
							rootNodeId = amdaModel.BkgJobNode.RES_ROOT_NODE.PLOT;
						break;
						case amdaModel.BkgJobNode.JOB_TYPES.CONDITION:		   
							rootNodeId = amdaModel.BkgJobNode.RES_ROOT_NODE.CONDITION;
						break;
						case amdaModel.BkgJobNode.JOB_TYPES.DOWNLOAD:		    
							rootNodeId = amdaModel.BkgJobNode.RES_ROOT_NODE.DOWNLOAD;
						break;
						case amdaModel.BkgJobNode.JOB_TYPES.STATISTICS:                   
							rootNodeId = amdaModel.BkgJobNode.RES_ROOT_NODE.STATISTICS;
						break;
						default:
						break;
					}
				} 
				this.set('rootNode',this.myGetOwnerTree().getRootNode().findChild( 'id', rootNodeId, true));
			}
			return this.get('rootNode');
915d6711   Benjamin Renard   DownloadNode now ...
398
		}
16035364   Benjamin Renard   First commit
399
});