Blame view

js/app/models/DownloadNode.js 8.68 KB
16035364   Benjamin Renard   First commit
1
2
3
4
/** 
 * Project  : AMDA-NG4
 * Name     : DownloadNode.js
 * @class   amdaModel.DownloadNode
fdf1413b   Elena.Budnik   TT download
5
 * @extends Ext.data.Model
16035364   Benjamin Renard   First commit
6
7
 * @brief   Basic Model of Node corresponding to a download request
 * @author  Myriam
aa94fd24   elena   Merge with last svn
8
 * @version $Id: DownloadNode.js 2949 2015-06-23 10:25:59Z elena $
16035364   Benjamin Renard   First commit
9
 */
fdf1413b   Elena.Budnik   TT download
10

16035364   Benjamin Renard   First commit
11
12
Ext.define('amdaModel.DownloadNode', {

fdf1413b   Elena.Budnik   TT download
13
14
	extend: 'Ext.data.Model',	
	singleton: true,
16035364   Benjamin Renard   First commit
15
        
3a5f60a1   elena   proper use os sta...
16
17
18
19
20
21
22
23
	fields:[{name : 'downloadType', type : 'string'},
		{name: 'object', type: 'object'},
		{name: 'realLinkedNode', type: 'amdaModel.AmdaNode'},
		{name: 'moduleId', type: 'string', defaultValue:'down-win'},
		{name: 'nodeType', type: 'string', defaultValue: 'download'},
		{name: 'objectDataModel', type: 'string', defaultValue:'amdaModel.Download'},
		{name: 'jobNode', type: 'string', defaultValue: 'amdaModel.BkgJobNode'}
	], 
16035364   Benjamin Renard   First commit
24
    
fdf1413b   Elena.Budnik   TT download
25
26
27
	isExecutable: function(){
		return true;
	},
16035364   Benjamin Renard   First commit
28
      
fdf1413b   Elena.Budnik   TT download
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
	getObjectCallback : function(result,remoteEvent){  
		var t = remoteEvent.getTransaction();
		if (result) {            
			var paramObj = Ext.create(this.get('objectDataModel'), result);
			// set parameter into node
			this.set('object', paramObj);
			var downObject = amdaModel.DownloadNode.decodeObject();
			// Edition	 ;
			amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject));
			amdaModel.DownloadNode.editInModule();              
		} 
		else {
			myDesktopApp.errorMsg(t.action + "." + t.method + " : No parameter '"
				+this.get('name')+"' found!");
			 // EXCEPTION : parameter not found !?			 
		}
	},
16035364   Benjamin Renard   First commit
46
      
fdf1413b   Elena.Budnik   TT download
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	editInModule : function () {
		var me = this;
		myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
			// If the node to edit is not already linked to this module
			if (module.getLinkedNode() != me) {
				// set relative node into parameter Module
				module.setLinkedNode(me);        	
			}
			else {// the node to edit is already edited
				//TODO: TBD : message to user
				//Sol1: msg alert: "warning this node is already edited! If you want to get the original, please press the 'reset' button"->'OK'
				//Sol2: msg with user choice: "warning this node is already edited! Would you confirm this action and lost your modification?"->'Confirm','Cancel'
			}
			// Opening parameter window         
			module.createWindow();
		});
	},
16035364   Benjamin Renard   First commit
64
    
fdf1413b   Elena.Budnik   TT download
65
	decodeObject: function(obj) {
27504b3e   Elena.Budnik   redmine 5080
66
		var myValues  = new Object(); 		
fdf1413b   Elena.Budnik   TT download
67
		myValues.list=[];
fdf1413b   Elena.Budnik   TT download
68
69
70
		
		if (!obj) {
			var fullObject = this.get('realLinkedNode').get('object');	      
16035364   Benjamin Renard   First commit
71
		}
16035364   Benjamin Renard   First commit
72
		else {
fdf1413b   Elena.Budnik   TT download
73
			var fullObject = obj;
16035364   Benjamin Renard   First commit
74
		}
27504b3e   Elena.Budnik   redmine 5080
75
76
	   	  
		var i = 0;		
fdf1413b   Elena.Budnik   TT download
77
		fullObject.tabs().each(function (tab) {
27504b3e   Elena.Budnik   redmine 5080
78
79
80
81
82
			// only active tab			
			if (tab.get('id') == fullObject.get('last-plotted-tab'))
			{			 
				tab.panels().each(function (panel) {
					panel.params().each(function (param) {
553dd634   Benjamin Renard   Fix bug with 'Get...
83
						var myParam = new Object();
27504b3e   Elena.Budnik   redmine 5080
84
85
						myParam.paramid =  param.get('paramid');
						myParam.type =  param.get('type');
29dfb596   Benjamin Renard   Rework of ParamAr...
86
87
88
89
90
91
92
93
94
95
96
97
						myParam['dim1-index'] = param.get('dim1-index');
						myParam['dim1-sum-type'] = param.get('dim1-sum-type');
						myParam['dim1-min-value'] =  param.get('dim1-min-value');
						myParam['dim1-max-value'] =  param.get('dim1-max-value');
						myParam['dim1-min-index'] =  param.get('dim1-min-index');
						myParam['dim1-max-index'] =  param.get('dim1-max-index');
						myParam['dim2-index'] = param.get('dim2-index');
						myParam['dim2-sum-type'] = param.get('dim2-sum-type');
						myParam['dim2-min-value'] =  param.get('dim2-min-value');
						myParam['dim2-max-value'] =  param.get('dim2-max-value');
						myParam['dim2-min-index'] =  param.get('dim2-min-index');
						myParam['dim2-max-index'] =  param.get('dim2-max-index');
27504b3e   Elena.Budnik   redmine 5080
98
						myParam.template_args = param.get('template_args');
3f34cc52   Elena.Budnik   PlotOnly for GetD...
99
100
101
102
103
104
						if (!param.get('plotonly')) {
							myValues.list[i] = myParam;
							++i;
						}
						else 
							alert('Parameter '+ myParam.paramid + ' is PlotOnly');						
27504b3e   Elena.Budnik   redmine 5080
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
					});
				});				
				if (tab.get('multi-plot-linked'))
				{
					var object =  fullObject.data;
				}
				else 
				{
					var object =  tab.data;
				}				
				myValues.timesrc = object.timesrc;
				// if there's at least one timeTable name into 'timeTables' collection
				if (myValues.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0]
					&& object.timeTables 
					&& object.timeTables.length ){
					// get complete timeTables collection
					var timeTables =  object.timeTables;	    
					// init an empty array for timeTables
					myValues.timeTables=[];
					// for each interval record
					Ext.Array.each(timeTables, function(item, index, all){
						if (!item.$className) {
							myValues.timeTables[index] = {timeTableName : item.timeTableName, id : item.id};
						}
						// get Json simplified value 
						else {
							myValues.timeTables[index] = item.getJsonValues();
						}
					});            
fdf1413b   Elena.Budnik   TT download
134
				}
fdf1413b   Elena.Budnik   TT download
135
				else {
27504b3e   Elena.Budnik   redmine 5080
136
137
138
139
140
141
					myValues.startDate = object.startDate;
					myValues.stopDate = object.stopDate;
					myValues.durationDay = object.durationDay;
					myValues.durationHour = object.durationHour;
					myValues.durationMin = object.durationMin;
					myValues.durationSec = object.durationSec;
fdf1413b   Elena.Budnik   TT download
142
				}
27504b3e   Elena.Budnik   redmine 5080
143
144
145
146
			}	
		});
	  
		myValues.name = fullObject.get('name');
fdf1413b   Elena.Budnik   TT download
147
148
		return myValues;
	},
16035364   Benjamin Renard   First commit
149
      
fdf1413b   Elena.Budnik   TT download
150
151
	encodeObject: function() {
	},
16035364   Benjamin Renard   First commit
152
  
e516c132   Benjamin Renard   Add SAMP export i...
153
	loadJobTree : function(sendToSamp, clientId) {   
fdf1413b   Elena.Budnik   TT download
154
155
156
157
158
159
160
		//TBD - BRE - fix code duplication with ExecutableNode if possible
		var rootNode = Ext.getCmp(amdaUI.ExplorerUI.JOB_TAB.TREE_ID).getRootNode();
		var me = this;
		amdaModel.InteractiveNode.preloadNodes(rootNode,
			function()
			{
				amdaModel.InteractiveNode.jobTreeLoaded = true;
e516c132   Benjamin Renard   Add SAMP export i...
161
				me.realExecute(sendToSamp, clientId); 
fdf1413b   Elena.Budnik   TT download
162
163
			});
	},   
16035364   Benjamin Renard   First commit
164
    	   
e516c132   Benjamin Renard   Add SAMP export i...
165
	execute : function(sendToSamp, clientId) {
16035364   Benjamin Renard   First commit
166
	
e516c132   Benjamin Renard   Add SAMP export i...
167
168
		if (!amdaModel.ExecutableNode.jobTreeLoaded) this.loadJobTree(sendToSamp, clientId);
		else this.realExecute(sendToSamp, clientId); 		
fdf1413b   Elena.Budnik   TT download
169
170
171
172
173
	},
       
/**
* Method to execute this node 
*/
e516c132   Benjamin Renard   Add SAMP export i...
174
	realExecute : function(sendToSamp, clientId) {
fdf1413b   Elena.Budnik   TT download
175
176
177
178
179
		var jsonObject = this.get('object').getJsonValues();
		if (!jsonObject.list && !jsonObject.images) {
			myDesktopApp.warningMsg('Please select at least one Parameter (Get Data) or one Time Table (Get Time Table)');
			return;
		}
e516c132   Benjamin Renard   Add SAMP export i...
180
181
182
183

		if (sendToSamp) {
			jsonObject.sendToSamp = true;
		}
fdf1413b   Elena.Budnik   TT download
184
185
186
187
188
	
		loadMask.show(); 
		AmdaAction.execute({nodeType : this.get('nodeType')}, jsonObject, function(res,e)
		{
			loadMask.hide();
16035364   Benjamin Renard   First commit
189

fdf1413b   Elena.Budnik   TT download
190
191
192
193
194
195
196
197
198
199
200
201
202
203
			//AKKA - Rework of the result treatment for the integration with the new kernel
			if (!e.status)
			{
				myDesktopApp.errorMsg('Internal error during download request');
				return;
			}
			
			if (!res.success)
			{ 
				myDesktopApp.errorMsg(res.message);
				return;
			}
			//TBD if such condition is OK ?
			if (!res.id && res.download) {
95b44daa   Benjamin Renard   Send TT and catal...
204
205
206
207
208
209
210
211
				if (res.sendToSamp) {
					myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
						Ext.Array.each(res.download, function(download) {
							module.sendVOTable(download, clientId ? clientId : 'hub');
						});
					});
					return;
				} else if (res.compression) {					
fdf1413b   Elena.Budnik   TT download
212
213
214
215
216
217
218
					window.location.href = res.download;
				}
				else {
					window.open(res.download, '_blank');
				}
				return;
			}
2cfa3a1a   Benjamin Renard   Give the possibil...
219
220
221
222

			if (logExecTime && res.exectime && (res.exectime != 0)) {
				console.log("CMD EXEC TIME FOR "+res.id+" = "+res.exectime+"ms");
			}
fdf1413b   Elena.Budnik   TT download
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
			
			var newobj = this.createJobObject(res);
			var newNode = Ext.create(this.get('jobNode'), 
			{
				id : res.id,
				info : res.info,
				jobType : this.get('nodeType'),
				processId : res.id,
				text : res.name,
				status : res.status,
				stop : res.stop,
				leaf : true,
				object : newobj
				
			});
			
			// new Tab
			switch (res.status)
			{
				case amdaModel.BkgJobNode.STATUS_LIST.DONE :
e516c132   Benjamin Renard   Add SAMP export i...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
					if (!res.sendToSamp) {
						// New tab, non-interactive session
						var isInteractive = false;
						var isNewTab = true; 
						newNode.createJobNode(true);
						newNode.editNode(isNewTab, isInteractive);
					}
					else {
						var files = res.result.split(",");
						Ext.each(files, function(file) {
							var href = 'data/'+sessionID+'/RES/'+ res.folder + '/' + file;
							myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
								module.sendVOTable(href, clientId ? clientId : 'hub');
							});
						});
					}
fdf1413b   Elena.Budnik   TT download
259
260
261
262
263
264
265
266
267
					break;
				case amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS :
					newNode.createJobNode(false);
					break;
				default:
					newNode.createJobNode(true);
			}
		}, this );
	},  
16035364   Benjamin Renard   First commit
268

fdf1413b   Elena.Budnik   TT download
269
	createJobObject: function(res) {
16035364   Benjamin Renard   First commit
270
      
fdf1413b   Elena.Budnik   TT download
271
272
273
274
		var obj =  this.get('object').getJsonValues();		    
		//TODO text, name, outputName - if all is needed        
		//new object to attach to new bkgJobNode	
		//TODO Ext.clone()	
16035364   Benjamin Renard   First commit
275
		    
fdf1413b   Elena.Budnik   TT download
276
277
278
279
280
281
282
		var newobj = Ext.copyTo({}, obj, this.get('object').propertiesToCopy);
		newobj.id        = res.id;	
		newobj.resultId  = res.result;	
		newobj.folderId  = res.folder;
		newobj = Ext.create(this.get('object').$className, newobj);
		
		return   newobj;  
16035364   Benjamin Renard   First commit
283
	}
16035364   Benjamin Renard   First commit
284
});