Blame view

js/app/views/TabResultUI.js 9.19 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * Project   : AMDA-NG
 * Name      : TabResultUI.js
 * @class    amdaUI.TabResultUI
 * @extends  Ext.panel.Panel 
 * @brief   Tab Result UI definition (View)
 * @author    
 * @version  $Id: TabResultUI.js 2618 2014-10-24 12:27:42Z elena $
 ********************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 *              
 */

Ext.define('amdaUI.TabResultUI', {
    extend: 'Ext.panel.Panel',
   
    alias: 'widget.tabResult',
    
    requires: [
               'amdaUI.SendToSampButtonUI'
           ],
    
    constructor: function(config) {	 
	this.initConfig(config);
	this.callParent();	
    },  
        
    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;
d18b535d   elena   catalog draft + c...
40
41
	  case 'statistics': var title = 'Statistics Results';
			    break;
16035364   Benjamin Renard   First commit
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	  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
d18b535d   elena   catalog draft + c...
59
		       var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id);
16035364   Benjamin Renard   First commit
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
		       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);	 
    },
     
18d4a11e   Benjamin Renard   Save and load plo...
81
82
    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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
   }
});

Ext.define('amdaUI.ResultItem', {
    extend: 'Ext.form.FieldSet',
   
    alias: 'widget.resultItem',
    
    linkedNode : null,
    
    delete: function(processId) {
      var module = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.result.id);
      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);       
    },
    
d18b535d   elena   catalog draft + c...
110
111
112
113
114
115
116
117
118
119
    saveCatalog: function(folderId,ttName) {    
      this.linkedNode = Ext.create('amdaModel.CatalogNode',{leaf : true});
      AmdaAction.getTmpObject(
    		  folderId,
    		  ttName,
    		  this.linkedNode.get('nodeType'),
    		  this.getResultCallback,
    		  this);       
    },
    
16035364   Benjamin Renard   First commit
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    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;
        }
        
d18b535d   elena   catalog draft + c...
135
136
        var paramObj = Ext.create(this.linkedNode.get('objectDataModel'), result);
         paramObj.set('fromPlugin',true);
16035364   Benjamin Renard   First commit
137
138
139
140
141
142
143
144
         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	    
d18b535d   elena   catalog draft + c...
145
		   me.linkedNode.editInModule();
16035364   Benjamin Renard   First commit
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
	});
    },
    
    onSendVOTableToSamp : function (clientId, sendOpt)
    {
    	var o = {folderId : sendOpt.downFolder, downId : sendOpt.downId};

    	var me = this;
        myDesktopApp.getLoadeModule(myDesktopApp.dynamicModules.interop.id, true, function (module) {
        	loadMask.show();
        	
            AmdaAction.sendToSAMP(o,function (result, e)
            		{
            	        loadMask.hide();
            			if (!result.success)
        				{
        					Ext.Msg.show( {
        						title : 'SAMP - Cannot send VOTable',
        						msg : result.message,
        						modal : true,
        						icon : Ext.Msg.ERROR,
        						buttons : Ext.Msg.OK
        				});
        				return;
        			}
        			
        			Ext.each(result.files,function (file)
        					{
        						module.sendVOTable(file,clientId);
        					}, me);
        		},
        		me);
        });
        	
        
    },
    
    constructor: function(config) {
    	this.initConfig(config);
    	this.callParent();	
    },  
    
      initConfig: function(config){	
18d4a11e   Benjamin Renard   Save and load plo...
189
    	var jobtitle = config.title;
16035364   Benjamin Renard   First commit
190
191
192
193
    	
       switch (config.type) {	
	  
	    case 'request' : 
18d4a11e   Benjamin Renard   Save and load plo...
194
            var resultId = config.resultId;
16035364   Benjamin Renard   First commit
195
            var folderId = config.folderId;
18d4a11e   Benjamin Renard   Save and load plo...
196
            var href = 'data/'+sessionID+'/RES/'+ folderId  + '/' + resultId;
16035364   Benjamin Renard   First commit
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
225
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
			break; 
	    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:
	  }
	  
       
	var height = 60;  
	
        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...
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
	  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);
		  }
		}
	     ]
	  };
	  
16035364   Benjamin Renard   First commit
283
284
285
286
287
//TODO make this properly
	  	  
	  var configPlot = {
	    intId : config.processId,
	    height :  height,	
18d4a11e   Benjamin Renard   Save and load plo...
288
	    title : jobtitle,
16035364   Benjamin Renard   First commit
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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
	    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,
			sendOpt      : {'downId' : downId, 'downFolder'   : downFolder}
		}
	     ]
	  };
 
	  switch (config.type) {
	    case 'condition' : 
			      Ext.apply(this, configTT);	
			    break;
d18b535d   elena   catalog draft + c...
361
362
363
	    case 'statistics' : 
			      Ext.apply(this, configCat);	
			    break;
16035364   Benjamin Renard   First commit
364
365
366
367
368
369
370
371
372
373
374
375
	    case 'request' : 		      
			      Ext.apply(this, configPlot);
			    break; 
	    case 'download' :			     
			      Ext.apply(this, configDown);
			    break;
	    default:
	  }
 
    }
    
});