Blame view

js/app/controllers/InteractivePlotMgr.js 10.6 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

/** 
 * Project   : AMDA-NG
 * Name      : InteractivePlotMgr.js
 * @class    amdaDesktop.ResultModule
 * @extends  amdaDesktop.InteractiveModule
 * @brief    Result Module controller definition 
 * @author   
 * @version $Id: InteractivePlotMgr.js 1875 2013-11-22 15:02:50Z elena $
 *****************************************************************************
 *    FT Id     :   Date   : Name - Description
 *******************************************************************************
 *  			 
 */

Ext.define('amdaDesktop.InteractivePlotMgr', {
        extend: 'amdaDesktop.InteractiveModule',
  
        requires: [
                    'amdaUI.InteractivePlotUI',
                    'amdaUI.PlotTabResultUI'
        ],
    
        statics: {
            multiSelector: false,            
           
            maxWinNumber : 5,
16035364   Benjamin Renard   First commit
28
29
30
31
32
33
34
35
	    imgOffset : { x : 70, y : 85 },
	    winSize : {
	         landscape : { width : 0, height : 0 },
	         portrait : { width : 0, height : 0 }
	    }
        },
	
	imgSize : {
c45e3428   Benjamin Renard   Set adapted size ...
36
37
	      landscape : { width : 1052, height : 744 },
	      portrait : { width : 744, height : 1052 }
16035364   Benjamin Renard   First commit
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
75
76
77
78
79
80
81
82
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
110
111
112
113
114
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
141
142
143
144
145
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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
	    },
	   
 	maxWinNumber : 5,	 
 	contentId : 'InteractivePlotUI',	
    /**
     * @cfg {String} data models
     * @required
     */
	nodeDataModel :  'amdaModel.BkgJobNode',	
	windowMgr : null,
	win: null,
	
	 constructor : function(config) {
	    this.callParent(arguments);
	    if (!this.windowMgr) this.windowMgr = new Ext.AbstractManager();
	}, 
	
	init : function() {	
		//force the launcher to null to don't add this item on start menu
		this.launcher = null;
		amdaDesktop.InteractivePlotMgr.winSize.landscape.width  = this.imgSize.landscape.width + amdaDesktop.InteractivePlotMgr.imgOffset.x;
		amdaDesktop.InteractivePlotMgr.winSize.landscape.height = this.imgSize.landscape.height + amdaDesktop.InteractivePlotMgr.imgOffset.y;
		amdaDesktop.InteractivePlotMgr.winSize.portrait.width   = this.imgSize.portrait.width + amdaDesktop.InteractivePlotMgr.imgOffset.x;
		amdaDesktop.InteractivePlotMgr.winSize.portrait.height  = this.imgSize.portrait.height + amdaDesktop.InteractivePlotMgr.imgOffset.y;   
	},	
	
	computeWindowSize : function(panelResult)
	{
	    var size = panelResult.getImageSize();
	    size.width  += 30;
	    size.height += 95;
	    
	    return size;
	},
    /**
      * Window Creation method of the Module
      */
	createWindow : function () {	
	   // independent window manager to register all plot windows	        	   
		this.win = myDesktopApp.desktop.getWindow(this.id);
		 
		if (!this.win) {
			this.win = myDesktopApp.desktop.createWindow({
				id : this.id,
				title : this.title,
				width :  320,
				height : 120,
				iconCls : this.icon,
				x : 3000,
				y : 5 ,
				border : false,
				constrainHeader : true,
				layout : 'fit',
                                closable: false,
                                maximizable: false,
				tools: [
				  {
			        	type:'help',
			        	qtip: 'Help on Multi Plot',
                                        scope:this,
			        	handler: function(event, toolEl, panel){	
			        		myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.info.id, true, function (module) {
			        			module.createWindow('multiPlot', 'Help on Multi Plot');	  
			        		});             
			        	}
			         }
				],
				items : [ { xtype : 'panelPlotMgr' } ]
			});
			
			this.win.on({
				scope: this,				 
				// on window closing event
				beforeclose: function(){
				   this.windowMgr.each(function(key,win){
						   win.close();				        			      
				    });	
                                   this.linkedNode = null;
				} 
			});
		} 		 	 	  
	  
	    var linkedNode = this.getLinkedNode();	 

	    if (linkedNode) {
	    // array of nodes for reference
		this.addLinkedNode(linkedNode);	 	 	       
		this.setResult({object: linkedNode.get('object')});	   
	    }
	    
           //     this.win.show();
           //     this.win.toFront(); 
            
	},
	
       setResult: function(configResult){
 
// define window size depending on plot orientation
	    var orientation = configResult.object.get('orientation');
	     	     
            // get existing plot Result Plot Window with this resultId	    
	    var id = 'plot'+configResult.object.get('tabId');
	    var windowResultId = id + '-win';
	   	            
	    var windowResult = this.getWindowResult(windowResultId);

            // if no existing plot Tab Result Panel	 
            if (!windowResult) {	      
	      N = eval(configResult.object.get('tabId'));
	      
	      var title = 'Plot '+ configResult.object.get('tabId'); 	      
	      var panelResult = new amdaUI.PlotTabResultUI(configResult);
	    
	      var pageSize = Ext.state.Manager.getProvider().get(windowResultId+'_pagesize');
	      if (!pageSize)
	    	  pageSize = 75;
	      	      
	      var size = this.computeWindowSize(panelResult);
	     	      
	      var x = N * 50;
	      var y = 100 + N * 20;
	      var win = myDesktopApp.getDesktop().createWindow({
				id : windowResultId,
				mode : orientation,
				title : title,
				width : size.width,
				height : size.height,
				x : x,
				y : y,
				iconCls : this.icon,
				border : false,
				constrainHeader : true,
				layout : 'fit',
				items : [ 
				    panelResult 
				],  
				listeners: {
				  scope: this,				  
				  move: function(win,x,y){
				    var panel = win.items.items[0];
				    var image = panel.items.items[0];
				    panel.setImageSettings(image);
				  },				  
				  resize: function(win, w, h){
				    var panel = win.items.items[0];
				    var image = panel.items.items[0];
				    panel.setImageSettings(image);
				  },
				  beforeclose: function(win,opt){
					var linkedNodeKey = win.id;   					 
					var linkedNode = this.getLinkedNodeByKey(linkedNodeKey);					
					this.removeLinkedNode(linkedNodeKey);
					this.win.items.items[0].removePlotItem(linkedNodeKey);	
				     
					linkedNode.deleteNode();
					this.windowMgr.unregister(win);
					if (myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id) != null)
						myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id).multiSelector = false;					
				  },				  
				//   destroy: function(win,opt){
				// 	  if (this.windowMgr.getCount() === 0) this.win.close();
				//   }, 
				  show: function(o)
				  {
					  panelResult.setPageSize(pageSize);					 
				  }			      
			      }
		});
	      
		panelResult.on({
		      scope : this,
		      pagesize : function(win,val)
		      {
			    Ext.state.Manager.getProvider().set(windowResultId+'_pagesize',val);
		    }
		});
	      
		// register new window 	       
		this.windowMgr.register(win);				
		if (this.linkedNodes) this.win.items.items[0].addPlotItem(N-1,windowResultId);		
		win.show(); 
	     	 
            } else {	     
//update image (OUTPUTNAME!!!!) and timing   in existing Tab result Panel                 
		var linkedNode = this.getLinkedNode();
		//resize window for changed orientation	    		 
		var resultId = linkedNode.get('object').get('folderId'); 
		
	 	//var outputName = linkedNode.get('object').get('outputName');	
		var windowId =  'plot' + linkedNode.get('object').get('tabId') + '-win';
		panelResult = this.getWindowResult(windowId).items.items[0];
			
	 	//if (!outputName) {
		   var outputName = linkedNode.get('object').get('resultId');;
		   panelResult.updateObject(linkedNode.get('object'));
	 	//}
//if orientation was changed : resize window and image
		if (windowResult.mode != orientation) {	
		   var size = this.computeWindowSize(panelResult); 
		   windowResult.setSize(size.width,size.height);
		   windowResult.mode = orientation;
		   var sizeImg = Ext.clone(size);
		   var interactivePlotMgr = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.interactive_plot.id);
		   if (interactivePlotMgr)
c45e3428   Benjamin Renard   Set adapted size ...
242
243
			   panelResult.panelImage.setSize(sizeImg.width-amdaDesktop.InteractivePlotMgr.imgOffset.x, 
						  sizeImg.height-amdaDesktop.InteractivePlotMgr.imgOffset.y);
16035364   Benjamin Renard   First commit
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
314
315
		}
		   
		panelResult.panelImage.setSrc('data/'+sessionID +'/RES/'+resultId+'/'+ outputName +'.png');  		
		panelResult.currentStartTime = linkedNode.get('object').get('startDate');
		 
		var stopTime = linkedNode.get('object').get('stopDate');
		panelResult.plotDurationInSec = Ext.Date.getElapsed(panelResult.currentStartTime, stopTime) / 1000;
// reset mire and Start - Stop ONLY if Interactive Plugin is active
		 var interactivePlugin = Ext.getCmp('interactiveInter-win-'+windowResultId);
		 if (interactivePlugin) {
		  panelResult.resetMire();		    		  
		  interactivePlugin.items.getAt(0).getForm().findField('start').setValue('');
		  interactivePlugin.items.getAt(0).getForm().findField('stop').setValue('');             
		 }
				 		
		panelResult.setImageSettings(panelResult.panelImage);
		windowResult.toFront();
// if time interval => update Time in TimeSelector		
		if (configResult.object.get('timesrc')  ==  amdaModel.AmdaTimeObject.inputTimeSrc[1]) {	     
		    var timeSelector = Ext.getCmp('plotTimeSelector'+id);
		    timeSelector.cardContainer.activeItem = 1;		   
		    var intervalSelector = timeSelector.cardContainer.items[1];
		    intervalSelector.setInterval(panelResult.currentStartTime, stopTime);		  
		}
            }
//if plot for time table : set/update info            
            if (configResult.object.get('timesrc')  ==  amdaModel.AmdaTimeObject.inputTimeSrc[0]) {	     
	         panelResult.updateTimeTableInfo(configResult.object);
	    }
	    
// disable buttons if this Tab is checked in the multi plot selector
	    var resWin =  myDesktopApp.desktop.getWindow(myDesktopApp.dynamicModules.interactive_plot.id);
	    if (!resWin) return;
	    var checked = resWin.items.items[0].checkBoxGroup.getChecked();	  
	    Ext.Array.each(checked, function(item, index){
		if (item.name.toLowerCase() === windowResultId){
		  panelResult.disableButtons(true);
		  return;
		}
	    });   
    },
 
     
    // getter on specific plot Tab result window
	getWindowResult: function(windowResultId){
	    if (!this.windowMgr.get(windowResultId)) return null;
	    return this.windowMgr.get(windowResultId);	    
	},

	addLinkedNode : function (myLinkedNode){
	    if (!this.linkedNodes){
	        this.linkedNodes = new Array();
	    }
	    var obj = myLinkedNode.get('object');	   
	    if (obj.get('tabId')){	     
	        // add new linkedNode to this module
	        this.linkedNodes['plot'+obj.get('tabId') + '-win'] = myLinkedNode;		 
	    }	  
	},
	
	getLinkedNodeByKey: function(linkedNodeKey){
	    if (this.linkedNodes){
	        return this.linkedNodes[linkedNodeKey];
	    } else {
	        return null;
	    }
	},
	
	removeLinkedNode: function(linkedNodeKey){
	    delete this.linkedNodes[linkedNodeKey];
	}
});