Blame view

js/app/views/TabResultUI.js 7.94 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
/**
 * Project   : AMDA-NG
 * Name      : TabResultUI.js
 * @class    amdaUI.TabResultUI
 * @extends  Ext.panel.Panel 
 * @brief   Tab Result UI definition (View)
 * @author    
29c449bb   Elena.Budnik   format + redmine ...
8
 * @version  $Id: TabResultUI.js 2618 2014-10-24 12:27:42Z elena $  
16035364   Benjamin Renard   First commit
9
10
11
 */

Ext.define('amdaUI.TabResultUI', {
29c449bb   Elena.Budnik   format + redmine ...
12
13
14
15
16
17
18
19
20
21
	extend: 'Ext.panel.Panel',

	alias: 'widget.tabResult',
	
	requires: [ 'amdaUI.SendToSampButtonUI'],
	
	constructor: function(config) {	 
		this.initConfig(config);
		this.callParent();	
	},  
16035364   Benjamin Renard   First commit
22
        
29c449bb   Elena.Budnik   format + redmine ...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
	initConfig: function(config){
		this.type = config.nodeType;
		this.id = 'tab-' + config.nodeType;	 
		//var title = config.nodeType +' Result';	
		switch (config.nodeType) {
			case 'condition': var title = 'Data Mining Results';
						break;
			case 'request' : var title = 'Plot Results';
						break;	   
			case 'download': var title = 'Download Results';
						break;
			case 'statistics': var title = 'Statistics Results';
						break;
			default:
		}
		
		var newConfig = {
			id: this.id,          	    
			title: title,
			autoScroll: true,
			height: 250,
			closable: true,
			layout: {
				type: 'vbox',
				align : 'stretch',
				autoSize : true
			},
			listeners: {
				scope : this,
				beforeclose : function() {
				//delete linked nodes connected to ResultModule and corresponding to this Tab
					var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id);
					if (module.linkedNodes) {
						var indices = new Array();
						var i = 0;
						module.linkedNodes.each(function(item,index){
							if(this.type == item.get('jobType')) {
								indices[i] = index;
								i++;
							}
						}, this);
						if (indices.length > 0) {
							Ext.Array.each(indices, function(item) {
								module.linkedNodes.removeAt(item);
							});			    
						}
					}
				}
			}
		}
		Ext.apply(this, newConfig);	 
	},
16035364   Benjamin Renard   First commit
75
     
29c449bb   Elena.Budnik   format + redmine ...
76
77
78
	addResult: function(resultName, resultId, folderId, compression, format, processId) { 
		this.insert(0,[ {xtype : 'resultItem', type : this.type, title: resultName, folderId: folderId, resultId: resultId, compress : compression, format: format, processId: processId}]); 
	}
16035364   Benjamin Renard   First commit
79
80
81
});

Ext.define('amdaUI.ResultItem', {
29c449bb   Elena.Budnik   format + redmine ...
82
83
84
85
86
87
88
89
	extend: 'Ext.form.FieldSet',

	alias: 'widget.resultItem',
	
	linkedNode : null,
	
	delete: function(processId) {
		var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id);
29c449bb   Elena.Budnik   format + redmine ...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
		var jobLinkedNode = module.linkedNodes.getByKey(processId);
		jobLinkedNode.deleteNode();
		module.linkedNodes.remove(jobLinkedNode);    
	},
		
	saveTable: function(folderId,ttName) {
		this.linkedNode = Ext.create('amdaModel.TimeTableNode',{leaf : true});
		AmdaAction.getTmpObject(
				folderId,
				ttName,
				this.linkedNode.get('nodeType'),
				this.getResultCallback,
				this);       
	},
16035364   Benjamin Renard   First commit
104
    
29c449bb   Elena.Budnik   format + redmine ...
105
106
107
108
109
110
111
112
113
	saveCatalog: function(folderId,ttName) {    
		this.linkedNode = Ext.create('amdaModel.CatalogNode',{leaf : true});
		AmdaAction.getTmpObject(
				folderId,
				ttName,
				this.linkedNode.get('nodeType'),
				this.getResultCallback,
				this);       
	},
d18b535d   elena   catalog draft + c...
114
    
29c449bb   Elena.Budnik   format + redmine ...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
	getResultCallback : function(result,remoteEvent){ //result, e) {
		var t = remoteEvent.getTransaction();
		//AKKA - catch error
		if (!remoteEvent.status){
			myDesktopApp.errorMsg('Internal error');
			return;
		}
		
		if (result.error){
			myDesktopApp.errorMsg(result.error);
			return;
		}
		
		var paramObj = Ext.create(this.linkedNode.get('objectDataModel'), result);
		paramObj.set('fromPlugin',true);
		paramObj.set('intervals',result.intervals);
		// set parameter into node
		this.linkedNode.set('object',paramObj);
			
		var me = this;
		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id, true, function (module) {
			module.setLinkedNode(me.linkedNode);
			// Edition of parameter into parameter Module	    
			me.linkedNode.editInModule();
		});
	},
16035364   Benjamin Renard   First commit
141
    
29c449bb   Elena.Budnik   format + redmine ...
142
	onSendVOTableToSamp : function (clientId, sendOpt){
0bda97f3   Benjamin Renard   Fix SAMP export f...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
		loadMask.show();
		AmdaAction.getRequestByProcessId(sendOpt, function(res,e) {
			var request = res;
			request.sendToSamp = true;
			AmdaAction.execute({nodeType : 'download'}, request, function(res,e) {
				loadMask.hide();
				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');
					});
				});
			});
		});
29c449bb   Elena.Budnik   format + redmine ...
158
	},
16035364   Benjamin Renard   First commit
159
    
29c449bb   Elena.Budnik   format + redmine ...
160
161
162
163
	constructor: function(config) {
		this.initConfig(config);
		this.callParent();	
	},  
16035364   Benjamin Renard   First commit
164
    
29c449bb   Elena.Budnik   format + redmine ...
165
166
	initConfig: function(config){	
		var jobtitle = config.title;
0bda97f3   Benjamin Renard   Fix SAMP export f...
167

29c449bb   Elena.Budnik   format + redmine ...
168
169
170
171
172
		switch (config.type) {			
			case 'request' : 
				var resultId = config.resultId;
				var folderId = config.folderId;
				var href = 'data/'+sessionID+'/RES/'+ folderId  + '/' + resultId;
16035364   Benjamin Renard   First commit
173
			break; 
29c449bb   Elena.Budnik   format + redmine ...
174
175
176
177
178
179
180
181
182
183
			case 'download' :
				//TODO suffix parsing		     
				var suffix = '.tar.gz';			     
				if (config.compress == 'zip') var suffix = '.zip';
				var downId = config.resultId;
				var downFolder = config.folderId;			      
				var href = 'data/'+sessionID+'/RES/'+ downFolder + '/' + downId + suffix;			      
				break;
			default:
		}	  
16035364   Benjamin Renard   First commit
184
       
29c449bb   Elena.Budnik   format + redmine ...
185
		var height = 60;  
16035364   Benjamin Renard   First commit
186
	
29c449bb   Elena.Budnik   format + redmine ...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
		var configTT = {
			intId : config.title, 
			height : height,	
			title: jobtitle,
			collapsible: true,
			defaultType: 'button',
			items :[
			{
				xtype: 'label',
				text: 'Time Table '
			},{
				text: 'Edit/Save',
				scope : this,
				handler: function() {
					this.saveTable(config.folderId,config.resultId);
				}
			},  {
				xtype: 'label',
				text: '  || Gaps Time Table '
			}, {
				text: 'Edit/Save',
				scope : this,
				handler: function() {
					this.saveTable(config.folderId,'Gaps_'+config.resultId); 
				}
			}, {
				xtype: 'label',
				text: ' || ',
				width: 50
			}, {
				text: 'Delete Both',
				scope : this,
				handler: function() {
					this.delete(config.processId);
					this.ownerCt.remove(this);
				}
			}]
		};
d18b535d   elena   catalog draft + c...
225
	  
29c449bb   Elena.Budnik   format + redmine ...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
		var configCat = {
			intId : config.title, 
			height : height,	
			title: jobtitle,
			collapsible: true,
			defaultType: 'button',
			items :[
			{
				xtype: 'label',
				text: 'Catalog '
			}, {
				text: 'Edit/Save',
				scope : this,
				handler: function() {
					this.saveCatalog(config.folderId,config.resultId);
				}
			}, {
				text: 'Delete',
				scope : this,
				handler: function() {
					this.delete(config.processId);
					this.ownerCt.remove(this);
				}
			}]
		};
		
		//TODO make this properly	  	  
		var configPlot = {
			intId : config.processId,
			height :  height,	
			title : jobtitle,
			collapsible: true,
			defaultType: 'button',
			items :[
			{
				xtype: 'label',
				text: 'Plot '
			}, {
				text: 'Download',
				href: href,
				target: '_blank', // removed in 4.1    , hrefTarget: '_blank' // used in 4.1	
				hrefTarget: '_blank'
			},  {
				xtype: 'label',
				text: '  ||  '
			}, {
				text: 'Delete',
				scope : this,
				handler: function() {
					this.delete(config.processId);
					this.ownerCt.remove(this);
				}
			}]
		};
		
		var configDown = {
			intId : config.processId,
			height :  height,	
			title: jobtitle,
			collapsible: true,
			defaultType: 'button',
			items :[
			{
				xtype: 'label',
				text: 'File '
			}, {
				text: 'Download',
				href: href,
				target: '_self', // removed in 4.1    , hrefTarget: '_blank' // used in 4.1	
				hrefTarget: '_self'
			}, {
				xtype: 'label',
				text: '  ||  '
			}, 
			{
				text: 'Delete',
				scope : this,
				handler: function() {
					this.delete(config.processId);
					this.ownerCt.remove(this);
				}
			},{
				xtype: 'label',
				text: '  ||  '
			},{
				xtype        : 'sendToSampButton',
				type         : 'votable',
				onSendToSamp : this.onSendVOTableToSamp,
0bda97f3   Benjamin Renard   Fix SAMP export f...
314
				sendOpt      : {'processId' : config.processId}
29c449bb   Elena.Budnik   format + redmine ...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
			}]
		};
	
		switch (config.type) {
			case 'condition' : 
				Ext.apply(this, configTT);	
				break;
			case 'statistics' : 
				Ext.apply(this, configCat);	
				break;
			case 'request' : 		      
				Ext.apply(this, configPlot);
				break; 
			case 'download' :			     
				Ext.apply(this, configDown);
				break;
			default:
16035364   Benjamin Renard   First commit
332
		}
29c449bb   Elena.Budnik   format + redmine ...
333
	}    
16035364   Benjamin Renard   First commit
334
});