From f81954b8c820cbad881cbe48b86c1fc99b9ad02b Mon Sep 17 00:00:00 2001 From: Andy Creighton Date: Wed, 27 Jan 2016 17:27:17 -0500 Subject: [PATCH] completed tasks from review --- examples/stmtBank.js | 337 +++++++++++++++++++--------------------- src/xapi-util.js | 19 ++- test/my.mock.wrapper.js | 20 ++- test/tests/test.util.js | 71 ++++++--- 4 files changed, 239 insertions(+), 208 deletions(-) diff --git a/examples/stmtBank.js b/examples/stmtBank.js index 076b601..10abece 100644 --- a/examples/stmtBank.js +++ b/examples/stmtBank.js @@ -15,9 +15,9 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md A Statement MAY use its properties in any order. */ - /* 0 An example of the simplest possible Statement using all properties that MUST or SHOULD be used: Actor-Verb-Object and Statement Id + /* An example of the simplest possible Statement using all properties that MUST or SHOULD be used: Actor-Verb-Object and Statement Id */ - stmt0: { + "Base-Statement": { "actor": { "mbox": "mailto:xapi@adlnet.gov", "objectType": "Agent" @@ -43,9 +43,9 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "12345678-1234-5678-1234-567812345678" }, - /* 1 Actor Agent - Simple statement featured at the xapi spec https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#AppendixA + /* Actor Agent - Simple statement featured at the xapi spec https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#AppendixA features Actor-Verb-Object with UUID */ - stmt1: { + "Actor-Agent": { "actor": { "mbox": "mailto:user@example.com", "name": "Project Tin Can API", @@ -80,8 +80,28 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "fd41c918-b88b-4b20-a0a5-a4c32391aaa0" }, - /* 2 Actor Group - Simple Statment with the Actor of type Group */ - stmt2: { + /* Actor Group - Simple Statment with the Actor of type Identified Group */ + "Actor-Id-Group": { + "actor": { + "member": [ + { + "mbox": "mailto:andrew@example.com", + "name": "Andrew Downes", + "objectType": "Agent" + }, + { + "openid": "http://aaron.openid.example.org", + "name": "Aaron Silvers", + "objectType": "Agent" + } + ], + "account": { + "homePage": "http://example.com/homePage", + "name": "GroupAccount" + }, + "name": "Example Group", + "objectType": "Group" + }, "verb": { "id": "http://adlnet.gov/expapi/verbs/created", "display": { @@ -102,6 +122,17 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "http://example.adlnet.gov/xapi/example/activity", "objectType": "Activity" }, + "stored": "2016-01-25T20:15:46.622339+00:00", + "authority": { + "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", + "name": "xapi-tools", + "objectType": "Agent" + }, + "id": "65135a9a-b656-4445-9ffc-206ff22431c3" + }, + + /* Anonymous Group - the Actor is of type Anonymous Group */ + "Actor-Anon-Group": { "actor": { "member": [ { @@ -115,24 +146,39 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "objectType": "Agent" } ], - "account": { - "homePage": "http://example.com/homePage", - "name": "GroupAccount" - }, - "name": "Example Group", "objectType": "Group" }, - "stored": "2016-01-25T20:15:46.622339+00:00", + "verb": { + "id": "http://adlnet.gov/expapi/verbs/completed", + "display": { + "en-US": "completed" + } + }, + "version": "1.0.1", + "timestamp": "2016-01-27T19:12:45.427205+00:00", + "object": { + "definition": { + "name": { + "en-US": "Example Activity" + }, + "description": { + "en-US": "Example activity description" + } + }, + "id": "http://example.adlnet.gov/xapi/example/activity", + "objectType": "Activity" + }, + "stored": "2016-01-27T19:12:45.427205+00:00", "authority": { - "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", + "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", "name": "xapi-tools", "objectType": "Agent" }, - "id": "65135a9a-b656-4445-9ffc-206ff22431c3" + "id": "8484d8a3-cd78-4883-bbb7-04bb12409fa9" }, - /* 3 Actor Inverse Functional Identifier (IFI) mbox - Simple Statment with the Actor IFI mbox_sha1sum. */ - stmt3: { + /* Actor Inverse Functional Identifier (IFI) mbox - Simple Statment with the Actor IFI mbox_sha1sum. */ + "Actor-Mbox": { "actor": { "mbox_sha1sum": "6a113390c5a05e6e345e0f559e03a1b294c2c3a3", "objectType": "Agent" @@ -166,8 +212,8 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "e179532e-ae03-4b86-a84f-aea691f1fd13" }, - /* 4 Actor IFI Openid - Simple Statement with the Actor IFI openid */ - stmt4: { + /* Actor IFI Openid - Simple Statement with the Actor IFI openid */ + "Actor-Openid": { "actor": { "openid": "http://user.openid.example.com", "objectType": "Agent" @@ -201,19 +247,10 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "e038d689-2d58-4068-a8c9-2cd51c8aa4c8" }, - /* 5 Actor IFI Account - simple statement with the Actor as an account. + /* Actor IFI Account - simple statement with the Actor as an account. A user account on an existing system, such as a private system (LMS or - intranet) or a public system (social networking site). - - Details: - If the system that provides the account Object uses OpenID, the - Activity Provider SHOULD use the openid property instead of an account - Object. - If the Activity Provider is concerned about revealing personally - identifiable information about an Agent or Group, it SHOULD use an - opaque account name (for example an account number) to identify all - Statements about a person while maintaining anonymity.*/ - stmt5: { + intranet) or a public system (social networking site). https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#4124-account-object */ + "Actor-Account": { "actor": { "account": { "homePage": "http://www.example.com", @@ -250,9 +287,9 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "7a886f8b-e1c6-4470-8f33-54810b5a99e5" }, - /* 6 Verb - Simple Statement with user defined verb + /* Verb - Simple Statement with user defined verb https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#413-verb */ - stmt6: { + "Verb-User-Defined": { "verb": { "display": { "en-US": "perused" @@ -286,30 +323,30 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md } }, - /* 7 Verb - Simple Statement with predefined verb */ - stmt7: { + /* Verb - Simple Statement with predefined verb */ + "Verb-Predefined": { "verb": { - "id": "http://adlnet.gov/expapi/verbs/preferred", + "id": "http://adlnet.gov/expapi/verbs/preferred", "display": { - "en-US": "preferred" + "en-US": "preferred" } }, "version": "1.0.1", "timestamp": "2016-01-21T16:30:02.244116+00:00", "object": { - "definition": { - "name": { - "en-US": "Example Activity" - }, - "description": { - "en-US": "Example activity description" - } + "definition": { + "name": { + "en-US": "Example Activity" + }, + "description": { + "en-US": "Example activity description" + } }, "id": "http://example.adlnet.gov/xapi/example/activity", "objectType": "Activity" }, "actor": { - "openid": "http://user.openid.example.com", + "openid": "http://user.openid.example.com", "objectType": "Agent" }, "stored": "2016-01-21T16:30:02.244116+00:00", @@ -321,9 +358,9 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "12d33361-b5fe-48dd-ab8c-8777cc9c45a5" }, - /* 8 Object - Simple Statment with Object as an Activity + /* Object - Simple Statment with Object as an Activity https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#414-object */ - stmt8: { + "Object-Activity": { "object": { "definition": { "description": { @@ -357,8 +394,8 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "8d5a014c-0d8d-4bca-be53-d6dba346519b" }, - /* 9 Object - Simple Statment with Object as an Agent */ - stmt9: { + /* Object - Simple Statment with Object as an Agent */ + "Object-Agent": { "object": { "mbox": "mailto:instructor@example.com", "name": "Instructor", @@ -367,7 +404,7 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "verb": { "display": { "en-US": "asked" - }, + }, "id": "http://adlnet.gov/expapi/verbs/asked" }, "version": "1.0.1", @@ -385,8 +422,8 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "f3d9ed54-c057-11e5-b464-005056a25e99" }, - /* 10 Object - Simple Statement with object as a Group */ - stmt10: { + /* Object - Simple Statement with Object as a Group */ + "Object-Group": { "object": { "member": [ { @@ -437,8 +474,8 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "f3d68632-c057-11e5-b464-005056a25e99" }, - /* 11 Object - Simple Statement with Object as a Statement Reference*/ - stmt11: { + /* Object - Simple Statement with Object as a Statement Reference*/ + "Object-StatementRef": { "object": { "id": "12345678-1234-5678-1234-567812345678", "objectType": "StatementRef" @@ -464,147 +501,53 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md "id": "f3d4e214-c057-11e5-b464-005056a25e99" }, - /* 6 Verb = attempted, and a Result section */ - stmtA: { + /* Object - Simple Statement with Object as a Sub-Statement */ + "Object-Sub-Statement": { "verb": { - "id": "http://adlnet.gov/expapi/verbs/attempted", + "id": "http://example.com/planned", "display": { - "en-US": "attempted" + "en-US": "planned" } }, "version": "1.0.1", - "timestamp": "2016-01-25T20:40:21.350153+00:00", + "timestamp": "2016-01-26T19:28:25.096469+00:00", "object": { - "definition": { - "name": { - "en-US": "simple CBT course" - }, - "description": { - "en-US": "A fictitious example CBT course." - } - }, - "id": "http://example.adlnet.gov/xapi/example/simpleCBT", - "objectType": "Activity" - }, - "actor": { - "mbox": "mailto:example.learner@adlnet.gov", - "name": "Example Learner", - "objectType": "Agent" - }, - "stored": "2016-01-25T20:40:21.350153+00:00", - "result": { - "completion": true, - "score": { - "scaled": 0.95 - }, - "success": true - }, - "id": "0c808355-396c-4a3f-9bf2-5334e0f71493", - "authority": { - "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", - "name": "xapi-tools", - "objectType": "Agent" - } - }, - /* 3 Simple statement with Object as an Activity */ - stmtB: { - "verb": { - "id": "http://verb.com/do0" - }, - "version": "1.0.1", - "timestamp": "2016-01-25T20:37:36.706944+00:00", - "object": { - "definition": { - "type": "http://www.example.co.uk/types/exampleactivitytype", - "name": { - "en-GB": "example activity", - "en-US": "example activity" - }, - "description": { - "en-GB": "An example of an activity", - "en-US": "An example of an activity" + "verb": { + "id": "http://example.com/visited", + "display": { + "en-US": "will visit" } }, - "id": "http://www.example.co.uk/exampleactivity", - "objectType": "Activity" - }, "actor": { - "mbox": "mailto:tom@tom.com", - "objectType": "Agent" - }, - "stored": "2016-01-25T20:37:36.706944+00:00", - "authority": { - "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", - "name": "xapi-tools", - "objectType": "Agent" - }, - "id": "45f58f16-a6bc-401f-b324-b841a77a6d6f" - }, - /* 4 Simple statement with Object as an Agent*/ - stmtC: { - "verb": { - "id": "http://verb.com/do0" - }, - "version": "1.0.1", - "timestamp": "2016-01-25T20:35:39.683720+00:00", - "object": { - "mbox": "mailto:andrew@example.co.uk", - "name": "Andrew Downes", - "objectType": "Agent" - }, - "actor": { - "mbox": "mailto:tom@tom.com", - "objectType": "Agent" - }, - "stored": "2016-01-25T20:35:39.683720+00:00", - "authority": { - "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", - "name": "xapi-tools", - "objectType": "Agent" - }, - "id": "2bf2f7c9-58bb-459e-a50f-42951913b29c" - }, - /* 5 Simple statement with Object as an identified Group with members */ - stmtD: { - "object": { - "member": [ - { - "mbox": "mailto:andrew@example.com", - "name": "Andrew Downes", - "objectType": "Agent" + "mbox": "mailto:test@example.com", + "objectType": "Agent" + }, + "object": { + "definition": { + "name": { + "en-US": "Some Awesome Website" + } }, - { - "openid": "http://aaron.openid.example.org", - "name": "Aaron Silvers", - "objectType": "Agent" - } - ], - "account": { - "homePage": "http://example.com/homePage", - "name": "GroupAccount" + "id": "http://example.com/website", + "objectType": "Activity" }, - "name": "Example Group", - "objectType": "Group" - }, - "verb": { - "id": "http://verb.com/do0" + "objectType": "SubStatement" }, - "version": "1.0.1", - "timestamp": "2016-01-25T20:31:57.460856+00:00", "actor": { - "mbox": "mailto:tom@tom.com", + "mbox": "mailto:test@example.com", "objectType": "Agent" }, - "stored": "2016-01-25T20:31:57.460856+00:00", + "stored": "2016-01-26T19:28:25.096469+00:00", "authority": { "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", "name": "xapi-tools", "objectType": "Agent" }, - "id": "537e8b66-0598-4067-bb2d-de8c4e072049" + "id": "29cf2f86-3f41-4efc-8f64-866c3ce8899c" }, - /* 6 Simple statement with Object as a Sub-Statement whose Object is a Statement Reference*/ - stmtE: { + + /* Simple statement with Object as a Sub-Statement whose Object is a Statement Reference*/ + "Object-Sub-Statement-with-StatementRef": { "verb": { "id": "http://verb.com/do0" }, @@ -639,8 +582,52 @@ https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md }, "id": "b5f9eb2c-588f-48b0-b845-71ed17cd074e" }, - /* 7 A long example statement showcasing most of the properties available. This example shows a statement returned by an LRS including the authority and stored properties set by the LRS */ - stmtF: { + + /* Result section */ + "Result": { + "verb": { + "id": "http://adlnet.gov/expapi/verbs/attempted", + "display": { + "en-US": "attempted" + } + }, + "version": "1.0.1", + "timestamp": "2016-01-25T20:40:21.350153+00:00", + "object": { + "definition": { + "name": { + "en-US": "simple CBT course" + }, + "description": { + "en-US": "A fictitious example CBT course." + } + }, + "id": "http://example.adlnet.gov/xapi/example/simpleCBT", + "objectType": "Activity" + }, + "actor": { + "mbox": "mailto:example.learner@adlnet.gov", + "name": "Example Learner", + "objectType": "Agent" + }, + "stored": "2016-01-25T20:40:21.350153+00:00", + "result": { + "completion": true, + "score": { + "scaled": 0.95 + }, + "success": true + }, + "id": "0c808355-396c-4a3f-9bf2-5334e0f71493", + "authority": { + "mbox": "mailto:tyler.mulligan.ctr+xapi-tools@adlnet.gov", + "name": "xapi-tools", + "objectType": "Agent" + } + }, + + /* A long example statement showcasing most of the properties available. This example shows a statement returned by an LRS including the authority and stored properties set by the LRS */ + "Long-Example": { "id": "6690e6c9-3ef0-4ed3-8b37-7f3964730bee", "actor": { "name": "Team PB", diff --git a/src/xapi-util.js b/src/xapi-util.js index 9ab06f1..9589447 100644 --- a/src/xapi-util.js +++ b/src/xapi-util.js @@ -8,7 +8,6 @@ var getObjDefName = function (o) { if (o.definition && o.definition.name) { - // return o.definition.name[ADL.xapiutil.getLangVal()]; return ADL.xapiutil.getLangVal(o.definition.name); } return undefined; @@ -39,13 +38,14 @@ }; ADL.xapiutil.getLangVal = function (langprop) { +//test for undefined first var options = Object.keys(langprop); // test that langprop is a dict (obj) // skips if not a dict(obj) and returns - if (options == 0) return langprop; + if (options.length == 0) return undefined; var lang = ADL.xapiutil.getLang(), - ret = langprop[options[0]]; + ret = langprop[options[0]];//make undefined dispGotten = false; do { //test and retest if (langprop[lang]) @@ -57,18 +57,16 @@ { lang = lang.substring(0, lang.lastIndexOf('-')); } - // else lang = ""; } while (!dispGotten && lang !==""); return ret; }; ADL.xapiutil.getMoreStatements = function (iterations, callback, searchParams) { - if (!onBrowser) return "Error: Node not supported." - // throw new Error("Node not supported."); + if (!onBrowser) throw new Error("Node not supported."); var stmts = []; - +// debugger; ADL.XAPIWrapper.getStatements(searchParams, null, function getMore(r) { if (! (r && r.response) ) return; var res = JSON.parse(r.response); @@ -79,9 +77,14 @@ callback(stmts); } else { - if (res.more && res.more !== "") { + if (res.more && res.more !== "") + { ADL.XAPIWrapper.getStatements(searchParams, res.more, getMore); } + else if (res.more === "") + { + callback(stmts); + } } }); }; diff --git a/test/my.mock.wrapper.js b/test/my.mock.wrapper.js index ceba12a..83b4d1e 100644 --- a/test/my.mock.wrapper.js +++ b/test/my.mock.wrapper.js @@ -852,8 +852,10 @@ function isDate(date) { var index = urlparts[urlparts.length - 1]; - var numstmts = Object.keys(ADL.stmts).length; - var cutoff = 3; //only send 4 statements at a time + var keys = Object.keys(ADL.stmts); + var numstmts = keys.length; + var cutoff = 4; //only send 4 statements at a time +//index will either be zero or where to start with more statements if (index == "statements") { index = 0; @@ -862,25 +864,31 @@ function isDate(date) { { index = parseInt(index); } +//if doling out our ususal size block of statments would exceed the amount +//of statements that we have, then adjust the cutoff and send out what's left if (cutoff > (numstmts - index)) { cutoff = numstmts - index; } - for (var i = 0; i < cutoff; i++) +//make a mini array of the keys we want to return + var thesekeys = keys.slice(index, index + cutoff); +//use the mini array of keys to get the statments we want to return - hooray!! + for (var k in thesekeys) { - arrstmts.push(ADL.stmts["stmt" + (i + index)]) + arrstmts.push(ADL.stmts[thesekeys[k]]); } +//assume there's no more statements, if this is more, then return the next index number - it's magic var morestmts = ""; if ((index + cutoff) < numstmts) { morestmts = "/" + (index + cutoff); } - +//mkae a response object, and make that a string var response = { statements: arrstmts, more: morestmts}; response = JSON.stringify(response); - +//a good days work, we're outta here callback({response}); // "use strict"; // diff --git a/test/tests/test.util.js b/test/tests/test.util.js index 45424d7..46f1d13 100644 --- a/test/tests/test.util.js +++ b/test/tests/test.util.js @@ -4,7 +4,7 @@ after(function () { describe('testing xAPI utilities', function () { - var util, s1, s2, s3, s4, s5, s6, onBrowser, stmts; + var util, s1, s2, s3, s4, s5, s6, onBrowser, should, stmts; before(function () { @@ -12,11 +12,12 @@ describe('testing xAPI utilities', function () { if (typeof window !== 'undefined') { util = ADL.xapiutil; onBrowser = true; - //