@@ -61,16 +61,15 @@ const SimputPanel = React.createClass({
6161 var jsonData = this . props . simulation . steps [ this . props . step ] . metadata . model ;
6262
6363 // Create ini file container if not already here
64+ let promise = null ;
6465 if ( ! nwFile ) {
65- simulationsHelper . addEmptyFileForSimulation ( this . props . simulation , 'job.nw' )
66+ promise = simulationsHelper . addEmptyFileForSimulation ( this . props . simulation , 'job.nw' )
6667 . then ( resp => {
6768 const _id = resp . data . _id ; // itemId
6869 this . props . simulation . metadata . inputFolder . files . nw = _id ;
6970 this . setState ( { nwFile : _id } ) ;
70- simulationsHelper . saveSimulation ( this . props . simulation )
71- . then ( ( ) => {
72- this . props . updateSimulation ( this . props . simulation ) ;
73- } ) ;
71+ return simulationsHelper . saveSimulation ( this . props . simulation )
72+ . then ( ( ) => this . props . updateSimulation ( this . props . simulation ) ) ;
7473 } ) ;
7574 } else if ( ! this . state . nwFile ) {
7675 this . setState ( { nwFile } ) ;
@@ -85,14 +84,25 @@ const SimputPanel = React.createClass({
8584 hideViews : [ ] ,
8685 } ;
8786
88- // Update step metadata
89- client . updateSimulationStep ( this . props . simulation . _id , this . props . step , {
90- metadata : { model : JSON . stringify ( jsonData ) } ,
91- } ) . then ( ( resp ) => {
92- var newSim = deepClone ( this . props . simulation ) ;
93- newSim . steps [ this . props . step ] . metadata . model = JSON . stringify ( jsonData ) ;
94- this . props . saveSimulation ( newSim ) ;
95- } ) ;
87+ const updateSimulationStep = ( ) => {
88+ // Update step metadata
89+ client . updateSimulationStep ( this . props . simulation . _id , this . props . step , {
90+ metadata : { model : JSON . stringify ( jsonData ) } ,
91+ } ) . then ( ( resp ) => {
92+ var newSim = deepClone ( this . props . simulation ) ;
93+ newSim . steps [ this . props . step ] . metadata . model = JSON . stringify ( jsonData ) ;
94+ newSim . metadata . here = 'here' ;
95+ this . props . saveSimulation ( newSim ) ;
96+ } ) ;
97+ } ;
98+
99+ // If we have outstanding requests ensure they are chained to avoid lost
100+ // updates.
101+ if ( promise ) {
102+ this . promise . then ( updateSimulationStep ) ;
103+ } else {
104+ updateSimulationStep ( ) ;
105+ }
96106 } else {
97107 if ( typeof jsonData === 'string' ) {
98108 jsonData = JSON . parse ( jsonData ) ;
@@ -177,7 +187,7 @@ const SimputPanel = React.createClass({
177187 const simulationStepIndex = this . props . simulation . disabled . indexOf ( 'Simulation' ) ;
178188 if ( simulationStepIndex !== - 1 ) {
179189 this . props . simulation . disabled . splice ( simulationStepIndex , 1 ) ;
180- // simulationsHelper.updateDisabledSimulationSteps(this.props.simulation);
190+ simulationsHelper . updateDisabledSimulationSteps ( this . props . simulation ) ;
181191 }
182192 } else {
183193 console . log ( 'no .nw file' ) ;
0 commit comments