Skip to content

Commit

Permalink
issue/2799 Remove redundant behaviour (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Apr 11, 2022
1 parent 50d59cc commit 2ff3e0e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "adapt-contrib-xapi",
"version": "0.9.5",
"framework": ">=5.8",
"framework": ">=5.19.1",
"homepage": "https://github.com/adaptlearning/adapt-contrib-xapi",
"authors": [
"Dennis Heaney <[email protected]>",
Expand Down
57 changes: 31 additions & 26 deletions js/XAPI.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import Adapt from 'core/js/adapt';
import data from 'core/js/data';
import COMPLETION_STATE from 'core/js/enums/completionStateEnum';
import logging from 'core/js/logging';
import notify from 'core/js/notify';
import offlineStorage from 'core/js/offlineStorage';
import wait from 'core/js/wait';
import XAPIWrapper from 'libraries/xapiwrapper.min';

class XAPI extends Backbone.Model {
Expand Down Expand Up @@ -64,7 +69,7 @@ class XAPI extends Backbone.Model {
async initialize() {
if (!this.getConfig('_isEnabled')) return this;

Adapt.wait.begin();
wait.begin();

// Initialize the xAPIWrapper.
try {
Expand Down Expand Up @@ -97,7 +102,7 @@ class XAPI extends Backbone.Model {

if (!this.validateProps()) {
const error = new Error('Missing required properties');
Adapt.log.error('adapt-contrib-xapi: xAPI Wrapper initialisation failed', error);
logging.error('adapt-contrib-xapi: xAPI Wrapper initialisation failed', error);
this.onInitialised(error);
return this;
}
Expand Down Expand Up @@ -167,7 +172,7 @@ class XAPI extends Backbone.Model {
globals._learnerInfo = {};
}

Object.assign(globals._learnerInfo, Adapt.offlineStorage.get('learnerinfo'));
Object.assign(globals._learnerInfo, offlineStorage.get('learnerinfo'));
}

/**
Expand Down Expand Up @@ -234,7 +239,7 @@ class XAPI extends Backbone.Model {
onInitialised(error) {
this.set({ isInitialised: !error });

Adapt.wait.end();
wait.end();

_.defer(() => {
if (error) {
Expand Down Expand Up @@ -316,7 +321,7 @@ class XAPI extends Backbone.Model {
val = val.replace(/\/?$/, '/');

if (!/^https?:\/\//i.test(val)) {
Adapt.log.warn('adapt-contrib-xapi: "_endpoint" value is missing protocol (defaulting to http://)');
logging.warn('adapt-contrib-xapi: "_endpoint" value is missing protocol (defaulting to http://)');

val = 'http://' + val;
}
Expand All @@ -342,7 +347,7 @@ class XAPI extends Backbone.Model {
getBaseUrl() {
const url = window.location.origin + window.location.pathname;

Adapt.log.info(`adapt-contrib-xapi: Using detected URL (${url}) as ActivityID`);
logging.info(`adapt-contrib-xapi: Using detected URL (${url}) as ActivityID`);

return url;
}
Expand Down Expand Up @@ -393,7 +398,7 @@ class XAPI extends Backbone.Model {

setupListeners() {
if (!this.get('isInitialised')) {
Adapt.log.warn('adapt-contrib-xapi: Unable to setup listeners for xAPI');
logging.warn('adapt-contrib-xapi: Unable to setup listeners for xAPI');
return;
}

Expand Down Expand Up @@ -730,7 +735,7 @@ class XAPI extends Backbone.Model {
*/
getLessonActivity(page) {
const pageModel = (typeof page === 'string')
? Adapt.findById(page)
? data.findById(page)
: page;
const activity = new window.ADL.XAPIStatement.Activity(this.getUniqueIri(pageModel));
const name = this.getNameObject(pageModel);
Expand Down Expand Up @@ -864,7 +869,7 @@ class XAPI extends Backbone.Model {
verb = window.ADL.verbs[key];

if (!verb) {
Adapt.log.error(`adapt-contrib-xapi: Verb " ${key} " does not exist in window.ADL.verbs object`);
logging.error(`adapt-contrib-xapi: Verb " ${key} " does not exist in window.ADL.verbs object`);
}
}

Expand Down Expand Up @@ -968,7 +973,7 @@ class XAPI extends Backbone.Model {
if (restoreModel) {
restoreModel.setTrackableState(stateObject);
} else {
Adapt.log.warn('adapt-contrib-xapi: Unable to restore state for component: ' + stateObject._id);
logging.warn('adapt-contrib-xapi: Unable to restore state for component: ' + stateObject._id);
}
});
}
Expand All @@ -980,7 +985,7 @@ class XAPI extends Backbone.Model {
if (restoreModel) {
restoreModel.setTrackableState(stateObject);
} else {
Adapt.log.warn('adapt-contrib-xapi: Unable to restore state for block: ' + stateObject._id);
logging.warn('adapt-contrib-xapi: Unable to restore state for block: ' + stateObject._id);
}
});
}
Expand Down Expand Up @@ -1084,12 +1089,12 @@ class XAPI extends Backbone.Model {
await new Promise((resolve, reject) => {
this.xapiWrapper.getState(activityId, actor, type, registration, null, (error, xhr) => {
if (error) {
Adapt.log.warn(`adapt-contrib-xapi: getState() failed for ${activityId} (${type})`);
logging.warn(`adapt-contrib-xapi: getState() failed for ${activityId} (${type})`);
return reject(new Error(error));
}

if (!xhr) {
Adapt.log.warn(`adapt-contrib-xapi: getState() failed for ${activityId} (${type})`);
logging.warn(`adapt-contrib-xapi: getState() failed for ${activityId} (${type})`);
return reject(new Error('\'xhr\' parameter is missing from callback'));
}

Expand All @@ -1098,7 +1103,7 @@ class XAPI extends Backbone.Model {
}

if (xhr.status !== 200) {
Adapt.log.warn(`adapt-contrib-xapi: getState() failed for ${activityId} (${type})`);
logging.warn(`adapt-contrib-xapi: getState() failed for ${activityId} (${type})`);
return reject(new Error(`Invalid status code ${xhr.status} returned from getState() call`));
}

Expand All @@ -1122,7 +1127,7 @@ class XAPI extends Backbone.Model {
});
}
} catch (error) {
Adapt.log.error('adapt-contrib-xapi:', error);
logging.error('adapt-contrib-xapi:', error);
throw error;
}

Expand All @@ -1148,17 +1153,17 @@ class XAPI extends Backbone.Model {
await new Promise((resolve, reject) => {
this.xapiWrapper.deleteState(activityId, actor, type, registration, null, null, (error, xhr) => {
if (error) {
Adapt.log.warn(`adapt-contrib-xapi: deleteState() failed for ${activityId} (${type})`);
logging.warn(`adapt-contrib-xapi: deleteState() failed for ${activityId} (${type})`);
return reject(error);
}

if (!xhr) {
Adapt.log.warn(`adapt-contrib-xapi: deleteState() failed for ${activityId} (${type})`);
logging.warn(`adapt-contrib-xapi: deleteState() failed for ${activityId} (${type})`);
return reject(new Error('\'xhr\' parameter is missing from callback'));
}

if (xhr.status !== 204) {
Adapt.log.warn(`adapt-contrib-xapi: deleteState() failed for ${activityId} (${type})`);
logging.warn(`adapt-contrib-xapi: deleteState() failed for ${activityId} (${type})`);
return reject(new Error(`Invalid status code ${xhr.status} returned from getState() call`));
}

Expand All @@ -1167,7 +1172,7 @@ class XAPI extends Backbone.Model {
});
}
} catch (error) {
Adapt.log.error('adapt-contrib-xapi:', error);
logging.error('adapt-contrib-xapi:', error);
throw error;
}
}
Expand Down Expand Up @@ -1272,12 +1277,12 @@ class XAPI extends Backbone.Model {
let errorCount = 0;

if (!this.get('actor') || typeof this.get('actor') !== 'object') {
Adapt.log.warn('adapt-contrib-xapi: "actor" attribute not found!');
logging.warn('adapt-contrib-xapi: "actor" attribute not found!');
errorCount++;
}

if (!this.get('activityId')) {
Adapt.log.warn('adapt-contrib-xapi: "activityId" attribute not found!');
logging.warn('adapt-contrib-xapi: "activityId" attribute not found!');
errorCount++;
}

Expand Down Expand Up @@ -1429,7 +1434,7 @@ class XAPI extends Backbone.Model {
xhr.responseType = 'blob';
xhr.send();
} else {
Adapt.log.warn('Attachment object contained neither a value or url property.');
logging.warn('Attachment object contained neither a value or url property.');
return resolve();
}
});
Expand Down Expand Up @@ -1457,7 +1462,7 @@ class XAPI extends Backbone.Model {
await this.sendStatement(statement);
}
} catch (error) {
Adapt.log.error('adapt-contrib-xapi:', error);
logging.error('adapt-contrib-xapi:', error);
throw error;
}
}
Expand Down Expand Up @@ -1485,11 +1490,11 @@ class XAPI extends Backbone.Model {
};

// Setup wait so that notify does not get dismissed when the page loads
Adapt.wait.begin();
Adapt.notify.alert(notifyObject);
wait.begin();
notify.alert(notifyObject);
// Ensure notify appears on top of the loading screen
$('.notify').css({ position: 'relative', zIndex: 5001 });
Adapt.once('notify:closed', Adapt.wait.end);
Adapt.once('notify:closed', wait.end);
}
}

Expand Down
8 changes: 5 additions & 3 deletions js/XAPIIndex.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Adapt from 'core/js/adapt';
import logging from 'core/js/logging';
import offlineStorage from 'core/js/offlineStorage';
import setupOfflineStorage from './setupOfflineStorage';
import XAPI from './XAPI';

Expand All @@ -20,7 +22,7 @@ class XAPIIndex extends Backbone.Controller {
xapi.listenTo(Adapt, {
'adapt:initialize': xapi.setupListeners,
'xapi:lrs:initialize:error': error => {
Adapt.log.error('adapt-contrib-xapi: xAPI Wrapper initialisation failed', error);
logging.error('adapt-contrib-xapi: xAPI Wrapper initialisation failed', error);
xapi.showError();
},
'xapi:lrs:sendStatement:error xapi:lrs:sendState:error': xapi.showError
Expand All @@ -36,8 +38,8 @@ class XAPIIndex extends Backbone.Controller {
}

onLRSReady() {
Adapt.offlineStorage.get();
Adapt.offlineStorage.setReadyStatus();
offlineStorage.get();
offlineStorage.setReadyStatus();
}

}
Expand Down
3 changes: 2 additions & 1 deletion js/setupOfflineStorage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Adapt from 'core/js/adapt';
import offlineStorage from 'core/js/offlineStorage';

// xAPI handler for Adapt.offlineStorage interface.
export default function setupOfflineStorage(XAPI) {
Expand All @@ -12,7 +13,7 @@ export default function setupOfflineStorage(XAPI) {
const store = new Backbone.Model();
let isDataRestored = false;

Adapt.offlineStorage.initialize({
offlineStorage.initialize({

get(name) {
if (!name) {
Expand Down

0 comments on commit 2ff3e0e

Please sign in to comment.