Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Compilation issues and linting (fixes #137) #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions js/CMI5.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class CMI5 extends Backbone.Controller {
auth: `Basic ${this.xapi.get('_auth')}`,
activity_id: this.xapi.get('_activityId'),
endpoint: this.xapi.get('_endpoint'),
strictCallbacks: true,
strictCallbacks: true
});
this.xapi.set({
actor: this.xapi.get('_actor'),
registration: this.xapi.get('_registration'),
activityId: this.xapi.get('_activityId'),
activityId: this.xapi.get('_activityId')
});
const cmi5LaunchData = await this.getCmi5LaunchData();
if (this.isMasteryScoreSet(cmi5LaunchData)) {
Expand Down Expand Up @@ -56,7 +56,7 @@ class CMI5 extends Backbone.Controller {
_fetch: params.get('fetch'),
_activityId: params.get('activityId'),
_actor: JSON.parse(decodeURIComponent(params.get('actor'))),
_registration: params.get('registration'),
_registration: params.get('registration')
});
}

Expand All @@ -66,7 +66,7 @@ class CMI5 extends Backbone.Controller {
if (!authToken) return;
// Set the auth token in the model
this.xapi.set({
_auth: authToken,
_auth: authToken
});
}

Expand All @@ -82,7 +82,7 @@ class CMI5 extends Backbone.Controller {
try {
const fetchURL = this.xapi.get('_fetch');
const requestOptions = {
method: 'POST',
method: 'POST'
};
const response = await fetch(fetchURL, requestOptions);
if (!response.ok) {
Expand Down Expand Up @@ -255,14 +255,14 @@ class CMI5 extends Backbone.Controller {
(error, xhr) => {
if (error) {
logging.warn(
`adapt-contrib-xapi: getAgentProfile() failed for cmi5LearnerPreferences`
'adapt-contrib-xapi: getAgentProfile() failed for cmi5LearnerPreferences'
);
return reject(new Error(error));
}

if (!xhr) {
logging.warn(
`adapt-contrib-xapi: getAgentProfile() failed for cmi5LearnerPreferences`
'adapt-contrib-xapi: getAgentProfile() failed for cmi5LearnerPreferences'
);
return reject(
new Error("'xhr' parameter is missing from callback")
Expand All @@ -275,7 +275,7 @@ class CMI5 extends Backbone.Controller {

if (xhr.status !== 200) {
logging.warn(
`adapt-contrib-xapi: getAgentProfile() failed for cmi5LearnerPreferences`
'adapt-contrib-xapi: getAgentProfile() failed for cmi5LearnerPreferences'
);
return reject(
new Error(
Expand Down Expand Up @@ -379,10 +379,10 @@ class CMI5 extends Backbone.Controller {
category: [
{
id: 'https://w3id.org/xapi/cmi5/context/categories/cmi5',
objectType: 'Activity',
},
],
},
objectType: 'Activity'
}
]
}
};

// Append the category and masteryScore.
Expand Down Expand Up @@ -411,7 +411,7 @@ class CMI5 extends Backbone.Controller {

context.contextActivities.category.push({
id: 'https://w3id.org/xapi/cmi5/context/categories/moveon',
objectType: 'Activity',
objectType: 'Activity'
});
}

Expand All @@ -425,13 +425,13 @@ class CMI5 extends Backbone.Controller {
const { masteryScore } = this.xapi.get('launchData');
context.extensions
? context.extensions.push({
'https://w3id.org/xapi/cmi5/context/extensions/masteryscore':
masteryScore,
})
'https://w3id.org/xapi/cmi5/context/extensions/masteryscore':
masteryScore
})
: (context.extensions = {
'https://w3id.org/xapi/cmi5/context/extensions/masteryscore':
masteryScore,
});
'https://w3id.org/xapi/cmi5/context/extensions/masteryscore':
masteryScore
});
}

/**
Expand All @@ -453,17 +453,17 @@ class CMI5 extends Backbone.Controller {
...(context?.contextActivities || {}),
parent: [
...(context?.contextActivities?.parent || []),
...(contextActivities?.parent || []).filter(Boolean),
...(contextActivities?.parent || []).filter(Boolean)
],
grouping: [
...(context?.contextActivities?.grouping || []),
...(contextActivities?.grouping || []).filter(Boolean),
],
...(contextActivities?.grouping || []).filter(Boolean)
]
},
extensions: {
...(context?.extensions || {}),
...(extensions || {}),
},
...(extensions || {})
}
};

statement.timestamp = new Date().toISOString();
Expand All @@ -489,7 +489,7 @@ class CMI5 extends Backbone.Controller {
const conditions = {
CompletedOrPassed: () => completionVerb === failed,
Completed: () => completionVerb !== completed,
CompletedAndPassed: () => completionVerb === passed,
CompletedAndPassed: () => completionVerb === passed
};

if (conditions[launchDataMoveOn]?.()) {
Expand Down
24 changes: 12 additions & 12 deletions js/XAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class XAPI extends Backbone.Model {
componentBlacklist: 'blank,graphic',
isInitialised: false,
state: {},
shouldListenToTracking: true,
shouldListenToTracking: true
};

this.xapiWrapper = XAPIWrapper;
Expand Down Expand Up @@ -883,7 +883,7 @@ class XAPI extends Backbone.Model {
name[this.get('displayLang')] = assessment.id || 'Assessment';

object.definition = {
name: name,
name,
type: window.ADL.activityTypes.assessment
};

Expand Down Expand Up @@ -1115,7 +1115,7 @@ class XAPI extends Backbone.Model {
}

// Update the locally held state.
this.changedCollectionNames[collectionNames] = true;
this.changedCollectionNames[collectionName] = true;
state[collectionName] = newState;
this.set({
state
Expand All @@ -1125,7 +1125,7 @@ class XAPI extends Backbone.Model {
this.sendStateToServer();
}

sendStateToServer() {
async sendStateToServer() {
const activityId = this.get('activityId');
const actor = this.get('actor');
const registration = this.get('shouldUseRegistration') === true
Expand All @@ -1135,10 +1135,10 @@ class XAPI extends Backbone.Model {
const changedCollectionNames = Object.keys(this.changedCollectionNames);
this.changedCollectionNames = {};

for (const collectionName of changeCollectionNames) {
const newState = this.get('state')[collectionName];
for (const collectionName of changedCollectionNames) {
const newState = this.get('state')[collectionName];

await new Promise(resolve => {
await new Promise(resolve => {
this.xapiWrapper.sendState(activityId, actor, collectionName, registration, newState, null, null, (error, xhr) => {
if (error) {
Adapt.trigger('xapi:lrs:sendState:error', error);
Expand All @@ -1164,7 +1164,7 @@ class XAPI extends Backbone.Model {
const state = {};

try {
for (let type in this.coreObjects) {
for (const type in this.coreObjects) {
await new Promise((resolve, reject) => {
this.xapiWrapper.getState(activityId, actor, type, registration, null, (error, xhr) => {
if (error) {
Expand Down Expand Up @@ -1228,7 +1228,7 @@ class XAPI extends Backbone.Model {
: null;

try {
for (let type in this.coreObjects) {
for (const type in this.coreObjects) {
await new Promise((resolve, reject) => {
this.xapiWrapper.deleteState(activityId, actor, type, registration, null, null, (error, xhr) => {
if (error) {
Expand Down Expand Up @@ -1447,7 +1447,7 @@ class XAPI extends Backbone.Model {
* @returns {boolean}
*/
isCORS(url) {
const urlparts = url.toLowerCase().match(/^(.+):\/\/([^:\/]*):?(\d+)?(\/.*)?$/);
const urlparts = url.toLowerCase().match(/^(.+):\/\/([^:/]*):?(\d+)?(\/.*)?$/);
let isCORS = (location.protocol.toLowerCase().replace(':', '') !== urlparts[1] || location.hostname.toLowerCase() !== urlparts[2]);
if (isCORS) return true;
const urlPort = (urlparts[3] === null ? (urlparts[1] === 'http' ? '80' : '443') : urlparts[3]);
Expand Down Expand Up @@ -1487,7 +1487,7 @@ class XAPI extends Backbone.Model {
async processAttachments(statement) {
const attachments = statement.attachments;

for (let attachment of attachments) {
for (const attachment of attachments) {
await new Promise((resolve, reject) => {
// First check the attachment for a value
if (attachment.value) {
Expand Down Expand Up @@ -1539,7 +1539,7 @@ class XAPI extends Backbone.Model {
// Rather than calling the wrapper's sendStatements() function, iterate
// over each statement and call sendStatement().
try {
for (let statement of statements) {
for (const statement of statements) {
await this.sendStatement(statement);
}
} catch (error) {
Expand Down
Loading