Skip to content

Commit

Permalink
Update: Add v1 AAT schemas (Updates: #20) (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-replin authored Jul 31, 2023
1 parent ea9400e commit d6864c3
Show file tree
Hide file tree
Showing 51 changed files with 4,380 additions and 1,916 deletions.
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"framework": ">=3.0.0",
"homepage": "https://github.com/cgkineo/adapt-xAPI",
"issues": "https://github.com/cgkineo/adapt-xAPI/issues",
"displayName": "xAPI",
"extension": "xapi",
"targetAttribute": "_xapi",
"displayName": "xAPI",
"description": "An extension which allows the Experience API (xAPI) to collect data on human performance, stored within a suitable Learning Record Store (LRS).",
"main": "/js/adapt-xapi.js",
"keywords": [
Expand All @@ -17,7 +18,6 @@
"experience api",
"tracking"
],
"targetAttribute": "_xapi",
"license": "GPL-3.0",
"private": true,
"devDependencies": {
Expand Down
264 changes: 132 additions & 132 deletions js/adapt-xapi.js
Original file line number Diff line number Diff line change
@@ -1,173 +1,173 @@
define([
'core/js/adapt',
'./offlineStorage',
'./errorNotificationModel',
'./launchModel',
'./statementModel',
'./stateModel',
'libraries/xapiwrapper.min',
'libraries/url-polyfill',
'libraries/fetch-polyfill',
'libraries/promise-polyfill.min'
'core/js/adapt',
'./offlineStorage',
'./errorNotificationModel',
'./launchModel',
'./statementModel',
'./stateModel',
'libraries/xapiwrapper.min',
'libraries/url-polyfill',
'libraries/fetch-polyfill',
'libraries/promise-polyfill.min'
], function(Adapt, OfflineStorage, ErrorNotificationModel, LaunchModel, StatementModel, StateModel) {

var xAPI = Backbone.Controller.extend({
const xAPI = Backbone.Controller.extend({

_isInitialized: false,
_config: null,
_activityId: null,
_restoredLanguage: null,
_currentLanguage: null,
errorNotificationModel: null,
launchModel: null,
statementModel: null,
stateModel: null,

initialize: function() {
this.listenToOnce(Adapt, 'offlineStorage:prepare', this.onPrepareOfflineStorage);
},

initializeErrorNotification: function() {
var config = this._config._errors;

this.errorNotificationModel = new ErrorNotificationModel(config);
},
_isInitialized: false,
_config: null,
_activityId: null,
_restoredLanguage: null,
_currentLanguage: null,
errorNotificationModel: null,
launchModel: null,
statementModel: null,
stateModel: null,

initialize: function() {
this.listenToOnce(Adapt, 'offlineStorage:prepare', this.onPrepareOfflineStorage);
},

initializeErrorNotification: function() {
const config = this._config._errors;

this.errorNotificationModel = new ErrorNotificationModel(config);
},

initializeLaunch: function() {
this.listenToOnce(Adapt, {
'xapi:launchInitialized': this.onLaunchInitialized,
'xapi:launchFailed': this.onLaunchFailed
});
initializeLaunch: function() {
this.listenToOnce(Adapt, {
'xapi:launchInitialized': this.onLaunchInitialized,
'xapi:launchFailed': this.onLaunchFailed
});

this.launchModel = new LaunchModel();
},
this.launchModel = new LaunchModel();
},

initializeState: function() {
this.listenTo(Adapt, 'xapi:stateLoaded', this.onStateLoaded);
initializeState: function() {
this.listenTo(Adapt, 'xapi:stateLoaded', this.onStateLoaded);

var config = {
activityId: this.getActivityId(),
registration: this.launchModel.get('registration'),
actor: this.launchModel.get('actor')
};
const config = {
activityId: this.getActivityId(),
registration: this.launchModel.get('registration'),
actor: this.launchModel.get('actor')
};

this.stateModel = new StateModel(config, {
wrapper: this.launchModel.getWrapper(),
_tracking: this._config._tracking
});
},
this.stateModel = new StateModel(config, {
wrapper: this.launchModel.getWrapper(),
_tracking: this._config._tracking
});
},

initializeStatement: function() {
var config = {
activityId: this.getActivityId(),
registration: this.launchModel.get('registration'),
revision: this._config._revision || null,
actor: this.launchModel.get('actor'),
contextActivities: this.launchModel.get('contextActivities')
};
initializeStatement: function() {
const config = {
activityId: this.getActivityId(),
registration: this.launchModel.get('registration'),
revision: this._config._revision || null,
actor: this.launchModel.get('actor'),
contextActivities: this.launchModel.get('contextActivities')
};

this.statementModel = new StatementModel(config, {
wrapper: this.launchModel.getWrapper(),
_tracking: this._config._tracking
});
},
this.statementModel = new StatementModel(config, {
wrapper: this.launchModel.getWrapper(),
_tracking: this._config._tracking
});
},

getActivityId: function() {
if (this._activityId) return this._activityId;
getActivityId: function() {
if (this._activityId) return this._activityId;

var lrs = this.launchModel.getWrapper().lrs;
// if using cmi5 the activityId MUST come from the query string for "cmi.defined" statements
var activityId = lrs.activityId || lrs.activity_id || this._config._activityId;
const lrs = this.launchModel.getWrapper().lrs;
// if using cmi5 the activityId MUST come from the query string for "cmi.defined" statements
let activityId = lrs.activityId || lrs.activity_id || this._config._activityId;

// @todo: should activityId be derived from URL? Would suggest not as the domain may not be controlled by the author/vendor
if (!activityId) Adapt.trigger('xapi:activityIdError');
// @todo: should activityId be derived from URL? Would suggest not as the domain may not be controlled by the author/vendor
if (!activityId) Adapt.trigger('xapi:activityIdError');

// remove trailing slash if included
activityId = activityId.replace(/\/?$/, "");
// remove trailing slash if included
activityId = activityId.replace(/\/?$/, '');

return activityId;
},
return activityId;
},

// @todo: offlineStorage conflict with adapt-contrib-spoor
onPrepareOfflineStorage: function() {
this._config = Adapt.config.get('_xapi');
// @todo: offlineStorage conflict with adapt-contrib-spoor
onPrepareOfflineStorage: function() {
this._config = Adapt.config.get('_xapi');

if (this._config && this._config._isEnabled) {
Adapt.wait.begin();
if (this._config && this._config._isEnabled) {
Adapt.wait.begin();

Adapt.offlineStorage.initialize(OfflineStorage);
Adapt.offlineStorage.initialize(OfflineStorage);

this.initializeErrorNotification();
this.initializeLaunch();
}
},
this.initializeErrorNotification();
this.initializeLaunch();
}
},

onLaunchInitialized: function() {
this._activityId = this.getActivityId();
onLaunchInitialized: function() {
this._activityId = this.getActivityId();

if (!this._activityId) {
this.onLaunchFailed();
if (!this._activityId) {
this.onLaunchFailed();

return;
}
return;
}

this.listenToOnce(Adapt, {
'offlineStorage:ready': this.onOfflineStorageReady,
'app:dataLoaded': this.onDataLoaded,
'adapt:initialize': this.onAdaptInitialize
});
this.listenToOnce(Adapt, {
'offlineStorage:ready': this.onOfflineStorageReady,
'app:dataLoaded': this.onDataLoaded,
'adapt:initialize': this.onAdaptInitialize
});

this.listenTo(Adapt, {
'app:languageChanged': this.onLanguageChanged
});
this.listenTo(Adapt, {
'app:languageChanged': this.onLanguageChanged
});

this.initializeState();
this.initializeStatement();
},
this.initializeState();
this.initializeStatement();
},

onLaunchFailed: function() {
Adapt.wait.end();
onLaunchFailed: function() {
Adapt.wait.end();

Adapt.offlineStorage.setReadyStatus();
},
Adapt.offlineStorage.setReadyStatus();
},

onOfflineStorageReady: function() {
this._restoredLanguage = Adapt.offlineStorage.get('lang');
},
onOfflineStorageReady: function() {
this._restoredLanguage = Adapt.offlineStorage.get('lang');
},

onLanguageChanged: function(lang) {
var languageConfig = Adapt.config.get('_languagePicker');
onLanguageChanged: function(lang) {
const languageConfig = Adapt.config.get('_languagePicker');

if (languageConfig && languageConfig._isEnabled && this._restoredLanguage !== lang && this._currentLanguage !== lang) {
// only reset if language has changed since the course was started - not neccessary before
var resetState = this._isInitialized && !languageConfig._restoreStateOnLanguageChange;
if (languageConfig && languageConfig._isEnabled && this._restoredLanguage !== lang && this._currentLanguage !== lang) {
// only reset if language has changed since the course was started - not neccessary before
const resetState = this._isInitialized && !languageConfig._restoreStateOnLanguageChange;

// @todo: only send when via a user selection? If `"_showOnCourseLoad": false`, this will still be triggered
Adapt.trigger('xapi:languageChanged', lang, resetState);
}
// @todo: only send when via a user selection? If `"_showOnCourseLoad": false`, this will still be triggered
Adapt.trigger('xapi:languageChanged', lang, resetState);
}

this._restoredLanguage = null;
this._currentLanguage = lang;
},
this._restoredLanguage = null;
this._currentLanguage = lang;
},

onStateLoaded: function() {
Adapt.wait.end();
onStateLoaded: function() {
Adapt.wait.end();

Adapt.offlineStorage.setReadyStatus();
},
Adapt.offlineStorage.setReadyStatus();
},

onDataLoaded: function() {
var globals = Adapt.course.get('_globals');
if (!globals._learnerInfo) globals._learnerInfo = {};
globals._learnerInfo = Adapt.offlineStorage.get('learnerinfo');
},
onDataLoaded: function() {
const globals = Adapt.course.get('_globals');
if (!globals._learnerInfo) globals._learnerInfo = {};
globals._learnerInfo = Adapt.offlineStorage.get('learnerinfo');
},

onAdaptInitialize: function() {
this._isInitialized = true;
}
onAdaptInitialize: function() {
this._isInitialized = true;
}

});
});

return new xAPI();
return new xAPI();

});
Loading

0 comments on commit d6864c3

Please sign in to comment.