Skip to content

Commit

Permalink
issue/232 Added offlineStorage.clear (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Jun 8, 2022
1 parent 7b40c7a commit 94dc079
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
7 changes: 7 additions & 0 deletions js/adapt-offlineStorage-scorm.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ export default class OfflineStorageScorm extends Backbone.Controller {
return (this.suspendDataRestored) ? this.scorm.setSuspendData(dataAsString) : false;
}

clear() {
this.temporaryStore = {};
this.suspendDataStore = {};
const dataAsString = JSON.stringify(this.suspendDataStore);
this.scorm.setSuspendData(dataAsString);
}

getCustomStates() {
const isSuspendDataStoreEmpty = _.isEmpty(this.suspendDataStore);
if (!isSuspendDataStoreEmpty && this.suspendDataRestored) {
Expand Down
15 changes: 3 additions & 12 deletions js/adapt-stateful-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class StatefulSession extends Backbone.Controller {

initialize() {
_.bindAll(this, 'beginSession', 'onVisibilityChange', 'endSession');
this.debouncedSaveSession = _.debounce(this.saveSessionState.bind(this), 1);
this.scorm = ScormWrapper.getInstance();
this._trackingIdType = 'block';
this._componentSerializer = null;
Expand Down Expand Up @@ -116,13 +117,14 @@ export default class StatefulSession extends Backbone.Controller {
}

setupEventListeners() {
this.debouncedSaveSession = _.debounce(this.saveSessionState.bind(this), 1);
this.removeEventListeners();
this.listenTo(Adapt.components, 'change:_isComplete', this.debouncedSaveSession);
this.listenTo(Adapt.course, 'change:_isComplete', this.debouncedSaveSession);
if (this._shouldStoreResponses) {
this.listenTo(data, 'change:_isSubmitted change:_userAnswer', this.debouncedSaveSession);
}
this.listenTo(Adapt, {
'app:dataReady': this.restoreSession,
'app:languageChanged': this.onLanguageChanged,
'questionView:recordInteraction': this.onQuestionRecordInteraction,
'tracking:complete': this.onTrackingComplete
Expand Down Expand Up @@ -186,18 +188,7 @@ export default class StatefulSession extends Backbone.Controller {
}

onLanguageChanged() {
// when the user switches language, we need to:
// - reattach the event listeners as the language change triggers a reload of
// the json, which will create brand new collections
// - get and save a fresh copy of the session state. as the json has been reloaded,
// the blocks completion data will be reset (the user is warned that this will
// happen by the language picker extension)
// - check to see if the config requires that the lesson_status be reset to
// 'incomplete'
const config = Adapt.spoor.config;
this.removeEventListeners();
this.setupEventListeners();
this.saveSessionState();
if (config?._reporting?._resetStatusOnLanguageChange !== true) return;
offlineStorage.set('status', 'incomplete');
}
Expand Down

0 comments on commit 94dc079

Please sign in to comment.