From 4461c530d16f46320a509e069e14315647348e31 Mon Sep 17 00:00:00 2001 From: Matt Leathes Date: Fri, 26 May 2017 11:11:45 +0100 Subject: [PATCH] have spoor overwrite the hard-coded 'learner info' data with real data (#155) * amend adapt-stateful-session.js so that it replaces the hard-coded 'learner info' data with actual data from the LMS update offline_API_wrapper.js so that it has the student_name in "Lastname, Firstname" (as the SCORM spec requires) and also so that it has student_id/learner_id * version bump * change default Student surname from 'Student' to 'Surname' following code review * update student_id to match * defensive programming to account for situations when the _learnerInfo object might not be present in _globals --- README.md | 4 ++-- bower.json | 2 +- js/adapt-stateful-session.js | 16 ++++++++++++++++ required/offline_API_wrapper.js | 6 ++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 17ba713c..5348931e 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,8 @@ When **Spoor** is installed, *scorm_test_harness.html* can be used instead of *i Currently (officially) only supports SCORM 1.2 ---------------------------- -**Version number:** 2.0.15 adapt learning logo -**Framework versions:** 2.0.15 +**Version number:** 2.0.16 adapt learning logo +**Framework versions:** 2.0.16 **Author / maintainer:** Adapt Core Team with [contributors](https://github.com/adaptlearning/adapt-contrib-spoor/graphs/contributors) **Accessibility support:** n/a **RTL support:** n/a diff --git a/bower.json b/bower.json index f1a9081a..932014ba 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "adapt-contrib-spoor", - "version": "2.0.15", + "version": "2.0.16", "framework": "^2.0.16", "homepage": "https://github.com/adaptlearning/adapt-contrib-spoor", "issues": "https://github.com/adaptlearning/adapt_framework/issues/new?title=contrib-spoor%3A%20please%20enter%20a%20brief%20summary%20of%20the%20issue%20here&body=please%20provide%20a%20full%20description%20of%20the%20problem,%20including%20steps%20on%20how%20to%20replicate,%20what%20browser(s)/device(s)%20the%20problem%20occurs%20on%20and,%20where%20helpful,%20the%20contents%20of%20the%20SCORM%20debug%20window.", diff --git a/js/adapt-stateful-session.js b/js/adapt-stateful-session.js index 6db33422..e2495256 100644 --- a/js/adapt-stateful-session.js +++ b/js/adapt-stateful-session.js @@ -15,7 +15,11 @@ define([ //Session Begin initialize: function(callback) { this._onWindowUnload = _.bind(this.onWindowUnload, this); + this.getConfig(); + + this.getLearnerInfo(); + // restore state asynchronously to prevent IE8 freezes this.restoreSessionState(_.bind(function() { // still need to defer call because AdaptModel.check*Status functions are asynchronous @@ -35,6 +39,18 @@ define([ } }, + /** + * replace the hard-coded _learnerInfo data in _globals with the actual data from the LMS + * if the course has been published from the AT, the _learnerInfo object won't exist so we'll need to create it + */ + getLearnerInfo: function() { + var globals = Adapt.course.get('_globals'); + if (!globals._learnerInfo) { + globals._learnerInfo = {}; + } + _.extend(globals._learnerInfo, Adapt.offlineStorage.get("learnerinfo")); + }, + saveSessionState: function() { var sessionPairs = this.getSessionState(); Adapt.offlineStorage.set(sessionPairs); diff --git a/required/offline_API_wrapper.js b/required/offline_API_wrapper.js index dc359ac1..5b6f51a3 100644 --- a/required/offline_API_wrapper.js +++ b/required/offline_API_wrapper.js @@ -20,7 +20,8 @@ var API = { if (!API.LMSFetch()) { this.data["cmi.core.lesson_status"] = "not attempted"; this.data["cmi.suspend_data"] = ""; - this.data["cmi.core.student_name"] = "Test Student"; + this.data["cmi.core.student_name"] = "Surname, Sam"; + this.data["cmi.core.student_id"] = "sam.surname@example.org"; this.data["cmi.interactions._count"] = 0; API.LMSStore(true); } @@ -97,7 +98,8 @@ var API_1484_11 = { if (!API_1484_11.LMSFetch()) { this.data["cmi.completion_status"] = "not attempted"; this.data["cmi.suspend_data"] = ""; - this.data["cmi.learner_name"] = "Test Student"; + this.data["cmi.learner_name"] = "Surname, Sam"; + this.data["cmi.learner_id"] = "sam.surname@example.org"; this.data["cmi.interactions._count"] = 0; API_1484_11.LMSStore(true); }