Commit 2048f5bc38e3f243827410e3906fdb39703ff952

Authored by Benjamin Renard
1 parent fac46f96

Fix save & edit plot

js/app/controllers/InteractiveModule.js
@@ -37,12 +37,15 @@ Ext.define('amdaDesktop.InteractiveModule', { @@ -37,12 +37,15 @@ Ext.define('amdaDesktop.InteractiveModule', {
37 /** 37 /**
38 * Window Creation method of the Module 38 * Window Creation method of the Module
39 */ 39 */
40 - createWindow : function (onShowEvent) { 40 + createWindow : function (onShowEvent, onAfterCreateObject) {
41 41
42 if (this.linkedNode === null){ 42 if (this.linkedNode === null){
43 this.createLinkedNode(); 43 this.createLinkedNode();
44 } 44 }
45 - this.createObject(); 45 + this.createObject();
  46 + if (onAfterCreateObject) {
  47 + onAfterCreateObject();
  48 + }
46 var desktop = this.app.getDesktop(); 49 var desktop = this.app.getDesktop();
47 var win = desktop.getWindow(this.id); 50 var win = desktop.getWindow(this.id);
48 var me = this; 51 var me = this;
js/app/controllers/PlotModule.js
@@ -212,5 +212,25 @@ Ext.define('amdaDesktop.PlotModule', { @@ -212,5 +212,25 @@ Ext.define('amdaDesktop.PlotModule', {
212 me.getUiContent().addParameter(paramNode, true); 212 me.getUiContent().addParameter(paramNode, true);
213 }); 213 });
214 } 214 }
  215 + },
  216 +
  217 + editPlot : function(plotNode) {
  218 + var me = this;
  219 + var desktop = this.app.getDesktop();
  220 + var win = desktop.getWindow(this.id);
  221 + if (win) {
  222 + // Plot UI is opened => add plot in a new tab
  223 + me.getUiContent().editPlot(plotNode);
  224 + win.show();
  225 + }
  226 + else {
  227 + // Plot UI is closed
  228 + this.createWindow(null, function() {
  229 + //This is the onAfterCreateObject callback
  230 + //Add plot node to the multiplot object
  231 + me.linkedNode.get('object').plots().removeAll();
  232 + me.linkedNode.get('object').plots().add(plotNode);
  233 + });
  234 + }
215 } 235 }
216 }); 236 });
js/app/models/PlotNode.js
@@ -95,5 +95,17 @@ Ext.define('amdaModel.PlotNode', { @@ -95,5 +95,17 @@ Ext.define('amdaModel.PlotNode', {
95 default: 95 default:
96 break; 96 break;
97 } 97 }
  98 + },
  99 +
  100 + //Override editInModule
  101 + editInModule : function (contextNode, onReady)
  102 + {
  103 + // set the contextNode of this node
  104 + this.set('contextNode',contextNode);
  105 +
  106 + var me = this;
  107 + myDesktopApp.getLoadedModule(this.get('moduleId'),true, function (module) {
  108 + module.editPlot(me);
  109 + });
98 } 110 }
99 }); 111 });
js/app/models/PlotObjects/MultiplotRequestObject.js
@@ -62,7 +62,6 @@ Ext.define('amdaPlotObj.MultiplotRequestObject', { @@ -62,7 +62,6 @@ Ext.define('amdaPlotObj.MultiplotRequestObject', {
62 createNewPlotFromObject: function(plotObject) { 62 createNewPlotFromObject: function(plotObject) {
63 var plotNode = Ext.create('amdaModel.PlotNode', { 63 var plotNode = Ext.create('amdaModel.PlotNode', {
64 leaf : true, 64 leaf : true,
65 - contextNode : this  
66 }); 65 });
67 plotNode.set('object',plotObject); 66 plotNode.set('object',plotObject);
68 this.plots().add(plotNode); 67 this.plots().add(plotNode);
js/app/views/PlotComponents/PlotTabContent.js
@@ -83,7 +83,10 @@ Ext.define('amdaPlotComp.PlotTabContent', { @@ -83,7 +83,10 @@ Ext.define('amdaPlotComp.PlotTabContent', {
83 width: 300, 83 width: 300,
84 buttons: Ext.Msg.OKCANCEL, 84 buttons: Ext.Msg.OKCANCEL,
85 icon: Ext.Msg.WARNING, 85 icon: Ext.Msg.WARNING,
86 - fn : me.overwritePlot, 86 + fn : function(btn) {
  87 + if (btn == 'cancel') return;
  88 + me.saveProcess(true);
  89 + },
87 scope : me 90 scope : me
88 }); 91 });
89 } 92 }
@@ -100,11 +103,6 @@ Ext.define('amdaPlotComp.PlotTabContent', { @@ -100,11 +103,6 @@ Ext.define('amdaPlotComp.PlotTabContent', {
100 }); 103 });
101 }, 104 },
102 105
103 - overwritePlot : function(btn) {  
104 - if (btn == 'cancel') return;  
105 - this.saveProcess(true);  
106 - },  
107 -  
108 saveProcess : function(toRename) { 106 saveProcess : function(toRename) {
109 if (toRename) { 107 if (toRename) {
110 this.plotNode.update(); 108 this.plotNode.update();
js/app/views/PlotComponents/PlotTabPanel.js
@@ -38,6 +38,17 @@ Ext.define('amdaPlotComp.PlotTabPanel', { @@ -38,6 +38,17 @@ Ext.define('amdaPlotComp.PlotTabPanel', {
38 38
39 addPlotNode: function(plotNode, selectTab) 39 addPlotNode: function(plotNode, selectTab)
40 { 40 {
  41 + for (i = 0; i < this.items.getCount(); ++i)
  42 + {
  43 + var tabItem = this.items.getAt(i);
  44 + var tabContent = tabItem.items.getAt(0);
  45 + if (plotNode == tabContent.plotNode) {
  46 + //Already opened => select tab
  47 + this.setActiveTab(tabItem);
  48 + return;
  49 + }
  50 + }
  51 +
41 var tabNumber = this.getTabBar().items.getCount(); 52 var tabNumber = this.getTabBar().items.getCount();
42 var tabContent = new amdaPlotComp.PlotTabContent({plotNode: plotNode, tabIndex: tabNumber-1}); 53 var tabContent = new amdaPlotComp.PlotTabContent({plotNode: plotNode, tabIndex: tabNumber-1});
43 var me = this; 54 var me = this;
js/app/views/PlotUI.js
@@ -69,6 +69,10 @@ Ext.define(&#39;amdaUI.PlotUI&#39;, { @@ -69,6 +69,10 @@ Ext.define(&#39;amdaUI.PlotUI&#39;, {
69 } 69 }
70 } 70 }
71 }, 71 },
  72 +
  73 + editPlot : function(plotNode) {
  74 + this.plotTabs.addPlotNode(plotNode, true);
  75 + },
72 76
73 /** 77 /**
74 * plot method called by 'Do Plot' button to launch the plot process 78 * plot method called by 'Do Plot' button to launch the plot process
php/classes/AmdaAction.php
@@ -151,7 +151,6 @@ class AmdaAction @@ -151,7 +151,6 @@ class AmdaAction
151 $isParameter = false; 151 $isParameter = false;
152 $isAddable = false; 152 $isAddable = false;
153 $isSimulation = false; 153 $isSimulation = false;
154 - $plotTabs = FALSE;  
155 $rank = null; 154 $rank = null;
156 $skip = FALSE; 155 $skip = FALSE;
157 156
@@ -185,19 +184,6 @@ class AmdaAction @@ -185,19 +184,6 @@ class AmdaAction
185 else { 184 else {
186 $info = $id; 185 $info = $id;
187 } 186 }
188 -  
189 - $isLeaf = isset($objplot->tabs);  
190 - if ($isLeaf) {  
191 - $plotTabs = array();  
192 - foreach ($objplot->tabs as $index => $tab) {  
193 - $plotTabs[$index] = array(  
194 - "name" => (!empty($tab->{'tab-name'})) ? $tab->{'tab-name'} : "Plot ".($index+1),  
195 - "id" => $tab->id,  
196 - );  
197 - }  
198 - }  
199 - else  
200 - $plotTabs = FALSE;  
201 break; 187 break;
202 188
203 // case 'alias': 189 // case 'alias':
@@ -597,7 +583,7 @@ class AmdaAction @@ -597,7 +583,7 @@ class AmdaAction
597 } 583 }
598 584
599 $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info, 585 $childrenToReturn[] = array('text' => $name, 'id' => $id, 'nodeType' => $nodeType, 'info' => $info,
600 - 'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'dim_1' => $dim_1, 'dim_2' => $dim_2, 'tabs' => $plotTabs, 586 + 'help' => $help, 'leaf' => $isLeaf, 'isParameter' => $isParameter, 'dim_1' => $dim_1, 'dim_2' => $dim_2,
601 'component_info' => isset($component_info) ? $component_info : NULL, 587 'component_info' => isset($component_info) ? $component_info : NULL,
602 'iconCls' => isset($iconCls) ? $iconCls : NULL ); 588 'iconCls' => isset($iconCls) ? $iconCls : NULL );
603 } 589 }
@@ -826,7 +812,6 @@ class AmdaAction @@ -826,7 +812,6 @@ class AmdaAction
826 break; 812 break;
827 case 'condition' : 813 case 'condition' :
828 case 'request' : 814 case 'request' :
829 - case 'plottab' :  
830 $objectMgr = new RequestMgr($obj->nodeType); 815 $objectMgr = new RequestMgr($obj->nodeType);
831 break; 816 break;
832 case 'alias' : 817 case 'alias' :
@@ -916,7 +901,6 @@ class AmdaAction @@ -916,7 +901,6 @@ class AmdaAction
916 break; 901 break;
917 case 'condition' : 902 case 'condition' :
918 case 'request' : 903 case 'request' :
919 - case 'plottab' :  
920 $objectMgr = new RequestMgr($obj->nodeType); 904 $objectMgr = new RequestMgr($obj->nodeType);
921 break; 905 break;
922 default: 906 default:
php/classes/RequestMgr.php
@@ -30,7 +30,7 @@ class RequestMgr extends AmdaObjectMgr @@ -30,7 +30,7 @@ class RequestMgr extends AmdaObjectMgr
30 $this->attributes = array('name' => ''); 30 $this->attributes = array('name' => '');
31 $this->optionalAttributes = array(); 31 $this->optionalAttributes = array();
32 32
33 - if ($type == 'request' || $type == 'plottab') 33 + if ($type == 'request' )
34 { 34 {
35 $this->id_prefix = 'req_'; 35 $this->id_prefix = 'req_';
36 } 36 }
@@ -73,47 +73,11 @@ class RequestMgr extends AmdaObjectMgr @@ -73,47 +73,11 @@ class RequestMgr extends AmdaObjectMgr
73 73
74 public function validNameObject($p) 74 public function validNameObject($p)
75 { 75 {
76 - if ($this->type == 'plottab') {  
77 - if (empty($p->name)) {  
78 - return array('valid' => false, 'error' => 'Name is required');  
79 - }  
80 - return array('valid' => true);  
81 - }  
82 return parent::validNameObject($p); 76 return parent::validNameObject($p);
83 } 77 }
84 78
85 public function renameObject($p) 79 public function renameObject($p)
86 { 80 {
87 - if ($this->type == 'plottab') {  
88 - //Rename a plot tab  
89 - if (!isset($p->parent) || empty($p->parent)) {  
90 - return array('error' => 'Missing parent definition');  
91 - }  
92 - $plotObj = $this->getObject($p->parent);  
93 - if (is_array($plotObj) && isset($plotObj['error'])) {  
94 - return array('error' => $plotObj['error']);  
95 - }  
96 - if (!isset($plotObj->tabs)) {  
97 - return array('error' => 'Cannot retrieve tab in plot request');  
98 - }  
99 - $renameOK = FALSE;  
100 - foreach ($plotObj->tabs as &$tab) {  
101 - if ($tab->id == $p->id) {  
102 - $tab->{'tab-name'} = $p->name;  
103 - $renameOK = TRUE;  
104 - break;  
105 - }  
106 - }  
107 - if (!$renameOK) {  
108 - return array('error' => 'Cannot retrieve tab in plot request 2');  
109 - }  
110 - //Save modification  
111 - $file = fopen(USERREQDIR.$p->parent, 'w');  
112 - fwrite($file, json_encode($plotObj));  
113 - fclose($file);  
114 -  
115 - return array('id' => $p->id);  
116 - }  
117 return parent::renameObject($p); 81 return parent::renameObject($p);
118 } 82 }
119 83
@@ -225,17 +189,6 @@ class RequestMgr extends AmdaObjectMgr @@ -225,17 +189,6 @@ class RequestMgr extends AmdaObjectMgr
225 } 189 }
226 190
227 $additional = array(); 191 $additional = array();
228 - if ($this->type == 'request') {  
229 - $additional['tabs'] = array();  
230 - if (isset($p->tabs)) {  
231 - foreach ($p->tabs as $index => $tab) {  
232 - $additional['tabs'][$index] = array(  
233 - "name" => (!empty($tab->{'tab-name'})) ? $tab->{'tab-name'} : "Plot ".($index+1),  
234 - "id" => $tab->id,  
235 - );  
236 - }  
237 - }  
238 - }  
239 192
240 $this->descFileName = USERREQDIR.$this->id; 193 $this->descFileName = USERREQDIR.$this->id;
241 $p->id = $this->id; 194 $p->id = $this->id;