Blame view

js/app/models/BkgJobNode.js 11.3 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
                    
e511f2cc   elena   stat node
177
			}
6bfa699d   Elena.Budnik   Statistics -> Stats
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
			//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
195
    
29c449bb   Elena.Budnik   format + redmine ...
196
197
		getObjectCallback : function(result,remoteEvent){
			var t = remoteEvent.getTransaction();        
6bfa699d   Elena.Budnik   Statistics -> Stats
198
			//AKKA - Rework of the result treatment for the integration with the new kernel
29c449bb   Elena.Budnik   format + redmine ...
199
			if (!remoteEvent.status) {
6bfa699d   Elena.Budnik   Statistics -> Stats
200
201
202
				myDesktopApp.errorMsg('Internal error during download request');
				return;
			}
16035364   Benjamin Renard   First commit
203
 	   	
29c449bb   Elena.Budnik   format + redmine ...
204
			if (!result.success) {
6bfa699d   Elena.Budnik   Statistics -> Stats
205
206
207
				myDesktopApp.errorMsg(result.message);
				return;
			}
16035364   Benjamin Renard   First commit
208
        
6bfa699d   Elena.Budnik   Statistics -> Stats
209
			var obj = null;
29c449bb   Elena.Budnik   format + redmine ...
210
211
			
			switch (this.get('jobType')) {
6bfa699d   Elena.Budnik   Statistics -> Stats
212
213
214
215
216
217
				case 'condition' : 
					obj = Ext.create('amdaModel.Search',
							{name: result.name,
							resultId : result.result,
							folderId : result.folder});
					break;
2e7079bb   Benjamin Renard   First implementat...
218
219
				case 'statistic' : 
					obj = Ext.create('amdaModel.Statistic',
6bfa699d   Elena.Budnik   Statistics -> Stats
220
221
222
223
224
							{name: result.name,
							resultId : result.result,
							folderId : result.folder});
					break;
				case 'request' : 
29c449bb   Elena.Budnik   format + redmine ...
225
					obj = Ext.create('amdaPlotObj.PlotRequestObject',
6bfa699d   Elena.Budnik   Statistics -> Stats
226
227
228
229
230
231
232
233
234
235
236
237
							{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
238
        	
29c449bb   Elena.Budnik   format + redmine ...
239
			if (!obj){
6bfa699d   Elena.Budnik   Statistics -> Stats
240
241
				myDesktopApp.errorMsg("Unknown job type");
				return;
29c449bb   Elena.Budnik   format + redmine ...
242
			}
16035364   Benjamin Renard   First commit
243
        
6bfa699d   Elena.Budnik   Statistics -> Stats
244
245
			// set parameter into node
			this.set('object',obj);
16035364   Benjamin Renard   First commit
246
        
6bfa699d   Elena.Budnik   Statistics -> Stats
247
			var isInteractive = false;
29c449bb   Elena.Budnik   format + redmine ...
248
249
			var isNewTab = true;
			
6bfa699d   Elena.Budnik   Statistics -> Stats
250
251
			this.editNode(isNewTab, isInteractive);	   
		},
16035364   Benjamin Renard   First commit
252
 
6bfa699d   Elena.Budnik   Statistics -> Stats
253
		// Show Result 
29c449bb   Elena.Budnik   format + redmine ...
254
		editNode : function(isNewTab, isInteractive) {
6bfa699d   Elena.Budnik   Statistics -> Stats
255
			var me = this;
29c449bb   Elena.Budnik   format + redmine ...
256
			if (isInteractive) {
6bfa699d   Elena.Budnik   Statistics -> Stats
257
258
259
260
261
262
263
264
265
266
				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 ...
267
268
269
					if (isNewTab) {	
						module.setLinkedNode(me);
					}
6bfa699d   Elena.Budnik   Statistics -> Stats
270
271
272
273
					module.createWindow();
				});
			}
		},
16035364   Benjamin Renard   First commit
274
  
0b736ee7   Furkan   #9915 - Bug fixed
275
		createJobNode: function(isResult, start)
6bfa699d   Elena.Budnik   Statistics -> Stats
276
277
278
279
280
281
282
		{       
			// 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
283
        
6bfa699d   Elena.Budnik   Statistics -> Stats
284
285
286
287
288
289
290
			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
291
        
6bfa699d   Elena.Budnik   Statistics -> Stats
292
293
294
295
296
297
298
299
300
301
302
303
304
305
			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
306
                
6bfa699d   Elena.Budnik   Statistics -> Stats
307
308
309
310
311
312
313
314
			// 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...
315
					case 'statistic' : var type = 'Statistics '; break;
6bfa699d   Elena.Budnik   Statistics -> Stats
316
317
318
					default: var type = 'unknown';    
				}
				myDesktopApp.infoMsg('Your request is still running and has been assigned the name '+this.get('text')+' -- Check Jobs in Progress');
0b736ee7   Furkan   #9915 - Bug fixed
319
				var message = Ext.Date.format(new Date(start), 'Y-m-d H:i:s: ')+ type + ' '+this.get('text')+ ' created';
6bfa699d   Elena.Budnik   Statistics -> Stats
320
321
322
				myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id, true, function (module) {
					module.addLogMessage(message);
				});
16035364   Benjamin Renard   First commit
323
	    
6bfa699d   Elena.Budnik   Statistics -> Stats
324
325
326
327
328
329
330
331
332
333
334
				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
335
    
6bfa699d   Elena.Budnik   Statistics -> Stats
336
337
338
339
340
341
342
343
344
345
346
347
348
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
		//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 ...
385
		}
16035364   Benjamin Renard   First commit
386
});