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

feat(general): initialize default model #129

Merged
merged 21 commits into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a321a45
feat: initialize empty README
sergiulucaci Mar 11, 2019
772e5ee
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
9d3223f
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
1c6b909
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
99693f1
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
1c973b5
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
c0512e2
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
f1ab5d0
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
029b36c
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
c0d9b37
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
83f2812
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
14dbeec
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
21f9553
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
942b264
feat: implement default-model-initialization method
sergiulucaci Mar 11, 2019
2a2f1d9
fix: add babel-transform-runtime in order to support async/await
sergiulucaci Mar 12, 2019
9dbf836
Merge branch 'develop' into feat/initialize-default-model
edeustace Mar 12, 2019
a5033d2
bump yarn lock
edeustace Mar 12, 2019
70aa57c
update snapshots
edeustace Mar 12, 2019
76e8b26
Merge branch 'feat/initialize-default-model' of github.com:pie-framew…
edeustace Mar 12, 2019
00dcd3f
Merge branch 'develop' into feat/initialize-default-model
edeustace Mar 12, 2019
72b2c0f
Merge branch 'develop' into feat/initialize-default-model
evaneus Mar 12, 2019
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
3 changes: 2 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-export-default-from',
'@babel/plugin-proposal-export-namespace-from'
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-transform-runtime'
],
ignore: ['node_modules', 'packages/**/lib'],
sourceMaps: true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@pie-framework/build-helper": "^3.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @pie-element/calculator
3 changes: 3 additions & 0 deletions packages/calculator/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
mode: 'basic',
};
9 changes: 8 additions & 1 deletion packages/calculator/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import ReactDOM from 'react-dom';
import Main from './main';
import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events';

export default class extends HTMLElement {
import defaults from './defaults';

export default class Calculator extends HTMLElement {
static createDefaultModel = (model = {}) => ({
...defaults,
...model,
});

constructor() {
super();
this.onModelChanged = this.onModelChanged.bind(this);
Expand Down
44 changes: 44 additions & 0 deletions packages/categorize/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export default {
choices: [
{
id: '0',
content: '<span mathjax="" data-latex="">420\\text{ cm}=4.2\\text{ meters}</span>'
},
{
id: '1',
content: '<span mathjax="" data-latex="" data-raw="3.4\\text{ kg}=350\\text{ g}">3.4\\text{ kg}=340\\text{ g}</span>'
},
],
categories: [
{
id: '0',
label: 'Equivalent',
choices: [
{
id: '0',
content: '<span mathjax="" data-latex="">420\\text{ cm}=4.2\\text{ meters}</span>'
},
]
},
{
id: '1',
label: '<b>NOT </b>equivalent',
choices: [
{
id: '1',
content: '<span mathjax="" data-latex="">3.4\\text{ kg}=340\\text{ g}</span>'
},
]
}
],
correctResponse: [
{
category: '0',
choices: ['0']
},
{
category: '1',
choices: ['1']
}
],
};
7 changes: 7 additions & 0 deletions packages/categorize/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import {
InsertImageEvent
} from '@pie-framework/pie-configure-events';

import defaults from './defaults';

export default class CategorizeConfigure extends HTMLElement {
static createDefaultModel = (model = {}) => ({
...defaults,
...model,
});

set model(m) {
this._model = m;
this.render();
Expand Down
31 changes: 31 additions & 0 deletions packages/categorize/controller/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default {
choices: [
{
id: '0',
content: '420 cm = 4.2 meters'
},
{
id: '1',
content: '3.4 kg = 340 g'
},
],
categories: [
{
id: '0',
label: 'Equivalent',
},
{
id: '1',
label: '<b>NOT </b>equivalent',
}
],
config: {
choices: {
columns: 2,
position: 'below',
},
categories: {
columns: 2
}
}
};
9 changes: 9 additions & 0 deletions packages/categorize/controller/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { buildState, score } from '@pie-lib/categorize';
import { getFeedbackForCorrectness } from '@pie-lib/feedback';
import defaults from './defaults';
import debug from 'debug';
const log = debug('@pie-element:categorize:controller');

Expand Down Expand Up @@ -33,6 +34,14 @@ export const getCorrectness = (question, session, env) => {
});
};

export const createDefaultModel = (model = {}) =>
new Promise(resolve => {
resolve({
...defaults,
...model,
})
});

export const model = (question, session, env) =>
new Promise(resolve => {
const correctPromise = getCorrectness(question, session, env);
Expand Down
3 changes: 3 additions & 0 deletions packages/extended-text-entry/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
prompt: 'This is the question prompt',
};
9 changes: 8 additions & 1 deletion packages/extended-text-entry/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import React from 'react';
import ReactDOM from 'react-dom';
import Root from './root';

import defaults from './defaults';

const csToUi = cs => {};
/**
*
* @param
* {"{"width":"200px","height":"100px","disabled":true,"mode":"evaluate","feedback":{"type":"default","default":"Your answer has been submitted","customFeedback":"<div>Thank you very much</div>"},"id":"1","element":"extended-text-entry","value":"<div>asrt</div>","mathEnabled":false}"} ui
*/
const uiToCs = ui => {};
export default class extends HTMLElement {
export default class ExtendedTextEntry extends HTMLElement {
static createDefaultModel = (model = {}) => ({
...defaults,
...model,
});

set model(m) {
this._model = m;
this.render();
Expand Down
4 changes: 4 additions & 0 deletions packages/extended-text-entry/controller/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
prompt: '<div>This is the question prompt</div>',
width: '500px',
};
11 changes: 11 additions & 0 deletions packages/extended-text-entry/controller/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import debug from 'debug';
const log = debug('@pie-element:extended-text-entry:controller');
import { getFeedback } from '@pie-lib/feedback';

import defaults from './defaults';

export async function createDefaultModel(model = {}) {
log('[createDefaultModel]', model);

return {
...defaults,
...model,
};
}

export async function model(model, session, env) {
log('[model]', model);

Expand Down
4 changes: 4 additions & 0 deletions packages/function-entry/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
equation: '3x+2',
showFormattingHelp: true,
};
6 changes: 6 additions & 0 deletions packages/function-entry/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import Configure from './configure';
import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events';
import debug from 'debug';

import defaults from './defaults';

const log = debug('pie-elements:function-entry:configure');

export default class FunctionEntryConfigure extends HTMLElement {
static createDefaultModel = (model = {}) => ({
...defaults,
...model,
});

constructor() {
super();
Expand Down
4 changes: 4 additions & 0 deletions packages/function-entry/controller/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
equation: '3x+2',
showFormattingHelp: true,
};
11 changes: 11 additions & 0 deletions packages/function-entry/controller/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import debug from 'debug';
import mathjs from 'mathjs';
import { getFeedbackForCorrectness } from '@pie-lib/feedback';

import defaults from './defaults';

const log = debug('@pie-element:function-entry:controller');

const process = v => mathjs.simplify(v ? v.trim() : '');
Expand All @@ -14,6 +16,15 @@ const isResponseCorrect = (correctResponse, value) => {
return processedValue.equals(cr);
};

export function createDefaultModel(model = {}) {
return new Promise(resolve => {
resolve({
...defaults,
...model,
});
});
}

export function model(question, session, env) {
return new Promise(resolve => {
const { showFormattingHelp, equation, feedback } = question;
Expand Down
24 changes: 24 additions & 0 deletions packages/inline-choice/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
choices: [
{
correct: true,
value: 'sweden',
label: 'Sweden'
},
{
value: 'iceland',
label: 'Iceland',
feedback: {
type: 'default'
}
},
{
value: 'finland',
label: 'Finland',
feedback: {
type: 'custom',
value: 'Nokia was founded in Finland.'
}
}
]
};
9 changes: 8 additions & 1 deletion packages/inline-choice/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import ReactDOM from 'react-dom';
import Root from './root';
import { choiceUtils as utils } from '@pie-lib/config-ui';

export default class extends HTMLElement {
import defaults from './defaults';

export default class InlineChoice extends HTMLElement {
static createDefaultModel = (model = {}) => utils.normalizeChoices({
...defaults,
...model,
});

constructor() {
super();
this.onModelChanged = this.onModelChanged.bind(this);
Expand Down
16 changes: 16 additions & 0 deletions packages/inline-choice/controller/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
choices: [
{
value: 'sweden',
label: 'Sweden'
},
{
value: 'iceland',
label: 'Iceland',
},
{
value: 'finland',
label: 'Finland',
}
]
};
11 changes: 11 additions & 0 deletions packages/inline-choice/controller/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import debug from 'debug';

import defaults from './defaults';

const log = debug('pie-element:inline-choice:controller');

/** build a ui model to work with @pie-ui/inline-choice */

export function createDefaultModel(model = {}) {
return new Promise(resolve => {
resolve({
...defaults,
...model
});
});
}

export function model(question, session, env) {
return new Promise(resolve => {
const getResult = () => {
Expand Down
17 changes: 17 additions & 0 deletions packages/match/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
rows: [
{
id: 1,
title: 'Question Text 1',
values: [false, false]
},
{
id: 2,
title: 'Question Text 2',
values: [false, false]
},
],
layout: 3,
headers: ['Column 1', 'Column 2', 'Column 3'],
responseType: 'radio',
};
7 changes: 7 additions & 0 deletions packages/match/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ import {
} from '@pie-framework/pie-configure-events';
import debug from 'debug';

import defaults from './defaults';

const log = debug('pie-elements:match:configure');

export default class MatchConfigure extends HTMLElement {
static createDefaultModel = (model = {}) => ({
...defaults,
...model,
});

constructor() {
super();
}
Expand Down
18 changes: 18 additions & 0 deletions packages/match/controller/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
config: {
rows: [
{
id: 1,
title: 'Question Text 1',
values: [false, false]
},
{
id: 2,
title: 'Question Text 2',
values: [false, false]
},
],
layout: 3,
headers: ['Column 1', 'Column 2', 'Column 3'],
}
};
Loading