Blame view

js/app/models/ExecutableNode.js 4.74 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/** 
 * Project  : AMDA-NG4
 * Name     : ExecutableNode.js
 * @class   amdaModel.ExecutableNode
 * @extends amdaModel.InteractiveNode
 * @brief   Generic Model of Executable Node
 * @author  elena
 * @version $Id: ExecutableNode.js 1662 2013-07-02 15:10:22Z benjamin $
16035364   Benjamin Renard   First commit
9
10
11
 */

Ext.define('amdaModel.ExecutableNode', {
4078a635   Elena.Budnik   small cleanning up
12
	extend: 'amdaModel.InteractiveNode',
16035364   Benjamin Renard   First commit
13
    
698494ac   Benjamin Renard   Add tooltip for s...
14
	fields: [ 'jobNode', 'resultModel' ],
16035364   Benjamin Renard   First commit
15

4078a635   Elena.Budnik   small cleanning up
16
	statics: { jobTreeLoaded : false },
16035364   Benjamin Renard   First commit
17
    
4078a635   Elena.Budnik   small cleanning up
18
19
20
21
22
23
	constructor : function(config) 
	{
		this.callParent(arguments);        
		this.set('ownerTreeId',amdaUI.ExplorerUI.OPE_TAB.TREE_ID);
		this.set('jobNode', 'amdaModel.BkgJobNode');		 
	},
16035364   Benjamin Renard   First commit
24
    
915d6711   Benjamin Renard   DownloadNode now ...
25
	loadJobTree : function(opts) 
4078a635   Elena.Budnik   small cleanning up
26
27
28
29
30
	{            
		var rootNode = Ext.getCmp(amdaUI.ExplorerUI.JOB_TAB.TREE_ID).getRootNode();	
		var me = this;
		amdaModel.InteractiveNode.preloadNodes(rootNode, function(){
			amdaModel.ExecutableNode.jobTreeLoaded = true;
915d6711   Benjamin Renard   DownloadNode now ...
31
			me.realExecute(opts); 
4078a635   Elena.Budnik   small cleanning up
32
33
		});
	},   
16035364   Benjamin Renard   First commit
34
   
915d6711   Benjamin Renard   DownloadNode now ...
35
	execute : function(opts) 
4078a635   Elena.Budnik   small cleanning up
36
37
	{     
		if (!amdaModel.ExecutableNode.jobTreeLoaded) 
915d6711   Benjamin Renard   DownloadNode now ...
38
			this.loadJobTree(opts);
4078a635   Elena.Budnik   small cleanning up
39
		else 
915d6711   Benjamin Renard   DownloadNode now ...
40
			this.realExecute(opts); 
4078a635   Elena.Budnik   small cleanning up
41
42
43
44
45
	},
   
	/**
	* Method to execute this node 
	*/
915d6711   Benjamin Renard   DownloadNode now ...
46
	realExecute : function(opts) 
4078a635   Elena.Budnik   small cleanning up
47
	{  
27a055f4   Benjamin Renard   Multiplot (#8314)
48
		var isInteractivePlot = (this.get('nodeType') == 'request') && (this.get('object').get('file-output') == 'INTERACTIVE') || (this.get('nodeType') == 'multiplot'); 
915d6711   Benjamin Renard   DownloadNode now ...
49
50
51

		var jsonObject = this.get('object').getJsonValues();
		if (opts && opts.sendToSamp) {
23450317   Benjamin Renard   Restore SAMP
52
53
			jsonObject.sendToSamp = true;
			opts.clientId = opts.clientId ? opts.clientId : 'hub';
915d6711   Benjamin Renard   DownloadNode now ...
54
		}
16035364   Benjamin Renard   First commit
55
       
4078a635   Elena.Budnik   small cleanning up
56
57
		if (!loadMask.isMasked())
			loadMask.show(isInteractivePlot);
16035364   Benjamin Renard   First commit
58
        
915d6711   Benjamin Renard   DownloadNode now ...
59
		AmdaAction.execute({nodeType : this.get('nodeType')}, jsonObject, 
4078a635   Elena.Budnik   small cleanning up
60
61
62
			function(res,e)
			{    
				loadMask.hide();
16035364   Benjamin Renard   First commit
63
	  
4078a635   Elena.Budnik   small cleanning up
64
65
				//AKKA - Rework of the result treatment for the integration with the new kernel
				if (!e.status){
f2b3e0e8   Elena.Budnik   ajax timeout = ga...
66
				//	myDesktopApp.errorMsg('Internal error during request');
4078a635   Elena.Budnik   small cleanning up
67
68
					return;
				}
f2b3e0e8   Elena.Budnik   ajax timeout = ga...
69

4078a635   Elena.Budnik   small cleanning up
70
71
72
73
74
75
76
				if (!res.success){
					myDesktopApp.errorMsg(res.message);
					return;
				}
   
				if (res.killed)
						return;
2cfa3a1a   Benjamin Renard   Give the possibil...
77

4078a635   Elena.Budnik   small cleanning up
78
79
80
81
82
				if (isInteractivePlot){
					myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id, true, function (module) {
						module.updateInteractiveSession(res, true);
					});
				}
23450317   Benjamin Renard   Restore SAMP
83
84
85
				else if (!res.id && res.download) {
					//Download TT / Cat
					if (res.sendToSamp) {
915d6711   Benjamin Renard   DownloadNode now ...
86
87
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
							Ext.Array.each(res.download, function(download) {
23450317   Benjamin Renard   Restore SAMP
88
								module.sendVOTable(download, opts.clientId);
915d6711   Benjamin Renard   DownloadNode now ...
89
90
91
							});
						});
						return;
23450317   Benjamin Renard   Restore SAMP
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
					} else if (res.compression) {					
						window.location.href = res.download;
					}
					else {
						window.open(res.download, '_blank');
					}
					return;
				}
				else {
					if (res.sendToSamp) {
						// Send to SAMP from Download UI
						var files = res.result.split(",");
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
							Ext.each(files, function(file) {
								var href = 'data/'+sessionID+'/RES/'+ res.folder + '/' + file;
								module.sendVOTable(href, opts.clientId);
							});
						});
						return;
					}
915d6711   Benjamin Renard   DownloadNode now ...
112

2cfa3a1a   Benjamin Renard   Give the possibil...
113
114
115
116
					if (logExecTime && res.exectime && (res.exectime != 0)) {
						console.log("CMD EXEC TIME FOR "+res.id+" = "+res.exectime+"ms");
					}

4078a635   Elena.Budnik   small cleanning up
117
118
119
120
121
122
123
124
125
126
127
128
129
130
					var newobj = this.createJobObject(res);	    
					var newNode = Ext.create(this.get('jobNode'), {
							info : res.info,
							jobType : this.get('nodeType'),
							processId : res.id,
							id : res.id,
							text : res.name,
							status : res.status,
							start : res.start,
							stop : res.stop,
							tabId : res.tabId,
							leaf : true,
							object : newobj
						});
16035364   Benjamin Renard   First commit
131
     	    
4078a635   Elena.Budnik   small cleanning up
132
133
					newNode.get('object').on('execute', function() {
							// Then call the node creation method
915d6711   Benjamin Renard   DownloadNode now ...
134
							this.execute(opts);
4078a635   Elena.Budnik   small cleanning up
135
						}, newNode);
16035364   Benjamin Renard   First commit
136
     	    
4078a635   Elena.Budnik   small cleanning up
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
					switch (res.status)
					{
						case amdaModel.BkgJobNode.STATUS_LIST.DONE :
							newNode.createJobNode(true);
							newNode.editNode(true, false);
							break;
						case amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS :
							newNode.createJobNode(false);
							break;
						default:
							newNode.createJobNode(true);
					}
				}
			}, this );
	},  
16035364   Benjamin Renard   First commit
152

4078a635   Elena.Budnik   small cleanning up
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	createJobObject: function(res) 
	{      
		var obj =  this.get('object').getJsonValues();		    
		//TODO text, name, outputName - if all is needed 
		
		//new object to attach to new bkgJobNode	
		//TODO Ext.clone()  		     	  
		var newobj = Ext.copyTo({}, obj, this.get('object').propertiesToCopy);
		newobj.resultId = res.result;	
		newobj.folderId = res.folder;
		newobj.processId= res.id;
		newobj.tabId = res.tabId;
		newobj.name = res.name;
		newobj = Ext.create(this.get('object').$className, newobj);
		
		return   newobj;  
16035364   Benjamin Renard   First commit
169
	},
4078a635   Elena.Budnik   small cleanning up
170
171
172
173
174
175
176
177
	
	/**
	* override isExecutable to return true 
	*/
	isExecutable: function()
	{
		return true;
	}
16035364   Benjamin Renard   First commit
178
});