diff --git a/app/components/exp-player/component.js b/app/components/exp-player/component.js
index 8fcdb49c..1b4d869d 100644
--- a/app/components/exp-player/component.js
+++ b/app/components/exp-player/component.js
@@ -17,7 +17,6 @@ let {
* experiment=experiment
* session=session
* pastSessions=pastSessions
- * saveHandler=(action 'saveSession')
* frameIndex=0
* fullScreenElementId='expContainer'}}
* ```
@@ -33,6 +32,10 @@ export default Ember.Component.extend(FullScreen, {
frames: null,
conditions: null,
+ // Store sequence and expData on the component so we can update them immediately, then transfer to session
+ _sequence: [],
+ _expData: {},
+
frameIndex: 0, // Index of the currently active frame
displayFullscreen: false,
@@ -207,16 +210,20 @@ export default Ember.Component.extend(FullScreen, {
},
saveFrame(frameId, frameData) {
- // Save the data from a completed frame to the session data item
- if (this.get('session.sequence') && frameId != this.get('session.sequence')[this.get('session.sequence').length - 1]) {
- this.get('session.sequence').push(frameId);
- }
- this.get('session.expData')[frameId] = frameData;
- if (!this.get('session').child.content || this.get('session').child.content.id === 'TEST_CHILD_DISREGARD') {
- return Ember.RSVP.Promise.resolve();
- } else {
- return this.get('session').save();
+ // Save the data from a completed frame to the session data item. Add to sequence and
+ if (frameId != this.get('_sequence')[this.get('_sequence').length - 1]) {
+ this.get('_sequence').push(frameId);
}
+ this.get('_expData')[frameId] = frameData;
+ this.get('session').set('sequence', this.get('_sequence'));
+ this.get('session').set('expData', this.get('_expData'));
+ // This takes a second or so! If we directly manipulate session.sequence and session.expData, we can
+ // end up with overlapping calls to save() that lead to data being lost. Because all of the above steps
+ // can be done immediately, we can keep _sequence and _expData current (and in the correct order) so that
+ // when we save the session we don't lose any information. (Alternately we can keep track of whether we're
+ // currently saving, defer the save if so, and use e.g.
+ // this.get('session').save().finally(() => {_this.set('_saving', false);})
+ return this.get('session').save();
},
next(nextFrameIndex = -1) {
@@ -267,7 +274,7 @@ export default Ember.Component.extend(FullScreen, {
exitType: 'manualInterrupt', // User consciously chose to exit, eg by pressing F1 key
lastPageSeen: this.get('frameIndex') + 1
});
- this.get('session').save(); // I think this is the response
+ this.get('session').save();
// Navigate to last page in experiment (assumed to be survey frame)
var max = this.get('frames.length') - 1;
diff --git a/app/controllers/participate.js b/app/controllers/participate.js
index 18d49649..488cc414 100644
--- a/app/controllers/participate.js
+++ b/app/controllers/participate.js
@@ -7,11 +7,5 @@ export default Ember.Controller.extend({
return response.get('hasDirtyAttributes');
},
actions: {
- saveResponse(payload, callback) {
- var response = this.get('response');
- response.setProperties(payload);
- response.save().then(callback);
- this.set('response', response);
- }
}
});
diff --git a/app/controllers/preview-without-saving.js b/app/controllers/preview-without-saving.js
index 5f001bd3..b2d49fc5 100644
--- a/app/controllers/preview-without-saving.js
+++ b/app/controllers/preview-without-saving.js
@@ -17,12 +17,6 @@ export default Participate.extend({
toggleData() {
this.toggleProperty('showData');
this.get('_resolve')();
- },
- saveResponse(payload, callback) {
- var response = this.get('response');
- response.setProperties(payload);
- response.save().then(callback);
- this.set('response', response);
}
}
});
diff --git a/app/templates/participate.hbs b/app/templates/participate.hbs
index 6e7ee942..e2c8dc1e 100644
--- a/app/templates/participate.hbs
+++ b/app/templates/participate.hbs
@@ -11,7 +11,6 @@
experiment=study
session=response
pastSessions=pastResponses
- saveHandler=(action "saveResponse")
frameIndex=0
fullScreenElementId="expContainer"
}}
diff --git a/app/templates/preview-without-saving.hbs b/app/templates/preview-without-saving.hbs
index f21729e3..f53b8155 100644
--- a/app/templates/preview-without-saving.hbs
+++ b/app/templates/preview-without-saving.hbs
@@ -11,7 +11,6 @@
experiment=study
session=response
pastSessions=pastResponses
- saveHandler=(action "saveResponse")
frameIndex=0
fullScreenElementId="expContainer"
}}
diff --git a/app/templates/preview.hbs b/app/templates/preview.hbs
index aca24e06..5427eed8 100644
--- a/app/templates/preview.hbs
+++ b/app/templates/preview.hbs
@@ -11,7 +11,6 @@
experiment=study
session=response
pastSessions=pastResponses
- saveHandler=(action "saveResponse")
frameIndex=0
fullScreenElementId="expContainer"
}}