Commit d794a307c8262ffd1f8518b96d328e484e55bfa9

Authored by Benjamin Renard
1 parent b9c5d84e

Fix bug when a plot rquest is overwriten

js/app/models/PlotObjects/MultiplotRequestObject.js
@@ -67,6 +67,25 @@ Ext.define('amdaPlotObj.MultiplotRequestObject', { @@ -67,6 +67,25 @@ Ext.define('amdaPlotObj.MultiplotRequestObject', {
67 return newPlotNode; 67 return newPlotNode;
68 }, 68 },
69 69
  70 + overwritePlot: function(plotNode, targetPlotNode) {
  71 + var targetIndex = -1;
  72 + this.plots().each(function(node, index) {
  73 + if (node == targetPlotNode) {
  74 + targetIndex = index;
  75 + }
  76 + });
  77 + if (targetIndex < 0) {
  78 + //Target not exists in multiplot node => add it
  79 + this.plots().add(targetPlotNode);
  80 + targetIndex = this.plots().count() - 1;
  81 + }
  82 + var data = plotNode.get('object').getJsonValues();
  83 + data.id = targetPlotNode.get('id');
  84 + targetPlotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', data));
  85 + plotNode.get('object').reject();
  86 + return targetPlotNode;
  87 + },
  88 +
70 createNewPlotFromObject: function(plotObject) { 89 createNewPlotFromObject: function(plotObject) {
71 var plotNode = Ext.create('amdaModel.PlotNode', { 90 var plotNode = Ext.create('amdaModel.PlotNode', {
72 leaf : true 91 leaf : true
js/app/views/PlotComponents/PlotTabContent.js
@@ -112,27 +112,40 @@ Ext.define(&#39;amdaPlotComp.PlotTabContent&#39;, { @@ -112,27 +112,40 @@ Ext.define(&#39;amdaPlotComp.PlotTabContent&#39;, {
112 }); 112 });
113 }, 113 },
114 114
115 - saveProcess : function(toRename) { 115 + saveProcess : function(overwriteExistingNode) {
  116 + var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);
  117 + if (!plotModule)
  118 + return;
  119 +
116 var me = this; 120 var me = this;
117 - if (toRename) { 121 + if (overwriteExistingNode) {
118 this.updateTimeObject(); 122 this.updateTimeObject();
119 - this.plotNode.update({plot: true, callback: function() {  
120 - me.setPlotNode(me.plotNode); //to update initial request data  
121 - me.plotTabPanel.updatePlotTabs();  
122 - }}); 123 + amdaModel.InteractiveNode.preloadNodes(this.plotNode.getRootNode(), function () {
  124 + var targetPlotNode = me.plotNode.getRootNode().findChild('text', me.plotNode.get('object').get('name'), true);
  125 + if (!targetPlotNode) {
  126 + myDesktopApp.errorMsg('Cannot retrieve request node');
  127 + return;
  128 + }
  129 + targetPlotNode = plotModule.linkedNode.get('object').overwritePlot(me.plotNode, targetPlotNode);
  130 + if (targetPlotNode) {
  131 + //Reject modifications in old plot node
  132 + me.resetModif();
  133 + targetPlotNode.update({plot: true, callback: function() {
  134 + me.setPlotNode(targetPlotNode);
  135 + me.plotTabPanel.updatePlotTabs();
  136 + me.updateUI();
  137 + }});
  138 + }
  139 + });
123 } 140 }
124 else { 141 else {
125 if (this.plotNode.get('object').get('id') != '') { 142 if (this.plotNode.get('object').get('id') != '') {
126 //Duplicate request 143 //Duplicate request
127 - var plotModule = myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.plot.id);  
128 - if (!plotModule)  
129 - return;  
130 - var newPlotNode = plotModule.linkedNode.get('object').duplicatePlot(this.plotNode); 144 + var newPlotNode = this.plotTabPanel.duplicatePlotNode(this.plotNode);
131 if (newPlotNode) { 145 if (newPlotNode) {
132 //Reject modifications in old plot node 146 //Reject modifications in old plot node
133 - this.plotNode.reject();  
134 - this.plotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', this.initialObjectData));  
135 - //Set new plot node 147 + this.resetModif();
  148 + //Set new plot node to the current tab
136 this.setPlotNode(newPlotNode); 149 this.setPlotNode(newPlotNode);
137 } 150 }
138 } 151 }
@@ -146,6 +159,10 @@ Ext.define(&#39;amdaPlotComp.PlotTabContent&#39;, { @@ -146,6 +159,10 @@ Ext.define(&#39;amdaPlotComp.PlotTabContent&#39;, {
146 } 159 }
147 }, 160 },
148 161
  162 + resetModif : function() {
  163 + this.plotNode.set('object', Ext.create('amdaPlotObj.PlotRequestObject', this.initialObjectData));
  164 + },
  165 +
149 getDataProcess : function() { 166 getDataProcess : function() {
150 var downObject = amdaModel.DownloadNode.decodeObject(this.plotNode.get('object')); 167 var downObject = amdaModel.DownloadNode.decodeObject(this.plotNode.get('object'));
151 amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject)); 168 amdaModel.DownloadNode.set('object',Ext.create('amdaModel.Download',downObject));
js/app/views/PlotComponents/PlotTabPanel.js
@@ -88,10 +88,14 @@ Ext.define(&#39;amdaPlotComp.PlotTabPanel&#39;, { @@ -88,10 +88,14 @@ Ext.define(&#39;amdaPlotComp.PlotTabPanel&#39;, {
88 }, 88 },
89 close: function( tab, eOpts ) { 89 close: function( tab, eOpts ) {
90 if (tab.items.getAt(0).plotNode) { 90 if (tab.items.getAt(0).plotNode) {
  91 + tab.items.getAt(0).resetModif();
91 this.multiplot_object.removePlotByInternalId(tab.items.getAt(0).plotNode.internalId); 92 this.multiplot_object.removePlotByInternalId(tab.items.getAt(0).plotNode.internalId);
92 } 93 }
93 }, 94 },
94 destroy: function(tab, eOpts) { 95 destroy: function(tab, eOpts) {
  96 + if (tab.items.getAt(0) && tab.items.getAt(0).plotNode) {
  97 + tab.items.getAt(0).resetModif();
  98 + }
95 if (!this.tabbar_destroy) 99 if (!this.tabbar_destroy)
96 this.updatePlotTabs(); 100 this.updatePlotTabs();
97 } 101 }
@@ -103,6 +107,14 @@ Ext.define(&#39;amdaPlotComp.PlotTabPanel&#39;, { @@ -103,6 +107,14 @@ Ext.define(&#39;amdaPlotComp.PlotTabPanel&#39;, {
103 107
104 return tabContent; 108 return tabContent;
105 }, 109 },
  110 +
  111 + duplicatePlotNode: function(plotNode)
  112 + {
  113 + var newPlotNode = this.multiplot_object.duplicatePlot(plotNode);
  114 + if (!newPlotNode)
  115 + return null;
  116 + return newPlotNode;
  117 + },
106 118
107 updatePlotTabs: function() 119 updatePlotTabs: function()
108 { 120 {
@@ -119,6 +131,18 @@ Ext.define(&#39;amdaPlotComp.PlotTabPanel&#39;, { @@ -119,6 +131,18 @@ Ext.define(&#39;amdaPlotComp.PlotTabPanel&#39;, {
119 } 131 }
120 }, 132 },
121 133
  134 + closePlotTabIfOpened: function(plotNodeToClose) {
  135 + for (i = 0; i < this.items.getCount(); ++i)
  136 + {
  137 + var tabItem = this.items.getAt(i);
  138 + var tabContent = tabItem.items.getAt(0);
  139 + var plotNode = tabContent.plotNode;
  140 + if (plotNode == renamedNode) {
  141 + this.remove(tabItem.getId());
  142 + }
  143 + }
  144 + },
  145 +
122 updateRequestName: function(renamedNode) 146 updateRequestName: function(renamedNode)
123 { 147 {
124 for (i = 0; i < this.items.getCount(); ++i) 148 for (i = 0; i < this.items.getCount(); ++i)