Skip to content
Snippets Groups Projects
Commit 828e7ae9 authored by Benjamin Ledel's avatar Benjamin Ledel
Browse files

* restructure + xapi

parent f63427f4
No related branches found
No related tags found
No related merge requests found
Showing
with 494 additions and 0 deletions
import "./src/css/styles.scss"
import { polarisDashboard } from "./src/js/dashboard";
import { getResult, initGrid } from "./src/js/utils";
import { BaseChartWidget } from "./src/js/charts/base";
import { LineChartWidget } from"./src/js/charts/linechart";
......@@ -18,6 +19,7 @@ import { TextAreaElement } from "./src/js/elements/textareaelement";
export {
getResult,
initGrid,
polarisDashboard,
LineChartWidget,
BarChartWidget,
AreaChartWidget,
......
import xApi from "./xapi";
export var polaris_authority;
export function polarisDashboard(username, dashboardId, grid, generatexAPIStatement = false, xapiCallback = null)
{
polaris_authority = xApi.IFI.account({
name: username,
homePage: 'https://polaris.io/' + dashboardId
});
grid.grid.on('added', function(event, items) {
console.log("addd");
const statement = xApi.polaris.completed().actor(polaris_authority)
console.log(statement.getStatement())
});
grid.grid.on('drag', function(event, items) {
console.log("drag");
});
grid.grid.on('resize', function(event, items) {
console.log("resize");
const statement = xApi.polaris.resized().actor(polaris_authority)
console.log(statement.getStatement())
});
return authority;
}
\ No newline at end of file
const IFI = require('./xapi/IFI');
const polaris = require('./xapi/polaris');
const xApi = {
IFI,
polaris,
};
module.exports = xApi;
\ No newline at end of file
const account = ({name, homePage}) => ({
key: 'account',
getStatement() {
return {name, homePage}
}
});
module.exports = account;
\ No newline at end of file
const account = require('./account');
describe('IFI: Account', () => {
test('it should have the right key', () => {
const aliceId = account({name: 'Alice', homePage: 'http://www.example.com'});
expect(aliceId.key).toEqual('account');
})
test('it should generate the right statement snippet', () => {
const aliceId = account({name: 'Alice', homePage: 'http://www.example.com'});
expect({[aliceId.key]: aliceId.getStatement()}).toEqual({
account: {
name: 'Alice',
homePage: 'http://www.example.com'
}
})
})
});
\ No newline at end of file
const choice = (id, description, lang='en-US') => {
return {
"id": id.toString(),
"description": {
[lang]: description
}
}
};
module.exports = choice;
const choice = require('./choice');
describe('IFI: Choice', () => {
test('it should have the right id', () => {
const firstChoice = choice(1, "First choice");
expect(firstChoice.id).toEqual('1');
})
test('it should generate the right description', () => {
const firstChoice = choice(1, "First choice");
expect(firstChoice.description['en-US']).toEqual('First choice');
})
});
const account = require('./account');
const mbox = require('./mbox');
const opeinId = require('./openId');
const choice = require('./choice');
const IFI = {account, mbox, opeinId, choice};
module.exports = IFI;
const mbox = (mbox, isHash = false) => ({
key: isHash ? 'mbox_sha1sum' : 'mbox',
getStatement() {
return mbox
}
});
module.exports = mbox;
\ No newline at end of file
const mbox = require('./mbox');
describe('IFI: mbox', () => {
test('it should have the right key', () => {
const aliceId = mbox('fooMbox');
expect(aliceId.key).toEqual('mbox');
});
test('it should generate the right statement snippet', () => {
const aliceId = mbox('fooMbox');
expect({[aliceId.key]: aliceId.getStatement()}).toEqual({
mbox: 'fooMbox'
})
});
describe('Hex Encoded sha1 mbox identifier', () => {
test('it should have the right key', () => {
const aliceId = mbox('fooMbox', true);
expect(aliceId.key).toEqual('mbox_sha1sum');
});
test('it should generate the right statement snippet', () => {
const aliceId = mbox('fooHashedMbox', true);
expect({[aliceId.key]: aliceId.getStatement()}).toEqual({
mbox_sha1sum: 'fooHashedMbox'
})
});
})
});
\ No newline at end of file
const openId = openid => ({
key: 'openid',
getStatement() {
return openid
}
});
module.exports = openId;
\ No newline at end of file
const openId = require('./openId');
describe('IFI: openid', () => {
test('it should have the right key', () => {
const aliceId = openId('fooOpenId');
expect(aliceId.key).toEqual('openid');
});
test('it should generate the right statement snippet', () => {
const aliceId = openId('fooOpenId');
expect({[aliceId.key]: aliceId.getStatement()}).toEqual({
openid: 'fooOpenId'
})
});
});
\ No newline at end of file
const actor = (account) => {
if (account.key !== 'account') {
throw new Error('Actor must be identified by account https://github.com/AICC/CMI-5_Spec_Current/blob/quartz/cmi5_spec.md#92-actor')
}
let state = {
objectType: "Agent",
[account.key]: account.getStatement(),
};
return {
key: 'actor',
name (name) {
state = {...state, name};
return this;
},
getStatement () {
return state
},
}
};
module.exports = actor;
\ No newline at end of file
const actor = require('./actor');
describe('actor statement builder', () => {
const fixtures = {
accountStmt: {
"name": "ALICE001",
"homePage": "https://www.example.com"
}
};
const mockAccount = {
getStatement: jest.fn(() => fixtures.accountStmt),
key: 'account'
};
test('it should have the right key', () => {
const alice = actor(mockAccount);
expect(alice.key).toEqual('actor');
});
test('should generate the actor portion of the statement', () => {
const alice = actor(mockAccount);
expect(alice.getStatement()).toEqual({
"objectType": "Agent",
"account": {
"name": "ALICE001",
"homePage": "https://www.example.com"
}
});
});
test('it should reject generic IFI other than "account"', () => {
const IFI = {
key: 'ifi-name',
getStatement: () => 'some-ifi-data'
};
expect(() => actor(IFI)).toThrow();
});
test('it should allow an optional name', () => {
const alice = actor(mockAccount)
.name('Alice Cooper');
expect(alice.getStatement()).toEqual({
"objectType": "Agent",
"name": "Alice Cooper",
"account": {
"name": "ALICE001",
"homePage": "https://www.example.com"
}
});
})
});
\ No newline at end of file
const actor = require('./actor');
const answered = require('./verb/answered');
const completed = require('./verb/completed');
const failed = require('./verb/failed');
const initialized = require('./verb/initialized');
const passed = require('./verb/passed');
const registered = require('./verb/registered');
const terminated = require('./verb/terminated');
const resized = require('./verb/resized');
const polaris = {
actor,
answered,
completed,
failed,
initialized,
passed,
registered,
terminated,
resized
};
module.exports = polaris;
const statement = require('../../statement');
const {cmi5} = require('../../profiles');
const answered = () => {
let state = {};
const baseStatement = statement(cmi5.answered);
return {
...baseStatement,
result(score, success, completion, duration, response, progress) {
state = {
result: {
"score": score,
"success": success,
"completion": completion,
"duration": duration,
"response": response,
"extensions": {
"https://w3id.org/xapi/cmi5/result/extensions/progress": progress
}
}
};
return this;
},
getStatement() {
return {
...baseStatement.getStatement(),
...state,
}
}
};
};
module.exports = answered;
const answeredBuilder = require('./answered');
describe('answered verb statement builder', () => {
it('should generate the verb portion of the statement', () => {
const answered = answeredBuilder();
expect(answered.getStatement()).toEqual({
version: "1.0.3",
object: {
objectType: 'Activity',
definition: {
type: 'http://adlnet.gov/expapi/activities/cmi.interaction'
}
},
verb: {
"id": "http://adlnet.gov/expapi/verbs/answered",
"display": {
"en-US": "answered"
}
}
})
});
});
describe('result', () => {
it('should allow to define duration result', () => {
const score = {
scaled: 0,
raw: 0,
min: 0,
max: 278
}
const success = false
const completion = true
const duration = "PT0H0M48S"
const response = "2[,]5"
const progress = 3
const answered = answeredBuilder()
.result(score, success, completion, duration, response, progress);
expect(answered.getStatement()).toEqual({
version: "1.0.3",
object: {
objectType: 'Activity',
definition: {
type: 'http://adlnet.gov/expapi/activities/cmi.interaction'
}
},
verb: {
"id": "http://adlnet.gov/expapi/verbs/answered",
"display": {
"en-US": "answered"
}
},
result: {
score,
success,
completion,
duration,
response,
extensions: {
"https://w3id.org/xapi/cmi5/result/extensions/progress": progress
}
}
})
})
});
const statement = require('../../statement');
const {cmi5} = require('../../profiles');
const completed = () => {
let state = {};
const baseStatement = statement(cmi5.completed);
return {
...baseStatement,
result(duration) {
state = {
result: {
completion: true,
duration,
extensions: {
"https://w3id.org/xapi/cmi5/result/extensions/progress": 100
}
}
};
return this;
},
getStatement() {
return {
...baseStatement.getStatement(),
...state,
}
}
};
};
module.exports = completed;
\ No newline at end of file
const completedBuilder = require('./completed');
describe('completed verb statement builder', () => {
it('should generate the verb portion of the statement', () => {
const completed = completedBuilder();
expect(completed.getStatement()).toEqual({
version: "1.0.3",
object: {
objectType: 'Activity',
definition: {
type: 'http://adlnet.gov/expapi/activities/cmi.interaction'
}
},
verb: {
"id": "http://adlnet.gov/expapi/verbs/completed",
"display": {
"en-US": "completed"
}
}
})
});
});
describe('result', () => {
it('should allow to define duration result', () => {
const completed = completedBuilder()
.result('PT8H0M0S');
expect(completed.getStatement()).toEqual({
version: "1.0.3",
object: {
objectType: 'Activity',
definition: {
type: 'http://adlnet.gov/expapi/activities/cmi.interaction'
}
},
verb: {
"id": "http://adlnet.gov/expapi/verbs/completed",
"display": {
"en-US": "completed"
}
},
result: {
completion: true,
duration: 'PT8H0M0S',
extensions: {
"https://w3id.org/xapi/cmi5/result/extensions/progress": 100
}
}
})
})
});
const statement = require('../../statement');
const {cmi5} = require('../../profiles');
const failed = () => {
let state = {};
const baseStatement = statement(cmi5.failed);
return {
...baseStatement,
result(score, duration, progress) {
state = {
result: {
"score": score,
"success": false,
"completion": true,
"duration": duration,
"extensions": {
"https://w3id.org/xapi/cmi5/result/extensions/progress": progress
}
}
};
return this;
},
getStatement() {
return {
...baseStatement.getStatement(),
...state,
}
}
};
};
module.exports = failed;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment