Skip to content

Commit

Permalink
refactor: comment out debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
satikaj committed Jul 5, 2024
1 parent 1b1710f commit 635ad51
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 66 deletions.
10 changes: 5 additions & 5 deletions src/app/api/models/scorm-datamodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class ScormDataModel {
}

public restore(dataModel: string) {
console.log(this.msgPrefix + 'restoring DataModel with provided data');
// console.log(this.msgPrefix + 'restoring DataModel with provided data');
this.dataModel = JSON.parse(dataModel);
}

Expand All @@ -27,22 +27,22 @@ export class ScormDataModel {
// cmi.interactions._count must be incremented after a new interaction is created
const interactionPath = key.match('cmi.interactions.\\d+');
const objectivesCounterForInteraction = interactionPath.toString() + '.objectives._count';
console.log('Incrementing cmi.interactions._count');
// console.log('Incrementing cmi.interactions._count');
this.dataModel['cmi.interactions._count']++;
// cmi.interactions.n.objectives._count must be initialized after an interaction is created
console.log(`Initializing ${objectivesCounterForInteraction}`);
// console.log(`Initializing ${objectivesCounterForInteraction}`);
this.dataModel[objectivesCounterForInteraction] = 0;
}
if (key.match('cmi.interactions.\\d+.objectives.\\d+.id')) {
const interactionPath = key.match('cmi.interactions.\\d+.objectives');
const objectivesCounterForInteraction = interactionPath.toString() + '._count';
// cmi.interactions.n.objectives._count must be incremented after objective creation
console.log(`Incrementing ${objectivesCounterForInteraction}`);
// console.log(`Incrementing ${objectivesCounterForInteraction}`);
this.dataModel[objectivesCounterForInteraction.toString()]++;
}
if (key.match('cmi.objectives.\\d+.id')) {
// cmi.objectives._count must be incremented after a new objective is created
console.log('Incrementing cmi.objectives._count');
// console.log('Incrementing cmi.objectives._count');
this.dataModel['cmi.objectives._count']++;
}
return 'true';
Expand Down
110 changes: 51 additions & 59 deletions src/app/api/services/scorm-adapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ export class ScormAdapterService {
}

Initialize(): string {
console.log('API_1484_11: Initialize');
// console.log('API_1484_11: Initialize');

// TODO: error handling and reporting
switch (this.context.state) {
case 'Initialized':
this.context.errorCode = 103;
console.log('Already Initialized');
// console.log('Already Initialized');
break;
case 'Terminated':
this.context.errorCode = 104;
console.log('Content Instance Terminated');
// console.log('Content Instance Terminated');
break;
}

Expand All @@ -62,23 +62,12 @@ export class ScormAdapterService {
this.xhr.setRequestHeader('Auth-Token', this.context.user.authenticationToken);
this.xhr.setRequestHeader('Username', this.context.user.username);

this.xhr.onload = () => {
if (this.xhr.status >= 200 && this.xhr.status < 400) {
console.log('Retrieved the attempt.');
} else if (this.xhr.status == 404) {
console.log('Not found.');
noTestFound = true;
} else {
console.error('Error saving DataModel:', this.xhr.responseText);
}
};

this.xhr.send();
console.log(this.xhr.responseText);
// console.log(this.xhr.responseText);

const reviewSession = JSON.parse(this.xhr.responseText);
this.dataModel.restore(reviewSession.cmi_datamodel);
console.log(this.dataModel.dump());
// console.log(this.dataModel.dump());

this.context.state = 'Initialized';
return 'true';
Expand All @@ -97,22 +86,26 @@ export class ScormAdapterService {
let startNewTest = false;

this.xhr.onload = () => {
if (this.xhr.status >= 200 && this.xhr.status < 400) {
console.log('Retrieved the latest attempt.');
} else if (this.xhr.status == 404) {
console.log('Not found.');
if (this.xhr.status == 404) {
noTestFound = true;
} else {
console.error('Error saving DataModel:', this.xhr.responseText);
}

// if (this.xhr.status >= 200 && this.xhr.status < 400) {
// console.log('Retrieved the latest attempt.');
// } else if (this.xhr.status == 404) {
// console.log('Not found.');
// noTestFound = true;
// } else {
// console.error('Error saving DataModel:', this.xhr.responseText);
// }
};

this.xhr.send();
console.log(this.xhr.responseText);
// console.log(this.xhr.responseText);

if (!noTestFound) {
const latestSession = JSON.parse(this.xhr.responseText);
console.log('Latest exam session:', latestSession);
// console.log('Latest exam session:', latestSession);
this.context.attemptId = latestSession.id;
if (latestSession.completion_status) {
startNewTest = true;
Expand All @@ -126,13 +119,13 @@ export class ScormAdapterService {
this.xhr.setRequestHeader('Auth-Token', this.context.user.authenticationToken);
this.xhr.setRequestHeader('Username', this.context.user.username);
this.xhr.send();
console.log(this.xhr.responseText);
// console.log(this.xhr.responseText);

const currentSession = JSON.parse(this.xhr.responseText);
console.log('Current exam session:', currentSession);
// console.log('Current exam session:', currentSession);
this.context.attemptId = currentSession.id;
this.dataModel.restore(currentSession.cmi_datamodel);
console.log(this.dataModel.dump());
// console.log(this.dataModel.dump());
} else {
this.xhr.open(
'POST',
Expand All @@ -142,31 +135,31 @@ export class ScormAdapterService {
this.xhr.setRequestHeader('Auth-Token', this.context.user.authenticationToken);
this.xhr.setRequestHeader('Username', this.context.user.username);
this.xhr.send();
console.log(this.xhr.responseText);
// console.log(this.xhr.responseText);

const currentSession = JSON.parse(this.xhr.responseText);
console.log('Current exam session:', currentSession);
// console.log('Current exam session:', currentSession);
this.context.attemptId = currentSession.id;
this.dataModel.restore(currentSession.cmi_datamodel);
console.log(this.dataModel.dump());
// console.log(this.dataModel.dump());
}

this.context.state = 'Initialized';
return 'true';
}

Terminate(): string {
console.log('API_1484_11: Terminate');
// console.log('API_1484_11: Terminate');

// TODO: error handling and reporting
switch (this.context.state) {
case 'Uninitialized':
this.context.errorCode = 112;
console.log('Termination Before Initialization');
// console.log('Termination Before Initialization');
break;
case 'Terminated':
this.context.errorCode = 113;
console.log('Termination After Termination');
// console.log('Termination After Termination');
break;
}

Expand All @@ -179,7 +172,7 @@ export class ScormAdapterService {
terminated: true,
};
this.xhr.send(JSON.stringify(requestData));
console.log(this.xhr.responseText);
// console.log(this.xhr.responseText);

// all done, clearing datamodel and setting state to terminated
this.dataModel = new ScormDataModel();
Expand All @@ -195,31 +188,31 @@ export class ScormAdapterService {
switch (this.context.state) {
case 'Uninitialized':
this.context.errorCode = 122;
console.log('Retrieve Data Before Initialization');
// console.log('Retrieve Data Before Initialization');
break;
case 'Terminated':
this.context.errorCode = 123;
console.log('Retrieve Data After Termination');
// console.log('Retrieve Data After Termination');
break;
}

console.log(`API_1484_11: GetValue:`, element, value);
// console.log(`API_1484_11: GetValue:`, element, value);
return value;
}

SetValue(element: string, value: any): string {
console.log(`API_1484_11: SetValue:`, element, value);
// console.log(`API_1484_11: SetValue:`, element, value);

// TODO: error reporting
// TODO: can't set until init is done
switch (this.context.state) {
case 'Uninitialized':
this.context.errorCode = 132;
console.log('Store Data Before Initialization');
// console.log('Store Data Before Initialization');
break;
case 'Terminated':
this.context.errorCode = 133;
console.log('Store Data After Termination');
// console.log('Store Data After Termination');
break;
}

Expand All @@ -228,18 +221,18 @@ export class ScormAdapterService {
}

Commit(): string {
console.log('API_1484_11: Commit');
// console.log('API_1484_11: Commit');

// TODO: error reporting
// TODO: can't commit until init is done
switch (this.context.state) {
case 'Uninitialized':
this.context.errorCode = 142;
console.log('Commit Before Initialization');
// console.log('Commit Before Initialization');
break;
case 'Terminated':
this.context.errorCode = 143;
console.log('Commit After Termination');
// console.log('Commit After Termination');
break;
}

Expand All @@ -250,19 +243,18 @@ export class ScormAdapterService {
const requestData = {
cmi_datamodel: JSON.stringify(this.dataModel.dump()),
};


this.xhr.onload = () => {
if (this.xhr.status >= 200 && this.xhr.status < 400) {
console.log('DataModel saved successfully.');
} else {
console.error('Error saving DataModel:', this.xhr.responseText);
}
};
// this.xhr.onload = () => {
// if (this.xhr.status >= 200 && this.xhr.status < 400) {
// console.log('DataModel saved successfully.');
// } else {
// console.error('Error saving DataModel:', this.xhr.responseText);
// }
// };

this.xhr.onerror = () => {
console.error('Request failed.');
};
// this.xhr.onerror = () => {
// console.error('Request failed.');
// };

this.xhr.send(JSON.stringify(requestData));
this.context.errorCode = 0;
Expand All @@ -271,21 +263,21 @@ export class ScormAdapterService {

GetLastError(): string {
const lastError = this.context.errorCode.toString();
if (lastError !== '0') {
console.log(`API_1484_11: GetLastError: ${lastError}`);
}
// if (lastError !== '0') {
// console.log(`API_1484_11: GetLastError: ${lastError}`);
// }
return lastError;
}

GetErrorString(errorCode: string): string {
const errorString = this.context.getErrorMessage(errorCode);
console.log(`API_1484_11: GetErrorString:`, errorCode, errorString);
// console.log(`API_1484_11: GetErrorString:`, errorCode, errorString);
return errorString;
}

GetDiagnostic(errorCode: string): string {
// TODO: implement this
console.log(`API_1484_11: GetDiagnostic:`, errorCode);
// console.log(`API_1484_11: GetDiagnostic:`, errorCode);
return 'GetDiagnostic is currently not implemented';
}
}
2 changes: 1 addition & 1 deletion src/app/common/scorm-player/scorm-player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class ScormPlayerComponent implements OnInit {
@HostListener('window:beforeunload', ['$event'])
beforeUnload($event: any): void {
if (this.scormAdapter.state == 'Initialized') {
console.log('SCORM player closing during an initialized session, commiting DataModel');
// console.log('SCORM player closing during an initialized session, commiting DataModel');
this.scormAdapter.Commit();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TaskDefinitionScormComponent {
}

public uploadScormData(files: FileList) {
console.log(Array.from(files).map((f) => f.type));
// console.log(Array.from(files).map((f) => f.type));
const validMimeTypes = ['application/zip', 'application/x-zip-compressed', 'multipart/x-zip'];
const validFiles = Array.from(files as ArrayLike<File>).filter((f) =>
validMimeTypes.includes(f.type),
Expand Down

0 comments on commit 635ad51

Please sign in to comment.