Commit 7cab5983c6cca7218002795e4b2d85099015e4ef

Authored by Benjamin Renard
1 parent 19ad3227

Add modif. time for derived parameter (#7063) + Add the possibility to resample …

…a derived parameter under a ref. parameter (#7018)
js/app/models/InteractiveNode.js
... ... @@ -204,6 +204,10 @@ Ext.define('amdaModel.InteractiveNode', {
204 204 this.set('info',res.info);
205 205 }
206 206  
  207 + if (res.last_update) {
  208 + this.get('object').set('last_update', res.last_update);
  209 + }
  210 +
207 211 // myDataParam and Parameter special update
208 212 this.specialUpdate(res, false);
209 213  
... ... @@ -280,9 +284,29 @@ Ext.define('amdaModel.InteractiveNode', {
280 284 // set the tooltip
281 285 this.set('info',res.info);
282 286 }
  287 +
  288 + var reloadObject = false;
  289 + if (res.last_update) {
  290 + this.get('object').set('last_update', res.last_update);
  291 + reloadObject = true;
  292 + }
  293 +
283 294 //set globalStart & global Stop to be used for time selection
284 295 this.specialUpdate(res, true);
285 296  
  297 + // reload object into the view of corresponding Module
  298 + var me = this;
  299 + if (reloadObject) {
  300 + myDesktopApp.getLoadedModule(this.get('moduleId'), true, function (module) {
  301 + if (!opt || !opt.plot) {
  302 + module.getUiContent().setObject(me.get('object'));
  303 + }
  304 + else {
  305 + module.getUiContent().reloadPlot(me);
  306 + }
  307 + });
  308 + }
  309 +
286 310 //TODO do we need this commission ???
287 311 // fix the modifications for object
288 312 this.get('object').commit();
... ...
js/app/models/Parameter.js
... ... @@ -19,13 +19,16 @@ Ext.define('amdaModel.Parameter', {
19 19 extend: 'amdaModel.AmdaObject',
20 20  
21 21 fields : [
22   - {name: 'timestep', type: 'string'},
  22 + {name: 'timestep', type: 'string'}, // only used if 'sampling_mode' is 'timestep'
23 23 {name: 'units', type: 'string'},
24 24 {name: 'buildchain', type: 'string'},
25 25 {name: 'description', type: 'string'},
26 26 {name: 'ytitle', type: 'string'},
27   - {name: 'dim_1', type: 'number'},
28   - {name: 'dim_2', type: 'number'}
  27 + {name: 'dim_1', type: 'number'},
  28 + {name: 'dim_2', type: 'number'},
  29 + {name: 'last_update', type: 'int', defaultValue: 0},
  30 + {name: 'sampling_mode', type: 'string', defaultValue: 'timestep'}, // 'timestep' or 'refparam'
  31 + {name: 'reference_param', type: 'string'} // only used if 'sampling_mode' is 'refparam'
29 32 ],
30 33  
31 34 /**
... ... @@ -54,7 +57,9 @@ Ext.define('amdaModel.Parameter', {
54 57 myValues.dim_1 = this.get('dim_1');
55 58 myValues.dim_2 = this.get('dim_2');
56 59 myValues.nodeType = amdaModel.DerivedParamNode.nodeType;
  60 + myValues.sampling_mode = this.get('sampling_mode');
  61 + myValues.reference_param = this.get('reference_param');
57 62 return myValues;
58 63 }
59 64  
60   -});
61 65 \ No newline at end of file
  66 +});
... ...
js/app/views/ParameterUI.js
... ... @@ -83,7 +83,7 @@ Ext.define('amdaUI.ParameterUI',
83 83 setObject : function (object)
84 84 {
85 85 this.object = object;
86   - // load object into form
  86 + // load object into form
87 87 this.formPanel.getForm().loadRecord(this.object);
88 88 },
89 89  
... ... @@ -140,7 +140,9 @@ Ext.define('amdaUI.ParameterUI',
140 140 var obj = {
141 141 paramId : 'ws_'+this.object.get('name'),
142 142 buildchain:this.object.get('buildchain'),
143   - timestep:this.object.get('timestep')
  143 + timestep:this.object.get('timestep'),
  144 + reference_param: this.object.get('reference_param'),
  145 + sampling_mode: this.object.get('sampling_mode')
144 146 };
145 147 loadMask.show();
146 148 AmdaAction.generateParamInfo(obj, function (result, e) {
... ... @@ -169,12 +171,11 @@ Ext.define('amdaUI.ParameterUI',
169 171 });
170 172 },
171 173  
172   -
173 174 /**
174 175 * save method called by Save button
175 176 */
176 177 saveProcess : function(toRename)
177   - {
  178 + {
178 179 if(this.object.dirty)
179 180 {
180 181 // Parameter Module
... ... @@ -268,6 +269,7 @@ Ext.define('amdaUI.ParameterUI',
268 269 {
269 270 this.fieldName = new Ext.form.field.Text({
270 271 labelAlign: 'top', itemId: 'formParamName',
  272 + labelPad: 0,
271 273 fieldLabel: 'Parameter Name',
272 274 name : 'name',
273 275 allowBlank : false, //blankText : 'Name is required',
... ... @@ -293,11 +295,12 @@ Ext.define('amdaUI.ParameterUI',
293 295  
294 296 this.constructionField = new extensions.SelectableTextArea({
295 297 labelAlign: 'top',
  298 + labelPad: 0,
296 299 itemId: 'formParamConstructParameter',
297 300 fieldLabel:'<img amda_clicktip="constructParameter" src="js/resources/images/16x16/info_mini.png"/>&nbsp;Construct Parameter',
298 301 allowBlank : false, blankText : 'Construct Parameter is required',
299 302 name : 'buildchain',
300   - flex: 0.9,
  303 + flex: 0.6,
301 304 validateOnChange: false,
302 305 validateOnBlur: false,
303 306 validator : this.isBalanced,
... ... @@ -401,6 +404,90 @@ Ext.define(&#39;amdaUI.ParameterUI&#39;,
401 404 // }
402 405 // }
403 406 });
  407 +
  408 + var samplingmode_store = new Ext.data.ArrayStore({
  409 + fields: ['id', 'name'],
  410 + data: [
  411 + ['timestep', 'Time Step'],
  412 + ['refparam', 'Ref. Parameter']
  413 + ]
  414 + });
  415 +
  416 + this.timeStepField = new Ext.form.NumberField({
  417 + fieldLabel: '<img amda_clicktip="resamplingStep" src="js/resources/images/16x16/info_mini.png"/>&nbsp;Time Step (sec)',
  418 + labelAlign: 'top',
  419 + labelPad: 0,
  420 + blankText : 'Time Step is required',
  421 + name : 'timestep',
  422 + minValue : 0.001,
  423 + decimalPrecision : 10,
  424 + hideTrigger: true,
  425 + width: 150,
  426 + validateOnBlur: false
  427 + });
  428 +
  429 + this.refParamField = new Ext.form.TextField({
  430 + fieldLabel: '<img amda_clicktip="resamplingRefParam" src="js/resources/images/16x16/info_mini.png"/>&nbsp;Reference Param.',
  431 + labelAlign: 'top',
  432 + labelPad: 0,
  433 + name : 'reference_param',
  434 + width: 150,
  435 + hidden: true,
  436 + listeners: {
  437 + afterrender: function(field, eOpts ){
  438 + var paramTarget = new Ext.dd.DropTarget(field.el.dom,
  439 + {
  440 + ddGroup: 'explorerTree',
  441 + notifyEnter: function(ddSource, e, data) {
  442 + },
  443 + notifyDrop: function(ddSource, e, data) {
  444 + var selectedRecord = ddSource.dragData.records[0];
  445 + switch (selectedRecord.$className) {
  446 + case 'amdaModel.LocalParamNode' :
  447 + case 'amdaModel.RemoteParamNode' :
  448 + case 'amdaModel.RemoteSimuParamNode' :
  449 + if (!selectedRecord.get('isParameter') || selectedRecord.get('disable'))
  450 + return false;
  451 + if (selectedRecord.get('alias') != "" )
  452 + field.setValue("#"+selectedRecord.get('alias'));
  453 + else
  454 + field.setValue(selectedRecord.get('id'));
  455 + return true;
  456 + case 'amdaModel.AliasNode' :
  457 + if (!selectedRecord.isLeaf())
  458 + return false;
  459 + field.setValue("#"+selectedRecord.get('text'));
  460 + return true;
  461 + case 'amdaModel.DerivedParamNode' :
  462 + if (!selectedRecord.isLeaf())
  463 + return false;
  464 + field.setValue("ws_"+selectedRecord.get('text'));
  465 + return true;
  466 + case 'amdaModel.MyDataParamNode' :
  467 + if (!selectedRecord.isLeaf())
  468 + return false;
  469 + field.setValue("wsd_"+selectedRecord.get('text'));
  470 + return true;
  471 + default:
  472 + return false;
  473 + }
  474 + return true;
  475 + }
  476 + }
  477 + );
  478 + },
  479 + scope: this
  480 + }
  481 + });
  482 +
  483 + this.samplingDefContainer = new Ext.container.Container({
  484 + border: false,
  485 + items: [
  486 + this.timeStepField,
  487 + this.refParamField
  488 + ],
  489 + width: 150
  490 + });
404 491  
405 492 this.formPanel = new Ext.form.Panel({
406 493 id: 'vbox-paramForm',
... ... @@ -411,7 +498,7 @@ Ext.define(&#39;amdaUI.ParameterUI&#39;,
411 498 trackResetOnLoad: true, //reset to the last loaded record
412 499 layout: {
413 500 type: 'vbox',
414   - defaultMargins: {top: 10, left:10, bottom:5, right:5},
  501 + defaultMargins: {top: 5, left:5, bottom:10, right:10},
415 502 align: 'stretch'
416 503 },
417 504 defaults: {
... ... @@ -428,7 +515,8 @@ Ext.define(&#39;amdaUI.ParameterUI&#39;,
428 515 },
429 516 defaultType: 'textfield',
430 517 defaults: {
431   - labelAlign: 'top'
  518 + labelAlign: 'top',
  519 + labelPad: 0
432 520 },
433 521 items: [
434 522 this.fieldName,
... ... @@ -436,17 +524,40 @@ Ext.define(&#39;amdaUI.ParameterUI&#39;,
436 524 xtype:'component', width: 20
437 525 },
438 526 {
439   - xtype : 'numberfield',
440   - itemId: 'formParamTimeStep', fieldLabel: '<img amda_clicktip="resamplingStep" src="js/resources/images/16x16/info_mini.png"/>&nbsp;Time Step (sec)', labelAlign: 'top',
441   - allowBlank : false, blankText : 'Time Step is required',
442   - name : 'timestep',
443   - minValue : 0.001,
444   - decimalPrecision : 10,
445   - hideTrigger: true,
  527 + fieldLabel: 'Last modification',
  528 + xtype: 'displayfield',
  529 + name : 'last_update',
446 530 width: 150,
447   - //validateOnChange: false,
448   - validateOnBlur: false
  531 + renderer: function(value, field) {
  532 + var tpl = new Ext.XTemplate('<p style="font-style:italic;color:gray;margin:0;">{date}</>');
  533 + var mod_date = 'Not saved';
  534 + if (value > 0)
  535 + mod_date = Ext.Date.format(new Date(value*1000), "Y-m-d\\TH:i:s");
  536 + return tpl.apply({date: mod_date});
  537 + },
449 538 },
  539 + {
  540 + xtype: 'combo',
  541 + fieldLabel: 'Sampling mode',
  542 + name: 'sampling_mode',
  543 + queryMode: 'local',
  544 + editable: false,
  545 + valueField: 'id',
  546 + displayField: 'name',
  547 + store: samplingmode_store,
  548 + value: samplingmode_store.first(),
  549 + listeners: {
  550 + change: function(field, value) {
  551 + this.timeStepField.setVisible(value != 'refparam');
  552 + this.refParamField.setVisible(value == 'refparam');
  553 + },
  554 + scope: this
  555 + }
  556 + },
  557 + {
  558 + xtype:'component', width: 20
  559 + },
  560 + this.samplingDefContainer,
450 561 {
451 562 itemId: 'formParamUnit',
452 563 fieldLabel: 'Units',
... ...
php/classes/DerivedParamMgr.php
... ... @@ -138,12 +138,13 @@ class DerivedParamMgr extends AmdaObjectMgr
138 138 {
139 139 if (file_exists(USERWSDIR.'Alias.xml')) {
140 140 $p->buildchain = $this->resetAlias($p->buildchain);
141   - }
  141 + }
  142 + $p->last_update = time();
142 143 // switch between myData and Derived
143 144 $this->createObjectDescription($p);
144 145 $this->addToContent($p, $folder);
145 146  
146   - return array('id' => $this->id, 'info' => $p->buildchain, 'dim_1' => $p->dim_1, 'dim_2' => $p->dim_2);
  147 + return array('id' => $this->id, 'info' => $p->buildchain, 'dim_1' => $p->dim_1, 'dim_2' => $p->dim_2, 'last_update' => $p->last_update);
147 148 }
148 149 // myData parameter
149 150 else
... ... @@ -317,12 +318,13 @@ class DerivedParamMgr extends AmdaObjectMgr
317 318 public function getObject($id)
318 319 {
319 320 if (!file_exists(USERWSDIR.$id.'.xml')) return array('error' => NO_OBJECT_FILE);
320   -
  321 +
321 322 $this->objectDom -> load(USERWSDIR.$id.'.xml');
322 323 if (!($objToGet = $this->objectDom->getElementById($id))) return array('error' => NO_SUCH_ID);
323 324  
324 325 $attributesToReturn['id'] = $objToGet->getAttribute('xml:id');
325 326 $attributes = $objToGet -> childNodes;
  327 + $last_update = 0;
326 328 foreach($attributes as $attribute)
327 329 {
328 330 if ($attribute->tagName === "buildchain") $attributesToReturn[$attribute->tagName] = $this->setAlias($attribute->nodeValue);
... ... @@ -343,7 +345,11 @@ class DerivedParamMgr extends AmdaObjectMgr
343 345 }
344 346 else $attributesToReturn[$attribute->tagName] = $attribute->nodeValue;
345 347 }
346   -
  348 +
  349 + if (empty($attributesToReturn['last_update'])) {
  350 + $attributesToReturn['last_update'] = filemtime(USERWSDIR.$id.'.xml');
  351 + }
  352 +
347 353 return $attributesToReturn;
348 354 }
349 355  
... ...