Blame view

js/app/models/DownloadNode.js 8.81 KB
16035364   Benjamin Renard   First commit
1
2
3
4
5
6
7
/** 
 * Project  : AMDA-NG4
 * Name     : DownloadNode.js
 * @class   amdaModel.DownloadNode
 * @extends amdaModel.ExecutableNode
 * @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
10
11
12
13
14
15
16
 */
//TODO amdaModel.SingletonNode class ???
Ext.define('amdaModel.DownloadNode', {

    extend: 'Ext.data.Model',
    
    singleton: true,
        
3a5f60a1   elena   proper use os sta...
17
18
19
20
21
22
23
24
	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
25
26
27
28
29
30
31
32
33
34
    
     isExecutable: function(){
        return true;
      },
      
//TODO MIXINS
      
      getObjectCallback : function(result,remoteEvent){  
        var t = remoteEvent.getTransaction();
        if (result) {            
aa94fd24   elena   Merge with last svn
35
             var paramObj = Ext.create(this.get('objectDataModel'), result);
16035364   Benjamin Renard   First commit
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
            // 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 {
            // EXCEPTION : parameter not found !?
            alert(t.action + "." + t.method + " : No parameter '"
                +this.get('name')+"' found!");
            //TODO: adding an error log
        }
      },
      
        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();
        	});
    },
    
      decodeObject: function(obj) {
18d4a11e   Benjamin Renard   Save and load plo...
71
72
    	  var myValues  = new Object(); 
    	  myValues.list=[];
16035364   Benjamin Renard   First commit
73
	 
18d4a11e   Benjamin Renard   Save and load plo...
74
75
76
77
78
79
    	  if (!obj) {
    		  var fullObject = this.get('realLinkedNode').get('object');	      
    	  }
    	  else {
    		  var fullObject = obj;
    	  }
16035364   Benjamin Renard   First commit
80
	  
18d4a11e   Benjamin Renard   Save and load plo...
81
82
83
84
    	  var i = 0;
    	  fullObject.tabs().each(function (tab) {
    		  tab.panels().each(function (panel) {
    			  panel.params().each(function (param) {
bb6e93d9   Benjamin Renard   Implement templat...
85
    				  myValues.list[i] = param.get('paramid');
18d4a11e   Benjamin Renard   Save and load plo...
86
87
88
89
90
91
92
93
    				  ++i;
    			  });
    		  });
    		  
    	  });
    	  
    	  myValues.name = fullObject.get('name');
    	  myValues.timesrc = fullObject.get('timesrc');
16035364   Benjamin Renard   First commit
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
	  // if there's at least one timeTable name into 'timeTables' collection
	  if (myValues.timesrc == amdaModel.AmdaTimeObject.inputTimeSrc[0] 
		    && fullObject.get('timeTables') 
		    && fullObject.get('timeTables').length ){
	      // get complete timeTables collection
	      var timeTables =  fullObject.get('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();
		}
	      });            
	  } else {
	      myValues.startDate = fullObject.get('startDate');
	      myValues.stopDate = fullObject.get('stopDate');
	      myValues.durationDay = fullObject.get('durationDay');
	      myValues.durationHour = fullObject.get('durationHour');
	      myValues.durationMin = fullObject.get('durationMin');
	      myValues.durationSec = fullObject.get('durationSec');
	  } 
	return myValues;
      },
      
      encodeObject: function() {
      },
      
/*
 * Method to parse special parameters cases with arguments (spectra && MODELS)
 * TODO to rewrite with amda new kernel
 */      
      parseArgs: function(param) {	
	 var name = param.name;
	 var args = param.downloadParamArgs;
16035364   Benjamin Renard   First commit
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
	 if (args.energyMax){
	   var nameToSent = name + '_' + args.energyMin +  '_' + args.energyMax;
	  return nameToSent;
	 }
	 
	 if (args.PA && args.Energy){
	   var nameToSent = name + '_' + args.PA +  '_' + args.Energy;
	  return nameToSent;	    
	 }
	 
	 if (args.PA) {
	     var pa = args.PA - 1;
	     var nameToSent = name + '(' +  pa + ')';
	   return nameToSent;	 
	 }
	 
	 if (args.Energy) {
	    var en = args.Energy - 1;
//TODO temporary	    
	    if (name.substr(name.length-2, 2) == '_E') name = name.substr(0,name.length-2);
	    var nameToSent = name + '(' +  en + ')';
	   return nameToSent;	
	 } 
	 // T96; A2000
	 if (args.SW_Monitor) {
              var nameToSent = name + '_' + args.Spacecraft +  '_' + args.SW_Monitor;
              return nameToSent;    
aa94fd24   elena   Merge with last svn
160
161
162
163
164
         } 
         // Cain ; Morschhauser
         if (args.Spacecraft && args.Sampling) {
              var nameToSent = name + '_' + args.Spacecraft +  '_' + args.Sampling;
              return nameToSent;    
16035364   Benjamin Renard   First commit
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
         }
         // LATMOS
         if (args.ClockAngle && args.Satellite) {
              var nameToSent = name + '_' + args.Satellite +  '_' + args.ClockAngle;
              return nameToSent;    
         }
         
         // FMI HYBRID
        if (args.Satellite && Ext.Object.getSize(args) === 1) {
            var nameToSent = name + '_' + args.Satellite;
            return nameToSent;    
        }
        
      },
      
  
    loadJobTree : function() {   
    	  //ToDo - 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;
					me.realExecute(); 
            	});
    },   
    	   
    execute : function() {
      
	if (!amdaModel.ExecutableNode.jobTreeLoaded) this.loadJobTree();
	else this.realExecute(); 
	   
    },
 
      
    /**
     * Method to execute this node 
     */
    realExecute : function() {

        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;
        }
	
	loadMask.show(); 
        AmdaAction.execute({nodeType : this.get('nodeType')}, jsonObject, function(res,e){
	
	   loadMask.hide();
aa94fd24   elena   Merge with last svn
216

16035364   Benjamin Renard   First commit
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
	   //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;
	   }
	   
       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 :
    	   // New tab, non-interactive session
    	   var isInteractive = false;
    	   var isNewTab = true; 
    	   newNode.createJobNode(true);
    	   newNode.editNode(isNewTab, isInteractive);
    	   break;
       case amdaModel.BkgJobNode.STATUS_LIST.IN_PROGRESS :
    	   newNode.createJobNode(false);
    	   break;
       default:
    	   newNode.createJobNode(true);
       }
        }, this );

},  

    createJobObject: function(res) {
      
		    var obj =  this.get('object').getJsonValues();		    
//TODO text, name, outputName - if all is needed        
	             //new object to attach to new bkgJobNode	
aa94fd24   elena   Merge with last svn
268

16035364   Benjamin Renard   First commit
269
270
271
272
273
274
275
//TODO Ext.clone()	
		    
		    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);
16035364   Benjamin Renard   First commit
276
277
278
279
		 return   newobj;  
	}

});