From fd2834cac8d33134bcc98f190475297293e3b73e Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Tue, 5 Mar 2019 14:49:25 +0200 Subject: [PATCH 01/42] chore(calculator): initialize empty README --- packages/calculator/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/calculator/README.md diff --git a/packages/calculator/README.md b/packages/calculator/README.md new file mode 100644 index 0000000000..25af66f802 --- /dev/null +++ b/packages/calculator/README.md @@ -0,0 +1 @@ +# @pie-element/calculator From d5f579576d84e39a65f6c9bf18d8233f1cb0bd1d Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Tue, 5 Mar 2019 14:59:27 +0200 Subject: [PATCH 02/42] chore(calculator): handle the use case where the model is incomplete/empty/undefined --- packages/calculator/configure/src/index.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/calculator/configure/src/index.js b/packages/calculator/configure/src/index.js index 9d3671ce2c..14d611675f 100644 --- a/packages/calculator/configure/src/index.js +++ b/packages/calculator/configure/src/index.js @@ -3,14 +3,25 @@ import ReactDOM from 'react-dom'; import Main from './main'; import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events'; -export default class extends HTMLElement { +export default class Calculator extends HTMLElement { + static prepareModelObject = (model = {}) => { + const { mode: modeFromProps } = model; + + const mode = modeFromProps !== 'scientific' ? 'basic' : 'scientific'; + + return { + ...model, + mode, + }; + }; + constructor() { super(); this.onModelChanged = this.onModelChanged.bind(this); } set model(s) { - this._model = s; + this._model = Calculator.prepareModelObject(s); this._render(); } From 5f8749d5080a484569fa209675c86ebcd667bea5 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 11:47:07 +0200 Subject: [PATCH 03/42] chore(extended-text-entry): implement controller method for model initialization --- .../controller/src/index.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/extended-text-entry/controller/src/index.js b/packages/extended-text-entry/controller/src/index.js index 059e5b524d..2da54af761 100644 --- a/packages/extended-text-entry/controller/src/index.js +++ b/packages/extended-text-entry/controller/src/index.js @@ -2,6 +2,25 @@ import debug from 'debug'; const log = debug('@pie-element:extended-text-entry:controller'); import { getFeedback } from '@pie-lib/feedback'; +export async function createConfigModel(model = {}) { + log('[createConfigModel]', model); + + const sensibleDefaults = { + prompt: '
This is the question prompt
', + width: '500px', + }; + + const fb = + model.feedback + ? getFeedback(model.feedback, 'Your answer has been submitted') + : Promise.resolve(undefined); + return fb.then(feedback => ({ + ...sensibleDefaults, + ...model, + feedback, + })); +} + export async function model(model, session, env) { log('[model]', model); From 989d60c49a594d70a336b2652f36ebb9774ad765 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 12:13:50 +0200 Subject: [PATCH 04/42] chore(extended-text-entry): implement config middleware to prepare the model object in order to avoid UI issues --- .../configure/src/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/extended-text-entry/configure/src/index.js b/packages/extended-text-entry/configure/src/index.js index 060bbca64f..3671e535cf 100644 --- a/packages/extended-text-entry/configure/src/index.js +++ b/packages/extended-text-entry/configure/src/index.js @@ -10,9 +10,24 @@ const csToUi = cs => {}; * {"{"width":"200px","height":"100px","disabled":true,"mode":"evaluate","feedback":{"type":"default","default":"Your answer has been submitted","customFeedback":"
Thank you very much
"},"id":"1","element":"extended-text-entry","value":"
asrt
","mathEnabled":false}"} ui */ const uiToCs = ui => {}; -export default class extends HTMLElement { +export default class ExtendedTextEntry extends HTMLElement { + static prepareModelObject = (model = {}) => { + const { feedback, prompt, width } = model; + + const sensibleDefault = { + feedback: feedback || {type: 'default', default: 'this is default feedback'}, + prompt: prompt || 'This is the question prompt', + width: width || '500px', + }; + + return { + ...sensibleDefault, + ...model, + }; + }; + set model(m) { - this._model = m; + this._model = ExtendedTextEntry.prepareModelObject(m); this.render(); } From dec4391e884a5c3aae6d411f284a082de4d1ac11 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 12:17:27 +0200 Subject: [PATCH 05/42] chore(calculator): make config calculator defaults sensible --- packages/calculator/configure/src/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/calculator/configure/src/index.js b/packages/calculator/configure/src/index.js index 14d611675f..32dbca5106 100644 --- a/packages/calculator/configure/src/index.js +++ b/packages/calculator/configure/src/index.js @@ -5,13 +5,11 @@ import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events'; export default class Calculator extends HTMLElement { static prepareModelObject = (model = {}) => { - const { mode: modeFromProps } = model; - - const mode = modeFromProps !== 'scientific' ? 'basic' : 'scientific'; + const { mode } = model; return { + mode: mode || 'basic', ...model, - mode, }; }; From 34376ce7d836d0f3bdbe9f2a240894243592fecc Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 12:43:27 +0200 Subject: [PATCH 06/42] chore(function-entry): implement config middleware to prepare the model object in order to avoid UI issues --- packages/function-entry/configure/src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/function-entry/configure/src/index.js b/packages/function-entry/configure/src/index.js index ffb0bb2e45..f8f8dc5b71 100644 --- a/packages/function-entry/configure/src/index.js +++ b/packages/function-entry/configure/src/index.js @@ -7,13 +7,23 @@ import debug from 'debug'; const log = debug('pie-elements:function-entry:configure'); export default class FunctionEntryConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + showFormattingHelp: true, + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; constructor() { super(); } set model(m) { - this._model = m; + this._model = FunctionEntryConfigure.prepareModelObject(m); this._render(); } From 93c734ee323950f0cb6af6187ebc1b6c87fac280 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 12:55:22 +0200 Subject: [PATCH 07/42] chore(function-entry): implement controller method for model initialization --- packages/function-entry/controller/src/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/function-entry/controller/src/index.js b/packages/function-entry/controller/src/index.js index b79b5e6ecb..87766e0150 100644 --- a/packages/function-entry/controller/src/index.js +++ b/packages/function-entry/controller/src/index.js @@ -14,6 +14,17 @@ const isResponseCorrect = (correctResponse, value) => { return processedValue.equals(cr); }; +export function createConfigModel(model = {}) { + const sensibleDefaults = { + showFormattingHelp: true, + }; + + return { + ...sensibleDefaults, + ...model, + }; +} + export function model(question, session, env) { return new Promise(resolve => { const { showFormattingHelp, equation, feedback } = question; From df1537a0b2ae385150514c61a3f5b16f3cbb88bf Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 13:30:06 +0200 Subject: [PATCH 08/42] chore(inline-choice): implement config middleware to prepare the model object in order to avoid UI issues --- packages/inline-choice/configure/src/index.js | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/inline-choice/configure/src/index.js b/packages/inline-choice/configure/src/index.js index 3da689359b..3f74ffb9ad 100755 --- a/packages/inline-choice/configure/src/index.js +++ b/packages/inline-choice/configure/src/index.js @@ -5,14 +5,48 @@ import ReactDOM from 'react-dom'; import Root from './root'; import { choiceUtils as utils } from '@pie-lib/config-ui'; -export default class extends HTMLElement { +export default class InlineChoice extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + 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.' + } + } + ] + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); this.onModelChanged = this.onModelChanged.bind(this); } set model(s) { - this._model = utils.normalizeChoices(s); + const modelParsed = InlineChoice.prepareModelObject(s); + + this._model = utils.normalizeChoices(modelParsed); this._render(); } From 1679eedfad0c861e793b28ea7dccfb00091def56 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 13:42:25 +0200 Subject: [PATCH 09/42] chore(inline-choice): implement controller method for model initialization --- .../inline-choice/controller/src/index.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/inline-choice/controller/src/index.js b/packages/inline-choice/controller/src/index.js index 0bf8a3fb12..3044833c74 100644 --- a/packages/inline-choice/controller/src/index.js +++ b/packages/inline-choice/controller/src/index.js @@ -4,6 +4,32 @@ const log = debug('pie-element:inline-choice:controller'); /** build a ui model to work with @pie-ui/inline-choice */ +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const sensibleDefaults = { + choices: [ + { + value: 'sweden', + label: 'Sweden' + }, + { + value: 'iceland', + label: 'Iceland', + }, + { + value: 'finland', + label: 'Finland', + } + ] + }; + + resolve({ + ...sensibleDefaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const getResult = () => { From c03e445f13f840a49b1fee05ff26a1e33f51519a Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 14:57:17 +0200 Subject: [PATCH 10/42] chore(graph-lines): implement config middleware to prepare the model object in order to avoid UI issues --- packages/graph-lines/configure/src/index.js | 39 ++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/graph-lines/configure/src/index.js b/packages/graph-lines/configure/src/index.js index f86ffc73ea..0a14247132 100644 --- a/packages/graph-lines/configure/src/index.js +++ b/packages/graph-lines/configure/src/index.js @@ -7,12 +7,49 @@ import debug from 'debug'; const log = debug('pie-elements:graph-lines:configure'); export default class GraphLinesConfigure extends HTMLElement { + static prepareModelObject = () => { + const model = { }; + + const sensibleDefaults = { + model: { + config: { + lines: [{ + label: 'Line One', + correctLine: '3x+2', + initialView: '3x+3' + }], + domainMin: -10, + domainMax: 10, + domainStepValue: 1, + domainSnapValue: 1, + domainLabelFrequency: 1, + domainGraphPadding: 50, + rangeMin: -10, + rangeMax: 10, + rangeStepValue: 1, + rangeSnapValue: 1, + rangeLabelFrequency: 1, + rangeGraphPadding: 50, + showPointLabels: true, + showInputs: true, + showAxisLabels: true, + showFeedback: true + } + } + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); } set model(m) { - this._model = m; + this._model = GraphLinesConfigure.prepareModelObject(m); this._render(); } From 3007538383da3b4a8e2385981a14bdbdb652d29e Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 15:00:03 +0200 Subject: [PATCH 11/42] chore(graph-lines): accept model as a parameter for the config middleware --- packages/graph-lines/configure/src/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/graph-lines/configure/src/index.js b/packages/graph-lines/configure/src/index.js index 0a14247132..479d3cb888 100644 --- a/packages/graph-lines/configure/src/index.js +++ b/packages/graph-lines/configure/src/index.js @@ -7,9 +7,7 @@ import debug from 'debug'; const log = debug('pie-elements:graph-lines:configure'); export default class GraphLinesConfigure extends HTMLElement { - static prepareModelObject = () => { - const model = { }; - + static prepareModelObject = (model = {}) => { const sensibleDefaults = { model: { config: { From fd9d94cb2617878a09696639f3eac20293e31b3e Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 15:31:30 +0200 Subject: [PATCH 12/42] chore(graph-lines): undo config middleware changes --- packages/graph-lines/configure/src/index.js | 37 +-------------------- 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/packages/graph-lines/configure/src/index.js b/packages/graph-lines/configure/src/index.js index 479d3cb888..f86ffc73ea 100644 --- a/packages/graph-lines/configure/src/index.js +++ b/packages/graph-lines/configure/src/index.js @@ -7,47 +7,12 @@ import debug from 'debug'; const log = debug('pie-elements:graph-lines:configure'); export default class GraphLinesConfigure extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - model: { - config: { - lines: [{ - label: 'Line One', - correctLine: '3x+2', - initialView: '3x+3' - }], - domainMin: -10, - domainMax: 10, - domainStepValue: 1, - domainSnapValue: 1, - domainLabelFrequency: 1, - domainGraphPadding: 50, - rangeMin: -10, - rangeMax: 10, - rangeStepValue: 1, - rangeSnapValue: 1, - rangeLabelFrequency: 1, - rangeGraphPadding: 50, - showPointLabels: true, - showInputs: true, - showAxisLabels: true, - showFeedback: true - } - } - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; - constructor() { super(); } set model(m) { - this._model = GraphLinesConfigure.prepareModelObject(m); + this._model = m; this._render(); } From c6ae996b11a127d3d07c9d2e0b79be5c66243e06 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 16:02:01 +0200 Subject: [PATCH 13/42] chore(categorize): implement config middleware to prepare the model object in order to avoid UI issues --- packages/categorize/configure/src/index.js | 63 +++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/packages/categorize/configure/src/index.js b/packages/categorize/configure/src/index.js index 07e1b1a840..65c46d11ab 100644 --- a/packages/categorize/configure/src/index.js +++ b/packages/categorize/configure/src/index.js @@ -8,8 +8,69 @@ import { } from '@pie-framework/pie-configure-events'; export default class CategorizeConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + choices: [ + { + id: '0', + content: '420\\text{ cm}=4.2\\text{ meters}' + }, + { + id: '1', + content: '3.4\\text{ kg}=340\\text{ g}' + }, + ], + categories: [ + { + id: '0', + label: 'Equivalent', + choices: [ + { + id: '0', + content: '420\\text{ cm}=4.2\\text{ meters}' + }, + ] + }, + { + id: '1', + label: 'NOT equivalent', + choices: [ + { + id: '1', + content: '3.4\\text{ kg}=340\\text{ g}' + }, + ] + } + ], + correctResponse: [ + { + category: '0', + choices: ['0'] + }, + { + category: '1', + choices: ['1'] + } + ], + config: { + choices: { + columns: 2, + position: 'below', + }, + categories: { + columns: 2 + } + } + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + set model(m) { - this._model = m; + this._model = CategorizeConfigure.prepareModelObject(m); this.render(); } From 4c742fde91e2fc81f52c2779fb100bc61458efa2 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 16:26:01 +0200 Subject: [PATCH 14/42] chore(categorize): implement controller method for model initialization --- packages/categorize/controller/src/index.js | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/categorize/controller/src/index.js b/packages/categorize/controller/src/index.js index b96730c38a..d454d1755d 100644 --- a/packages/categorize/controller/src/index.js +++ b/packages/categorize/controller/src/index.js @@ -33,6 +33,46 @@ export const getCorrectness = (question, session, env) => { }); }; +export const createConfigModel = (model = {}) => + new Promise(resolve => { + const sensibleDefaults = { + 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: 'NOT equivalent', + } + ], + config: { + choices: { + columns: 2, + position: 'below', + }, + categories: { + columns: 2 + } + } + }; + + resolve({ + ...sensibleDefaults, + ...model, + }) + }); + export const model = (question, session, env) => new Promise(resolve => { const correctPromise = getCorrectness(question, session, env); From c1c92e81d1bd672d33e322fdfec06c3ddc790e30 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 16:35:21 +0200 Subject: [PATCH 15/42] chore(match): implement config middleware to prepare the model object in order to avoid UI issues --- packages/match/configure/src/index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/match/configure/src/index.js b/packages/match/configure/src/index.js index b0477bd4fe..5d63e7ebe9 100644 --- a/packages/match/configure/src/index.js +++ b/packages/match/configure/src/index.js @@ -11,12 +11,32 @@ import debug from 'debug'; const log = debug('pie-elements:match:configure'); export default class MatchConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + rows: [ + { + id: 1, + title: 'Question Text 1', + values: [false, false] + } + ], + layout: 3, + headers: ['Column 1', 'Column 2', 'Column 3'], + responseType: 'radio', + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); } set model(m) { - this._model = m; + this._model = MatchConfigure.prepareModelObject(m); this._render(); } From bc48a40d8187b197e6d4601a9ea01d8a6937b0a5 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 16:41:15 +0200 Subject: [PATCH 16/42] chore(match): implement controller method for model initialization --- packages/match/controller/src/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/match/controller/src/index.js b/packages/match/controller/src/index.js index fc46575fd9..c014103829 100644 --- a/packages/match/controller/src/index.js +++ b/packages/match/controller/src/index.js @@ -98,6 +98,30 @@ export const outcome = (question, session, env) => { }); }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const sensibleDefaults = { + config: { + rows: [ + { + id: 1, + title: 'Question Text 1', + values: [false, false] + } + ], + layout: 3, + headers: ['Column 1', 'Column 2', 'Column 3'], + responseType: 'radio', + } + }; + + resolve({ + ...sensibleDefaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const correctness = getCorrectness(question, env, session.answers); From 3c3a3ab0cdb1ad692fd16146f39799a4de9d5bc1 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 16:52:57 +0200 Subject: [PATCH 17/42] chore(math-inline): implement config middleware to prepare the model object in order to avoid UI issues --- packages/math-inline/configure/src/index.js | 32 ++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/math-inline/configure/src/index.js b/packages/math-inline/configure/src/index.js index 0fb2427b26..fdd3ccfd82 100644 --- a/packages/math-inline/configure/src/index.js +++ b/packages/math-inline/configure/src/index.js @@ -7,12 +7,42 @@ import debug from 'debug'; const log = debug('pie-elements:math-inline:configure'); export default class MathInlineConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + mode: 'advanced', + expression: 'y = ', + question: 'What is the equation for a slope?', + equationEditor: 'everything', + defaultResponse: { + id: 0, + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }, + responses: [{ + id: 'answerBlock1', + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }], + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); } set model(m) { - this._model = m; + this._model = MathInlineConfigure.prepareModelObject(m); this._render(); } From 05a40eedc0d0468663fba32a05c363a64bbc0467 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 16:58:16 +0200 Subject: [PATCH 18/42] chore(math-inline): implement controller method for model initialization --- packages/math-inline/controller/src/index.js | 34 ++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/math-inline/controller/src/index.js b/packages/math-inline/controller/src/index.js index de6c5e5dc8..aa5efeb46f 100644 --- a/packages/math-inline/controller/src/index.js +++ b/packages/math-inline/controller/src/index.js @@ -71,6 +71,40 @@ const getCorrectness = (question, env, answers) => { } }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const sensibleDefaults = { + config: { + mode: 'advanced', + expression: 'y = ', + question: 'What is the equation for a slope?', + equationEditor: 'everything', + defaultResponse: { + id: 0, + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }, + responses: [{ + id: 'answerBlock1', + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }], + } + }; + + resolve({ + ...sensibleDefaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const correctness = getCorrectness(question, env, session.answers); From 2682307b95029dfd46b04e3430c0aae2afe2e89b Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 17:08:25 +0200 Subject: [PATCH 19/42] chore(multiple-choice): implement config middleware to prepare the model object in order to avoid UI issues --- .../multiple-choice/configure/src/index.js | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/multiple-choice/configure/src/index.js b/packages/multiple-choice/configure/src/index.js index aedbcf4953..81c4f7b016 100644 --- a/packages/multiple-choice/configure/src/index.js +++ b/packages/multiple-choice/configure/src/index.js @@ -59,7 +59,31 @@ const prepareCustomizationObject = (configure, model) => { }; }; -export default class extends HTMLElement { +export default class MultipleChoice extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + prompt: 'Which of these northern European countries are EU members?', + choiceMode: 'checkbox', + keyMode: 'numbers', + choices: [ + { + correct: true, + value: 'sweden', + label: 'Sweden', + }, + { + value: 'iceland', + label: 'Iceland', + }, + ], + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); this.onModelChanged = this.onModelChanged.bind(this); @@ -67,7 +91,9 @@ export default class extends HTMLElement { } set model(s) { - this._model = utils.normalizeChoices(s); + const modelParsed = MultipleChoice.prepareModelObject(s); + + this._model = utils.normalizeChoices(modelParsed); this._render(); } From 4ed98d770971918af4f2f53886525aef2c8b08f7 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Wed, 6 Mar 2019 17:11:47 +0200 Subject: [PATCH 20/42] chore(multiple-choice): implement controller method for model initialization --- .../multiple-choice/controller/src/index.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/multiple-choice/controller/src/index.js b/packages/multiple-choice/controller/src/index.js index efc78dd240..df88b9b175 100644 --- a/packages/multiple-choice/controller/src/index.js +++ b/packages/multiple-choice/controller/src/index.js @@ -25,6 +25,32 @@ const prepareChoice = (mode, defaultFeedback) => choice => { return out; }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const sensibleDefaults = { + prompt: 'Which of these northern European countries are EU members?', + choiceMode: 'checkbox', + keyMode: 'numbers', + choices: [ + { + correct: true, + value: 'sweden', + label: 'Sweden', + }, + { + value: 'iceland', + label: 'Iceland', + }, + ], + }; + + resolve({ + ...sensibleDefaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise((resolve, reject) => { const defaultFeedback = Object.assign( From 1db14905e557dacf37a7441ff8190d36caf05ada Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 08:59:17 +0200 Subject: [PATCH 21/42] chore(number-line): implement config middleware to prepare the model object in order to avoid UI issues --- packages/number-line/configure/src/index.js | 53 ++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/number-line/configure/src/index.js b/packages/number-line/configure/src/index.js index a13b25de6c..b227615a86 100644 --- a/packages/number-line/configure/src/index.js +++ b/packages/number-line/configure/src/index.js @@ -3,12 +3,63 @@ import React from 'react'; import ReactDOM from 'react-dom'; export default class NumberLineConfigReactElement extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + correctResponse: [ + { + type: 'point', + pointType: 'full', + domainPosition: 1 + }, + { + type: 'line', + leftPoint: 'full', + rightPoint: 'empty', + domainPosition: 1, + size: 2 + } + ], + config: { + domain: [-5, 5], + initialElements: [ + { + type: 'point', + pointType: 'empty', + domainPosition: -1 + } + ], + maxNumberOfPoints: 20, + tickFrequency: 6, + showMinorTicks: true, + snapPerTick: 1, + initialType: 'PF', + availableTypes: { + PF: true, + PE: true, + LFF: true, + LEF: true, + LFE: true, + LEE: true, + RFN: true, + RFP: true, + REN: true, + REP: true + } + } + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); } set model(s) { - this._model = s; + this._model = NumberLineConfigReactElement.prepareModelObject(s); this._rerender(); } From 12fac7070dc46a728bfa3faaa9d23ec086f8a0ee Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 09:20:08 +0200 Subject: [PATCH 22/42] chore(number-line): implement controller method for model initialization --- packages/number-line/controller/src/index.js | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/packages/number-line/controller/src/index.js b/packages/number-line/controller/src/index.js index d4d6aecd9b..e425b52cab 100644 --- a/packages/number-line/controller/src/index.js +++ b/packages/number-line/controller/src/index.js @@ -141,6 +141,49 @@ export function normalize(question) { }); } +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const sensibleDefaults = { + config: { + domain: [-5, 5], + initialElements: [ + { + type: 'point', + pointType: 'empty', + domainPosition: -1 + } + ], + maxNumberOfPoints: 20, + tickFrequency: 6, + showMinorTicks: true, + snapPerTick: 1, + tickLabelOverrides: [], + initialType: 'PF', + availableTypes: { + PF: true, + PE: true, + LFF: true, + LEF: true, + LFE: true, + LEE: true, + RFN: true, + RFP: true, + REN: true, + REP: true + } + }, + colorContrast: 'black_on_white', + }; + + const out = { + ...sensibleDefaults, + ...model + }; + + resolve(omitBy(out, v => !v)); + }); +} + export function model(question, session, env) { if (!question) { return Promise.reject(new Error('question is null')); From b106fed90db51ae803f708b456c110317ad0327c Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 12:30:21 +0200 Subject: [PATCH 23/42] chore(placement-ordering): implement config middleware to prepare the model object in order to avoid UI issues --- .../configure/src/defaultConfiguration.js | 85 +++++++++++++++---- .../placement-ordering/configure/src/index.js | 15 ++-- 2 files changed, 75 insertions(+), 25 deletions(-) diff --git a/packages/placement-ordering/configure/src/defaultConfiguration.js b/packages/placement-ordering/configure/src/defaultConfiguration.js index 0c8f75d83b..0002047696 100644 --- a/packages/placement-ordering/configure/src/defaultConfiguration.js +++ b/packages/placement-ordering/configure/src/defaultConfiguration.js @@ -1,19 +1,68 @@ export default { - orientationLabel: 'Orientation', - shuffleLabel: 'Highlight choices', - includePlacementAreaLabel: 'Include placement area', - numberedGuidesLabel: 'Numbered guides', - promptLabel: 'Prompt', - choiceLabel: 'Choice label', - choicesLabel: 'Choices', - removeTilesLabel: 'Remove all tiles after placing', - enableOrientationChange: true, - enableShuffleChange: true, - enablePlacementAreaChange: true, - enableNumberedGuideChange: true, - enablePromptChange: true, - enableChoiceLabelChange: true, - enableChoicesLabelChange: true, - enableRemoveTiles: true, - enableFeedback: true -}; \ No newline at end of file + configure: { + orientationLabel: 'Orientation', + shuffleLabel: 'Highlight choices', + includePlacementAreaLabel: 'Include placement area', + numberedGuidesLabel: 'Numbered guides', + promptLabel: 'Prompt', + choiceLabel: 'Choice label', + choicesLabel: 'Choices', + removeTilesLabel: 'Remove all tiles after placing', + enableOrientationChange: true, + enableShuffleChange: true, + enablePlacementAreaChange: true, + enableNumberedGuideChange: true, + enablePromptChange: true, + enableChoiceLabelChange: true, + enableChoicesLabelChange: true, + enableRemoveTiles: true, + enableFeedback: true, + }, + correctResponse: [ + { + id: 'c1', + weight: 0.2 + }, + { + id: 'c4', + weight: 0.2 + }, + { + id: 'c3', + weight: 0.3 + }, + { + id: 'c2', + weight: 0.3 + } + ], + prompt: 'Arrange the fruits alphabetically', + choices: [ + { + id: 'c2', + label: 'Lemon', + shuffle: false, + moveOnDrag: true + }, + { + id: 'c3', + label: 'Melon', + moveOnDrag: true + }, + { + id: 'c1', + label: 'Blueberry', + moveOnDrag: false + }, + { + id: 'c4', + label: 'Pear', + moveOnDrag: false + } + ], + placementType: 'none', + choiceAreaLayout: 'vertical', + choiceAreaLabel: 'choices: ', + answerAreaLabel: 'Answer Area Label', + showOrdering: true, +}; diff --git a/packages/placement-ordering/configure/src/index.js b/packages/placement-ordering/configure/src/index.js index b8642d9a02..1170898343 100644 --- a/packages/placement-ordering/configure/src/index.js +++ b/packages/placement-ordering/configure/src/index.js @@ -10,14 +10,15 @@ import ReactDOM from 'react-dom'; import defaultValues from './defaultConfiguration'; import defaults from 'lodash/defaults'; -const prepareCustomizationObject = (model) => { - return { - ...model, - configure: defaults(model.configure, defaultValues) +export default class PlacementOrdering extends HTMLElement { + static prepareModelObject = (model = {}) => { + return { + ...defaultValues, + configure: defaults(model.configure, defaultValues.configure), + ...model + }; }; -}; -export default class PlacementOrdering extends HTMLElement { constructor() { super(); this.onModelChange = (model, resetSession) => { @@ -40,7 +41,7 @@ export default class PlacementOrdering extends HTMLElement { } set model(s) { - this._model = prepareCustomizationObject(s); + this._model = PlacementOrdering.prepareModelObject(s); this._rerender(); } From 6b6e76e41eba4eff82c9c6ddcd137ffd26b99fe5 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 12:39:36 +0200 Subject: [PATCH 24/42] chore(placement-ordering): implement controller method for model initialization --- .../controller/src/index.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/packages/placement-ordering/controller/src/index.js b/packages/placement-ordering/controller/src/index.js index 439cc291b6..7e709593fa 100644 --- a/packages/placement-ordering/controller/src/index.js +++ b/packages/placement-ordering/controller/src/index.js @@ -70,6 +70,49 @@ function shuffle(session, choices) { } } +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const sensibleDefaults = { + choices: [ + { + id: 'c2', + label: 'Lemon', + shuffle: false, + moveOnDrag: true + }, + { + id: 'c3', + label: 'Melon', + moveOnDrag: true + }, + { + id: 'c1', + label: 'Blueberry', + moveOnDrag: false + }, + { + id: 'c4', + label: 'Pear', + moveOnDrag: false + } + ], + completeLength: 4, + config: { + orientation: 'vertical', + targetLabel: 'Answer Area Label', + choiceLabel: 'choices: ', + showOrdering: true + }, + prompt: 'Arrange the fruits alphabetically', + }; + + resolve({ + ...sensibleDefaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise((resolve, reject) => { const base = {}; From b47360270a37c9e75e2299c308fa79c963c64b0c Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 13:34:10 +0200 Subject: [PATCH 25/42] chore(ruler): implement config middleware to prepare the model object in order to avoid UI issues --- packages/ruler/configure/src/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/ruler/configure/src/index.js b/packages/ruler/configure/src/index.js index 736fe67ab7..e86317e466 100644 --- a/packages/ruler/configure/src/index.js +++ b/packages/ruler/configure/src/index.js @@ -16,6 +16,19 @@ const defaultModel = () => ({ }); export default class RulerConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + measure: 'metric', + label: 'm', + units: 10, + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + connectedCallback() { setTimeout(() => { if (!this._model) { @@ -28,7 +41,7 @@ export default class RulerConfigure extends HTMLElement { set model(m) { console.log('m?', m); - this._model = m; + this._model = RulerConfigure.prepareModelObject(m); this.render(); } From 8d77c4cc0ee901fea314f645af99c87b37a75b42 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 14:02:25 +0200 Subject: [PATCH 26/42] chore(select-text): implement config middleware to prepare the model object in order to avoid UI issues --- .../configure/src/defaultConfiguration.js | 79 ++++++++++++++----- packages/select-text/configure/src/index.js | 15 ++-- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/packages/select-text/configure/src/defaultConfiguration.js b/packages/select-text/configure/src/defaultConfiguration.js index dead906413..eec488c580 100644 --- a/packages/select-text/configure/src/defaultConfiguration.js +++ b/packages/select-text/configure/src/defaultConfiguration.js @@ -1,19 +1,62 @@ +const tokens = () => [ + { + text: 'Rachel cut out 8 stars in 6 minutes.', + start: 0, + end: 36, + correct: true + }, + { + text: 'Lovelle cut out 6 stars in 4 minutes.', + start: 37, + end: 74, + correct: true + }, + { + text: 'Lovelle and Rachel cut the same number of stars in 6 minutes.', + start: 117, + end: 177 + } +]; + export default { - promptLabel: 'Prompt', - contentLabel : 'Content', - highlightChoicesLabel: 'Highlight choices', - tokensLabel: 'Tokens', - setCorrectAnswersLabel: 'Set correct answers', - modeLabel: 'Mode', - availableSelectionsLabel: 'Selections Available', - correctAnswersLabel: 'Correct Answers', - selectionCountLabel: 'Selection count', - enableContentChange: true, - enableHighlightChoices: true, - enableTokensChange: true, - showMode: true, - showSelections: true, - showCorrectAnswersNumber: true, - showSelectionCount: true, - enableFeedback: true -}; \ No newline at end of file + highlightChoices: true, + feedback: { + correct: { + type: 'default', + default: 'Correct' + }, + incorrect: { + type: 'default', + default: 'Incorrect' + }, + partial: { + type: 'default', + default: 'Nearly' + } + }, + partialScoring: false, + maxSelections: 2, + mode: 'sentence', + prompt: 'What sentences contain the character 6 in them?', + text: + 'Rachel cut out 8 stars in 6 minutes. Lovelle cut out 6 stars in 4 minutes. Rachel cut out 4 more stars than Lovelle. Lovelle and Rachel cut the same number of stars in 6 minutes.', + tokens: tokens(), + configure: { + contentLabel: 'Content', + highlightChoicesLabel: 'Highlight choices', + tokensLabel: 'Tokens', + setCorrectAnswersLabel: 'Set correct answers', + modeLabel: 'Mode', + availableSelectionsLabel: 'Selections Available', + correctAnswersLabel: 'Correct Answers', + selectionCountLabel: 'Selection count', + enableContentChange: true, + enableHighlightChoices: true, + enableTokensChange: true, + showMode: true, + showSelections: true, + showCorrectAnswersNumber: true, + showSelectionCount: true, + enableFeedback: true + } +}; diff --git a/packages/select-text/configure/src/index.js b/packages/select-text/configure/src/index.js index 8943ee89be..153d606f5d 100644 --- a/packages/select-text/configure/src/index.js +++ b/packages/select-text/configure/src/index.js @@ -9,20 +9,21 @@ import { import defaults from 'lodash/defaults'; import defaultValues from './defaultConfiguration'; -const prepareCustomizationObject = model => { - return { - ...model, - configure: defaults(model.configure, defaultValues) +export default class SelectTextConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + return { + ...defaultValues, + configure: defaults(model.configure, defaultValues.configure), + ...model, + }; }; -}; -export default class SelectTextConfigure extends HTMLElement { constructor() { super(); } set model(m) { - this._model = prepareCustomizationObject(m); + this._model = SelectTextConfigure.prepareModelObject(m); this.render(); } From 444533ddb05648b03a0ddfe70060c0d53cd6a77b Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 14:14:24 +0200 Subject: [PATCH 27/42] chore(select-text): implement controller method for model initialization --- packages/select-text/controller/src/index.js | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/select-text/controller/src/index.js b/packages/select-text/controller/src/index.js index 363f484066..3166b97972 100644 --- a/packages/select-text/controller/src/index.js +++ b/packages/select-text/controller/src/index.js @@ -81,6 +81,42 @@ export const outcome = (question, session, env) => { }); }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const tokens = () => [ + { + text: 'Rachel cut out 8 stars in 6 minutes.', + start: 0, + end: 36, + }, + { + text: 'Lovelle cut out 6 stars in 4 minutes.', + start: 37, + end: 74, + }, + { + text: 'Lovelle and Rachel cut the same number of stars in 6 minutes.', + start: 117, + end: 177 + } + ]; + + const sensibleDefaults = { + highlightChoices: true, + maxSelections: 2, + prompt: 'What sentences contain the character 6 in them?', + text: + 'Rachel cut out 8 stars in 6 minutes. Lovelle cut out 6 stars in 4 minutes. Rachel cut out 4 more stars than Lovelle. Lovelle and Rachel cut the same number of stars in 6 minutes.', + tokens: tokens(), + }; + + resolve({ + ...sensibleDefaults, + ...model + }); + }); +} + export const model = (question, session, env) => { return new Promise((resolve, reject) => { log('[model]', 'question: ', question); From a4c4dfda75564a8c529b5a51af6bc0ff955f100e Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 14:25:37 +0200 Subject: [PATCH 28/42] chore(text-configure): implement config middleware to prepare the model object in order to avoid UI issues --- packages/text-entry/configure/src/index.js | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/text-entry/configure/src/index.js b/packages/text-entry/configure/src/index.js index 8e2a598d57..c695b4a9ee 100644 --- a/packages/text-entry/configure/src/index.js +++ b/packages/text-entry/configure/src/index.js @@ -7,12 +7,38 @@ import debug from 'debug'; const log = debug('pie-elements:text-entry:configure'); export default class TextEntryConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => { + const sensibleDefaults = { + correctResponses: { + values: ['mutt', 'hound'], + ignoreWhitespace: true, + ignoreCase: false + }, + partialResponses: { + values: ['mutty'], + ignoreWhitespace: true, + ignoreCase: true, + awardPercentage: '50' + }, + answerBlankSize: '10', + answerAlignment: 'left', + prompt: 'Question Prompt goes here', + allowDecimal: true, + allowThousandsSeparator: true + }; + + return { + ...sensibleDefaults, + ...model, + }; + }; + constructor() { super(); } set model(m) { - this._model = m; + this._model = TextEntryConfigure.prepareModelObject(m); this._render(); } From 52ad744c60a146e6cdfd7b00b5c83d77b2ef6799 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 15:52:02 +0200 Subject: [PATCH 29/42] chore(calculator): place default values in a separate file --- packages/calculator/configure/src/defaults.js | 3 +++ packages/calculator/configure/src/index.js | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 packages/calculator/configure/src/defaults.js diff --git a/packages/calculator/configure/src/defaults.js b/packages/calculator/configure/src/defaults.js new file mode 100644 index 0000000000..ace2c15a5b --- /dev/null +++ b/packages/calculator/configure/src/defaults.js @@ -0,0 +1,3 @@ +export default { + mode: 'basic', +}; diff --git a/packages/calculator/configure/src/index.js b/packages/calculator/configure/src/index.js index 32dbca5106..abfaaca678 100644 --- a/packages/calculator/configure/src/index.js +++ b/packages/calculator/configure/src/index.js @@ -3,15 +3,13 @@ import ReactDOM from 'react-dom'; import Main from './main'; import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events'; -export default class Calculator extends HTMLElement { - static prepareModelObject = (model = {}) => { - const { mode } = model; +import defaults from './defaults'; - return { - mode: mode || 'basic', - ...model, - }; - }; +export default class Calculator extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); From c87a0a730ca8285f86c983e718eef594b3a0cacd Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 16:03:08 +0200 Subject: [PATCH 30/42] chore(categorize): place default values in a separate file --- packages/categorize/configure/src/defaults.js | 53 +++++++++++++++ packages/categorize/configure/src/index.js | 68 ++----------------- .../categorize/controller/src/defaults.js | 31 +++++++++ packages/categorize/controller/src/index.js | 35 +--------- 4 files changed, 93 insertions(+), 94 deletions(-) create mode 100644 packages/categorize/configure/src/defaults.js create mode 100644 packages/categorize/controller/src/defaults.js diff --git a/packages/categorize/configure/src/defaults.js b/packages/categorize/configure/src/defaults.js new file mode 100644 index 0000000000..89df1f12ee --- /dev/null +++ b/packages/categorize/configure/src/defaults.js @@ -0,0 +1,53 @@ +export default { + choices: [ + { + id: '0', + content: '420\\text{ cm}=4.2\\text{ meters}' + }, + { + id: '1', + content: '3.4\\text{ kg}=340\\text{ g}' + }, + ], + categories: [ + { + id: '0', + label: 'Equivalent', + choices: [ + { + id: '0', + content: '420\\text{ cm}=4.2\\text{ meters}' + }, + ] + }, + { + id: '1', + label: 'NOT equivalent', + choices: [ + { + id: '1', + content: '3.4\\text{ kg}=340\\text{ g}' + }, + ] + } + ], + correctResponse: [ + { + category: '0', + choices: ['0'] + }, + { + category: '1', + choices: ['1'] + } + ], + config: { + choices: { + columns: 2, + position: 'below', + }, + categories: { + columns: 2 + } + } +}; diff --git a/packages/categorize/configure/src/index.js b/packages/categorize/configure/src/index.js index 65c46d11ab..2c791042d5 100644 --- a/packages/categorize/configure/src/index.js +++ b/packages/categorize/configure/src/index.js @@ -7,70 +7,16 @@ import { InsertImageEvent } from '@pie-framework/pie-configure-events'; -export default class CategorizeConfigure extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - choices: [ - { - id: '0', - content: '420\\text{ cm}=4.2\\text{ meters}' - }, - { - id: '1', - content: '3.4\\text{ kg}=340\\text{ g}' - }, - ], - categories: [ - { - id: '0', - label: 'Equivalent', - choices: [ - { - id: '0', - content: '420\\text{ cm}=4.2\\text{ meters}' - }, - ] - }, - { - id: '1', - label: 'NOT equivalent', - choices: [ - { - id: '1', - content: '3.4\\text{ kg}=340\\text{ g}' - }, - ] - } - ], - correctResponse: [ - { - category: '0', - choices: ['0'] - }, - { - category: '1', - choices: ['1'] - } - ], - config: { - choices: { - columns: 2, - position: 'below', - }, - categories: { - columns: 2 - } - } - }; +import defaults from './defaults'; - return { - ...sensibleDefaults, - ...model, - }; - }; +export default class CategorizeConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); set model(m) { - this._model = CategorizeConfigure.prepareModelObject(m); + this._model = CategorizeConfigure.prepareModelObject(); this.render(); } diff --git a/packages/categorize/controller/src/defaults.js b/packages/categorize/controller/src/defaults.js new file mode 100644 index 0000000000..52d2a25bdd --- /dev/null +++ b/packages/categorize/controller/src/defaults.js @@ -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: 'NOT equivalent', + } + ], + config: { + choices: { + columns: 2, + position: 'below', + }, + categories: { + columns: 2 + } + } +}; diff --git a/packages/categorize/controller/src/index.js b/packages/categorize/controller/src/index.js index d454d1755d..af7ec86072 100644 --- a/packages/categorize/controller/src/index.js +++ b/packages/categorize/controller/src/index.js @@ -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'); @@ -35,40 +36,8 @@ export const getCorrectness = (question, session, env) => { export const createConfigModel = (model = {}) => new Promise(resolve => { - const sensibleDefaults = { - 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: 'NOT equivalent', - } - ], - config: { - choices: { - columns: 2, - position: 'below', - }, - categories: { - columns: 2 - } - } - }; - resolve({ - ...sensibleDefaults, + ...defaults, ...model, }) }); From b9eea393596c3b4946922632dbafb6a6474fdc25 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 16:11:27 +0200 Subject: [PATCH 31/42] chore(extended-text-entry): place default values in a separate file for both config and controller --- .../configure/src/defaults.js | 5 +++++ .../configure/src/index.js | 20 ++++++------------- .../controller/src/defaults.js | 4 ++++ .../controller/src/index.js | 18 +++++------------ 4 files changed, 20 insertions(+), 27 deletions(-) create mode 100644 packages/extended-text-entry/configure/src/defaults.js create mode 100644 packages/extended-text-entry/controller/src/defaults.js diff --git a/packages/extended-text-entry/configure/src/defaults.js b/packages/extended-text-entry/configure/src/defaults.js new file mode 100644 index 0000000000..195d4d0caf --- /dev/null +++ b/packages/extended-text-entry/configure/src/defaults.js @@ -0,0 +1,5 @@ +export default { + feedback: {type: 'default', default: 'this is default feedback'}, + prompt: 'This is the question prompt', + width: '500px', +}; diff --git a/packages/extended-text-entry/configure/src/index.js b/packages/extended-text-entry/configure/src/index.js index 3671e535cf..835ca63418 100644 --- a/packages/extended-text-entry/configure/src/index.js +++ b/packages/extended-text-entry/configure/src/index.js @@ -3,6 +3,8 @@ import React from 'react'; import ReactDOM from 'react-dom'; import Root from './root'; +import defaults from './defaults'; + const csToUi = cs => {}; /** * @@ -11,20 +13,10 @@ const csToUi = cs => {}; */ const uiToCs = ui => {}; export default class ExtendedTextEntry extends HTMLElement { - static prepareModelObject = (model = {}) => { - const { feedback, prompt, width } = model; - - const sensibleDefault = { - feedback: feedback || {type: 'default', default: 'this is default feedback'}, - prompt: prompt || 'This is the question prompt', - width: width || '500px', - }; - - return { - ...sensibleDefault, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); set model(m) { this._model = ExtendedTextEntry.prepareModelObject(m); diff --git a/packages/extended-text-entry/controller/src/defaults.js b/packages/extended-text-entry/controller/src/defaults.js new file mode 100644 index 0000000000..a2241c5785 --- /dev/null +++ b/packages/extended-text-entry/controller/src/defaults.js @@ -0,0 +1,4 @@ +export default { + prompt: '
This is the question prompt
', + width: '500px', +}; diff --git a/packages/extended-text-entry/controller/src/index.js b/packages/extended-text-entry/controller/src/index.js index 2da54af761..946902c002 100644 --- a/packages/extended-text-entry/controller/src/index.js +++ b/packages/extended-text-entry/controller/src/index.js @@ -2,23 +2,15 @@ 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 createConfigModel(model = {}) { log('[createConfigModel]', model); - const sensibleDefaults = { - prompt: '
This is the question prompt
', - width: '500px', - }; - - const fb = - model.feedback - ? getFeedback(model.feedback, 'Your answer has been submitted') - : Promise.resolve(undefined); - return fb.then(feedback => ({ - ...sensibleDefaults, + return { + ...defaults, ...model, - feedback, - })); + }; } export async function model(model, session, env) { From 818f6a2fd24bf5d6f6c8ba2428d6e701d6647399 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 16:34:07 +0200 Subject: [PATCH 32/42] chore(function-entry): place default values in a separate file for both config and controller --- .../function-entry/configure/src/defaults.js | 4 ++++ packages/function-entry/configure/src/index.js | 16 ++++++---------- .../function-entry/controller/src/defaults.js | 4 ++++ packages/function-entry/controller/src/index.js | 16 ++++++++-------- 4 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 packages/function-entry/configure/src/defaults.js create mode 100644 packages/function-entry/controller/src/defaults.js diff --git a/packages/function-entry/configure/src/defaults.js b/packages/function-entry/configure/src/defaults.js new file mode 100644 index 0000000000..6468d9a7c0 --- /dev/null +++ b/packages/function-entry/configure/src/defaults.js @@ -0,0 +1,4 @@ +export default { + equation: '3x+2', + showFormattingHelp: true, +}; diff --git a/packages/function-entry/configure/src/index.js b/packages/function-entry/configure/src/index.js index f8f8dc5b71..9c6b1cb20e 100644 --- a/packages/function-entry/configure/src/index.js +++ b/packages/function-entry/configure/src/index.js @@ -4,19 +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 prepareModelObject = (model = {}) => { - const sensibleDefaults = { - showFormattingHelp: true, - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); diff --git a/packages/function-entry/controller/src/defaults.js b/packages/function-entry/controller/src/defaults.js new file mode 100644 index 0000000000..6468d9a7c0 --- /dev/null +++ b/packages/function-entry/controller/src/defaults.js @@ -0,0 +1,4 @@ +export default { + equation: '3x+2', + showFormattingHelp: true, +}; diff --git a/packages/function-entry/controller/src/index.js b/packages/function-entry/controller/src/index.js index 87766e0150..ef56859183 100644 --- a/packages/function-entry/controller/src/index.js +++ b/packages/function-entry/controller/src/index.js @@ -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() : ''); @@ -15,14 +17,12 @@ const isResponseCorrect = (correctResponse, value) => { }; export function createConfigModel(model = {}) { - const sensibleDefaults = { - showFormattingHelp: true, - }; - - return { - ...sensibleDefaults, - ...model, - }; + return new Promise(resolve => { + resolve({ + ...defaults, + ...model, + }); + }); } export function model(question, session, env) { From 80af1f0a7a9a517397a9c2e577d09a11e181f7af Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 16:41:20 +0200 Subject: [PATCH 33/42] chore(inline-choice): place default values in a separate file for both config and controller --- .../inline-choice/configure/src/defaults.js | 24 ++++++++++++ packages/inline-choice/configure/src/index.js | 37 +++---------------- .../inline-choice/controller/src/defaults.js | 16 ++++++++ .../inline-choice/controller/src/index.js | 21 ++--------- 4 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 packages/inline-choice/configure/src/defaults.js create mode 100644 packages/inline-choice/controller/src/defaults.js diff --git a/packages/inline-choice/configure/src/defaults.js b/packages/inline-choice/configure/src/defaults.js new file mode 100644 index 0000000000..802fcc2971 --- /dev/null +++ b/packages/inline-choice/configure/src/defaults.js @@ -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.' + } + } + ] +}; diff --git a/packages/inline-choice/configure/src/index.js b/packages/inline-choice/configure/src/index.js index 3f74ffb9ad..93edbf7ed0 100755 --- a/packages/inline-choice/configure/src/index.js +++ b/packages/inline-choice/configure/src/index.js @@ -5,38 +5,13 @@ import ReactDOM from 'react-dom'; import Root from './root'; import { choiceUtils as utils } from '@pie-lib/config-ui'; -export default class InlineChoice extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - 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.' - } - } - ] - }; +import defaults from './defaults'; - return { - ...sensibleDefaults, - ...model, - }; - }; +export default class InlineChoice extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); diff --git a/packages/inline-choice/controller/src/defaults.js b/packages/inline-choice/controller/src/defaults.js new file mode 100644 index 0000000000..93e4748fb7 --- /dev/null +++ b/packages/inline-choice/controller/src/defaults.js @@ -0,0 +1,16 @@ +export default { + choices: [ + { + value: 'sweden', + label: 'Sweden' + }, + { + value: 'iceland', + label: 'Iceland', + }, + { + value: 'finland', + label: 'Finland', + } + ] +}; diff --git a/packages/inline-choice/controller/src/index.js b/packages/inline-choice/controller/src/index.js index 3044833c74..2b378130c4 100644 --- a/packages/inline-choice/controller/src/index.js +++ b/packages/inline-choice/controller/src/index.js @@ -1,30 +1,15 @@ 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 createConfigModel(model = {}) { return new Promise(resolve => { - const sensibleDefaults = { - choices: [ - { - value: 'sweden', - label: 'Sweden' - }, - { - value: 'iceland', - label: 'Iceland', - }, - { - value: 'finland', - label: 'Finland', - } - ] - }; - resolve({ - ...sensibleDefaults, + ...defaults, ...model }); }); From 8976eb17da3b28db4b7e69e6dbebf11881c7a2ab Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:01:06 +0200 Subject: [PATCH 34/42] chore(match): place default values in a separate file for both config and controller --- packages/match/configure/src/defaults.js | 17 +++++++++++++++ packages/match/configure/src/index.js | 25 ++++++----------------- packages/match/controller/src/defaults.js | 19 +++++++++++++++++ packages/match/controller/src/index.js | 19 +++-------------- 4 files changed, 45 insertions(+), 35 deletions(-) create mode 100644 packages/match/configure/src/defaults.js create mode 100644 packages/match/controller/src/defaults.js diff --git a/packages/match/configure/src/defaults.js b/packages/match/configure/src/defaults.js new file mode 100644 index 0000000000..8ef41dd2db --- /dev/null +++ b/packages/match/configure/src/defaults.js @@ -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', +}; diff --git a/packages/match/configure/src/index.js b/packages/match/configure/src/index.js index 5d63e7ebe9..9b29220de7 100644 --- a/packages/match/configure/src/index.js +++ b/packages/match/configure/src/index.js @@ -8,28 +8,15 @@ 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 prepareModelObject = (model = {}) => { - const sensibleDefaults = { - rows: [ - { - id: 1, - title: 'Question Text 1', - values: [false, false] - } - ], - layout: 3, - headers: ['Column 1', 'Column 2', 'Column 3'], - responseType: 'radio', - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); diff --git a/packages/match/controller/src/defaults.js b/packages/match/controller/src/defaults.js new file mode 100644 index 0000000000..b502de2bdc --- /dev/null +++ b/packages/match/controller/src/defaults.js @@ -0,0 +1,19 @@ +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'], + responseType: 'radio', + } +}; diff --git a/packages/match/controller/src/index.js b/packages/match/controller/src/index.js index c014103829..19e0340049 100644 --- a/packages/match/controller/src/index.js +++ b/packages/match/controller/src/index.js @@ -1,6 +1,8 @@ import debug from 'debug'; import { getFeedbackForCorrectness } from '@pie-lib/feedback'; +import defaults from './defaults'; + const log = debug('@pie-element:graph-lines:controller'); const getResponseCorrectness = ( @@ -100,23 +102,8 @@ export const outcome = (question, session, env) => { export function createConfigModel(model = {}) { return new Promise(resolve => { - const sensibleDefaults = { - config: { - rows: [ - { - id: 1, - title: 'Question Text 1', - values: [false, false] - } - ], - layout: 3, - headers: ['Column 1', 'Column 2', 'Column 3'], - responseType: 'radio', - } - }; - resolve({ - ...sensibleDefaults, + ...defaults, ...model }); }); From 94101ddc73079cc6265c7c2a7b0cdebb8b5d90e8 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:13:14 +0200 Subject: [PATCH 35/42] chore(math-inline): place default values in a separate file for both config and controller --- .../math-inline/configure/src/defaults.js | 22 ++++++++++++ packages/math-inline/configure/src/index.js | 35 ++++--------------- .../math-inline/controller/src/defaults.js | 22 ++++++++++++ packages/math-inline/controller/src/index.js | 31 +++------------- 4 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 packages/math-inline/configure/src/defaults.js create mode 100644 packages/math-inline/controller/src/defaults.js diff --git a/packages/math-inline/configure/src/defaults.js b/packages/math-inline/configure/src/defaults.js new file mode 100644 index 0000000000..dadbd179a3 --- /dev/null +++ b/packages/math-inline/configure/src/defaults.js @@ -0,0 +1,22 @@ +export default { + mode: 'advanced', + expression: 'y = ', + question: 'What is the equation for a slope?', + equationEditor: 'everything', + defaultResponse: { + id: 0, + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }, + responses: [{ + id: 'answerBlock1', + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }], +}; diff --git a/packages/math-inline/configure/src/index.js b/packages/math-inline/configure/src/index.js index fdd3ccfd82..d908a93743 100644 --- a/packages/math-inline/configure/src/index.js +++ b/packages/math-inline/configure/src/index.js @@ -4,38 +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:math-inline:configure'); export default class MathInlineConfigure extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - mode: 'advanced', - expression: 'y = ', - question: 'What is the equation for a slope?', - equationEditor: 'everything', - defaultResponse: { - id: 0, - validation: 'symbolic', - answer: 'mx + b', - alternates: {}, - allowSpaces: true, - allowDecimals: true - }, - responses: [{ - id: 'answerBlock1', - validation: 'symbolic', - answer: 'mx + b', - alternates: {}, - allowSpaces: true, - allowDecimals: true - }], - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); diff --git a/packages/math-inline/controller/src/defaults.js b/packages/math-inline/controller/src/defaults.js new file mode 100644 index 0000000000..dadbd179a3 --- /dev/null +++ b/packages/math-inline/controller/src/defaults.js @@ -0,0 +1,22 @@ +export default { + mode: 'advanced', + expression: 'y = ', + question: 'What is the equation for a slope?', + equationEditor: 'everything', + defaultResponse: { + id: 0, + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }, + responses: [{ + id: 'answerBlock1', + validation: 'symbolic', + answer: 'mx + b', + alternates: {}, + allowSpaces: true, + allowDecimals: true + }], +}; diff --git a/packages/math-inline/controller/src/index.js b/packages/math-inline/controller/src/index.js index aa5efeb46f..d93e0674d7 100644 --- a/packages/math-inline/controller/src/index.js +++ b/packages/math-inline/controller/src/index.js @@ -2,6 +2,8 @@ import debug from 'debug'; import { getFeedbackForCorrectness } from '@pie-lib/feedback'; import areValuesEqual from '@pie-lib/math-evaluator'; +import defaults from './defaults'; + const log = debug('@pie-element:math-inline:controller'); const getResponseCorrectness = ( @@ -73,34 +75,11 @@ const getCorrectness = (question, env, answers) => { export function createConfigModel(model = {}) { return new Promise(resolve => { - const sensibleDefaults = { + resolve({ config: { - mode: 'advanced', - expression: 'y = ', - question: 'What is the equation for a slope?', - equationEditor: 'everything', - defaultResponse: { - id: 0, - validation: 'symbolic', - answer: 'mx + b', - alternates: {}, - allowSpaces: true, - allowDecimals: true - }, - responses: [{ - id: 'answerBlock1', - validation: 'symbolic', - answer: 'mx + b', - alternates: {}, - allowSpaces: true, - allowDecimals: true - }], + ...defaults, + ...model } - }; - - resolve({ - ...sensibleDefaults, - ...model }); }); } From 4c2caaeb2fb26172b2ec733524e962b7bd050040 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:22:30 +0200 Subject: [PATCH 36/42] chore(multiple-choice): place default values in a separate file for both config and controller --- .../multiple-choice/configure/src/defaults.js | 16 ++++++++++ .../multiple-choice/configure/src/index.js | 29 ++++--------------- .../controller/src/defaults.js | 15 ++++++++++ .../multiple-choice/controller/src/index.js | 21 ++------------ 4 files changed, 40 insertions(+), 41 deletions(-) create mode 100644 packages/multiple-choice/configure/src/defaults.js create mode 100644 packages/multiple-choice/controller/src/defaults.js diff --git a/packages/multiple-choice/configure/src/defaults.js b/packages/multiple-choice/configure/src/defaults.js new file mode 100644 index 0000000000..2b5e872cbb --- /dev/null +++ b/packages/multiple-choice/configure/src/defaults.js @@ -0,0 +1,16 @@ +export default { + prompt: 'Which of these northern European countries are EU members?', + choiceMode: 'checkbox', + keyMode: 'numbers', + choices: [ + { + correct: true, + value: 'sweden', + label: 'Sweden', + }, + { + value: 'iceland', + label: 'Iceland', + }, + ], +}; diff --git a/packages/multiple-choice/configure/src/index.js b/packages/multiple-choice/configure/src/index.js index 81c4f7b016..da957147b2 100644 --- a/packages/multiple-choice/configure/src/index.js +++ b/packages/multiple-choice/configure/src/index.js @@ -11,6 +11,8 @@ import debug from 'debug'; import { choiceUtils as utils } from '@pie-lib/config-ui'; import defaults from 'lodash/defaults'; +import sensibleDefaults from './defaults'; + const log = debug('multiple-choice:configure'); const defaultValues = { @@ -60,29 +62,10 @@ const prepareCustomizationObject = (configure, model) => { }; export default class MultipleChoice extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - prompt: 'Which of these northern European countries are EU members?', - choiceMode: 'checkbox', - keyMode: 'numbers', - choices: [ - { - correct: true, - value: 'sweden', - label: 'Sweden', - }, - { - value: 'iceland', - label: 'Iceland', - }, - ], - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...sensibleDefaults, + ...model, + }); constructor() { super(); diff --git a/packages/multiple-choice/controller/src/defaults.js b/packages/multiple-choice/controller/src/defaults.js new file mode 100644 index 0000000000..c506592171 --- /dev/null +++ b/packages/multiple-choice/controller/src/defaults.js @@ -0,0 +1,15 @@ +export default { + prompt: 'Which of these northern European countries are EU members?', + choiceMode: 'checkbox', + keyMode: 'numbers', + choices: [ + { + value: 'sweden', + label: 'Sweden', + }, + { + value: 'iceland', + label: 'Iceland', + }, + ], +}; diff --git a/packages/multiple-choice/controller/src/index.js b/packages/multiple-choice/controller/src/index.js index df88b9b175..94de95e21d 100644 --- a/packages/multiple-choice/controller/src/index.js +++ b/packages/multiple-choice/controller/src/index.js @@ -2,6 +2,8 @@ import debug from 'debug'; import shuffle from 'lodash/shuffle'; import { isResponseCorrect } from './utils'; +import defaults from './defaults'; + const log = debug('pie-elements:multiple-choice:controller'); const prepareChoice = (mode, defaultFeedback) => choice => { @@ -27,25 +29,8 @@ const prepareChoice = (mode, defaultFeedback) => choice => { export function createConfigModel(model = {}) { return new Promise(resolve => { - const sensibleDefaults = { - prompt: 'Which of these northern European countries are EU members?', - choiceMode: 'checkbox', - keyMode: 'numbers', - choices: [ - { - correct: true, - value: 'sweden', - label: 'Sweden', - }, - { - value: 'iceland', - label: 'Iceland', - }, - ], - }; - resolve({ - ...sensibleDefaults, + ...defaults, ...model }); }); From 354d21af720ab19d45c795f4fb602acdf3e4b6c0 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:30:18 +0200 Subject: [PATCH 37/42] chore(number-line): place default values in a separate file for both config and controller --- .../number-line/configure/src/defaults.js | 43 ++++++++++++++ packages/number-line/configure/src/index.js | 56 ++----------------- .../number-line/controller/src/defaults.js | 28 ++++++++++ packages/number-line/controller/src/index.js | 37 ++---------- 4 files changed, 82 insertions(+), 82 deletions(-) create mode 100644 packages/number-line/configure/src/defaults.js create mode 100644 packages/number-line/controller/src/defaults.js diff --git a/packages/number-line/configure/src/defaults.js b/packages/number-line/configure/src/defaults.js new file mode 100644 index 0000000000..3b3ab656c6 --- /dev/null +++ b/packages/number-line/configure/src/defaults.js @@ -0,0 +1,43 @@ +export default { + correctResponse: [ + { + type: 'point', + pointType: 'full', + domainPosition: 1 + }, + { + type: 'line', + leftPoint: 'full', + rightPoint: 'empty', + domainPosition: 1, + size: 2 + } + ], + config: { + domain: [-5, 5], + initialElements: [ + { + type: 'point', + pointType: 'empty', + domainPosition: -1 + } + ], + maxNumberOfPoints: 20, + tickFrequency: 6, + showMinorTicks: true, + snapPerTick: 1, + initialType: 'PF', + availableTypes: { + PF: true, + PE: true, + LFF: true, + LEF: true, + LFE: true, + LEE: true, + RFN: true, + RFP: true, + REN: true, + REP: true + } + } +}; diff --git a/packages/number-line/configure/src/index.js b/packages/number-line/configure/src/index.js index b227615a86..72cec560cd 100644 --- a/packages/number-line/configure/src/index.js +++ b/packages/number-line/configure/src/index.js @@ -2,57 +2,13 @@ import Main from './main'; import React from 'react'; import ReactDOM from 'react-dom'; -export default class NumberLineConfigReactElement extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - correctResponse: [ - { - type: 'point', - pointType: 'full', - domainPosition: 1 - }, - { - type: 'line', - leftPoint: 'full', - rightPoint: 'empty', - domainPosition: 1, - size: 2 - } - ], - config: { - domain: [-5, 5], - initialElements: [ - { - type: 'point', - pointType: 'empty', - domainPosition: -1 - } - ], - maxNumberOfPoints: 20, - tickFrequency: 6, - showMinorTicks: true, - snapPerTick: 1, - initialType: 'PF', - availableTypes: { - PF: true, - PE: true, - LFF: true, - LEF: true, - LFE: true, - LEE: true, - RFN: true, - RFP: true, - REN: true, - REP: true - } - } - }; +import defaults from './defaults'; - return { - ...sensibleDefaults, - ...model, - }; - }; +export default class NumberLineConfigReactElement extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); diff --git a/packages/number-line/controller/src/defaults.js b/packages/number-line/controller/src/defaults.js new file mode 100644 index 0000000000..883fbe41f4 --- /dev/null +++ b/packages/number-line/controller/src/defaults.js @@ -0,0 +1,28 @@ +export default { + domain: [-5, 5], + initialElements: [ + { + type: 'point', + pointType: 'empty', + domainPosition: -1 + } + ], + maxNumberOfPoints: 20, + tickFrequency: 6, + showMinorTicks: true, + snapPerTick: 1, + tickLabelOverrides: [], + initialType: 'PF', + availableTypes: { + PF: true, + PE: true, + LFF: true, + LEF: true, + LFE: true, + LEE: true, + RFN: true, + RFP: true, + REN: true, + REP: true + } +}; diff --git a/packages/number-line/controller/src/index.js b/packages/number-line/controller/src/index.js index e425b52cab..3e83cd22cb 100644 --- a/packages/number-line/controller/src/index.js +++ b/packages/number-line/controller/src/index.js @@ -6,6 +6,8 @@ import merge from 'lodash/merge'; import omitBy from 'lodash/omitBy'; import { getFeedbackForCorrectness } from '@pie-lib/feedback'; +import defaults from './defaults'; + const score = number => { return { score: { @@ -143,43 +145,14 @@ export function normalize(question) { export function createConfigModel(model = {}) { return new Promise(resolve => { - const sensibleDefaults = { + const out = { config: { - domain: [-5, 5], - initialElements: [ - { - type: 'point', - pointType: 'empty', - domainPosition: -1 - } - ], - maxNumberOfPoints: 20, - tickFrequency: 6, - showMinorTicks: true, - snapPerTick: 1, - tickLabelOverrides: [], - initialType: 'PF', - availableTypes: { - PF: true, - PE: true, - LFF: true, - LEF: true, - LFE: true, - LEE: true, - RFN: true, - RFP: true, - REN: true, - REP: true - } + ...defaults, + ...model }, colorContrast: 'black_on_white', }; - const out = { - ...sensibleDefaults, - ...model - }; - resolve(omitBy(out, v => !v)); }); } From d572c85edd4f29f6c1821d2a2188741137a9d981 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:33:58 +0200 Subject: [PATCH 38/42] chore(number-line): place default values in a separate file for controller --- .../controller/src/defaults.js | 33 ++++++++++++++++ .../controller/src/index.js | 39 ++----------------- 2 files changed, 37 insertions(+), 35 deletions(-) create mode 100644 packages/placement-ordering/controller/src/defaults.js diff --git a/packages/placement-ordering/controller/src/defaults.js b/packages/placement-ordering/controller/src/defaults.js new file mode 100644 index 0000000000..80fbf67912 --- /dev/null +++ b/packages/placement-ordering/controller/src/defaults.js @@ -0,0 +1,33 @@ +export default { + choices: [ + { + id: 'c2', + label: 'Lemon', + shuffle: false, + moveOnDrag: true + }, + { + id: 'c3', + label: 'Melon', + moveOnDrag: true + }, + { + id: 'c1', + label: 'Blueberry', + moveOnDrag: false + }, + { + id: 'c4', + label: 'Pear', + moveOnDrag: false + } + ], + completeLength: 4, + config: { + orientation: 'vertical', + targetLabel: 'Answer Area Label', + choiceLabel: 'choices: ', + showOrdering: true + }, + prompt: 'Arrange the fruits alphabetically', +}; diff --git a/packages/placement-ordering/controller/src/index.js b/packages/placement-ordering/controller/src/index.js index 7e709593fa..d0980eae24 100644 --- a/packages/placement-ordering/controller/src/index.js +++ b/packages/placement-ordering/controller/src/index.js @@ -3,6 +3,9 @@ import { flattenCorrect, score } from './scoring'; import _ from 'lodash'; import debug from 'debug'; import { getFeedbackForCorrectness } from '@pie-lib/feedback'; + +import defaults from './defaults'; + const log = debug('@pie-element:placement-ordering-controller'); export function outcome(question, session, env) { @@ -72,42 +75,8 @@ function shuffle(session, choices) { export function createConfigModel(model = {}) { return new Promise(resolve => { - const sensibleDefaults = { - choices: [ - { - id: 'c2', - label: 'Lemon', - shuffle: false, - moveOnDrag: true - }, - { - id: 'c3', - label: 'Melon', - moveOnDrag: true - }, - { - id: 'c1', - label: 'Blueberry', - moveOnDrag: false - }, - { - id: 'c4', - label: 'Pear', - moveOnDrag: false - } - ], - completeLength: 4, - config: { - orientation: 'vertical', - targetLabel: 'Answer Area Label', - choiceLabel: 'choices: ', - showOrdering: true - }, - prompt: 'Arrange the fruits alphabetically', - }; - resolve({ - ...sensibleDefaults, + ...defaults, ...model }); }); From d6937915355f24a95990267b234979f2e06c1f2d Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:37:25 +0200 Subject: [PATCH 39/42] chore(number-line): place default values in a separate file for config --- packages/ruler/configure/src/defaults.js | 5 +++++ packages/ruler/configure/src/index.js | 18 ++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 packages/ruler/configure/src/defaults.js diff --git a/packages/ruler/configure/src/defaults.js b/packages/ruler/configure/src/defaults.js new file mode 100644 index 0000000000..46d5ec6a76 --- /dev/null +++ b/packages/ruler/configure/src/defaults.js @@ -0,0 +1,5 @@ +export default { + measure: 'metric', + label: 'm', + units: 10, +}; diff --git a/packages/ruler/configure/src/index.js b/packages/ruler/configure/src/index.js index e86317e466..f08da69cfd 100644 --- a/packages/ruler/configure/src/index.js +++ b/packages/ruler/configure/src/index.js @@ -3,6 +3,8 @@ import ReactDOM from 'react-dom'; import Main from './main'; import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events'; +import defaults from './defaults'; + const defaultModel = () => ({ model: { config: { @@ -16,18 +18,10 @@ const defaultModel = () => ({ }); export default class RulerConfigure extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - measure: 'metric', - label: 'm', - units: 10, - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); connectedCallback() { setTimeout(() => { From b4346d2b737fa0dbd777eff3fb899b2910e11b56 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:44:11 +0200 Subject: [PATCH 40/42] chore(select-text): place default values in a separate file for controller --- .../select-text/controller/src/defaults.js | 26 ++++++++++++++++ packages/select-text/controller/src/index.js | 31 ++----------------- 2 files changed, 29 insertions(+), 28 deletions(-) create mode 100644 packages/select-text/controller/src/defaults.js diff --git a/packages/select-text/controller/src/defaults.js b/packages/select-text/controller/src/defaults.js new file mode 100644 index 0000000000..8cb4bbe393 --- /dev/null +++ b/packages/select-text/controller/src/defaults.js @@ -0,0 +1,26 @@ +const tokens = () => [ + { + text: 'Rachel cut out 8 stars in 6 minutes.', + start: 0, + end: 36, + }, + { + text: 'Lovelle cut out 6 stars in 4 minutes.', + start: 37, + end: 74, + }, + { + text: 'Lovelle and Rachel cut the same number of stars in 6 minutes.', + start: 117, + end: 177 + } +]; + +export default { + highlightChoices: true, + maxSelections: 2, + prompt: 'What sentences contain the character 6 in them?', + text: + 'Rachel cut out 8 stars in 6 minutes. Lovelle cut out 6 stars in 4 minutes. Rachel cut out 4 more stars than Lovelle. Lovelle and Rachel cut the same number of stars in 6 minutes.', + tokens: tokens(), +}; diff --git a/packages/select-text/controller/src/index.js b/packages/select-text/controller/src/index.js index 3166b97972..14feea2e0c 100644 --- a/packages/select-text/controller/src/index.js +++ b/packages/select-text/controller/src/index.js @@ -1,6 +1,8 @@ import debug from 'debug'; import { getFeedbackForCorrectness } from '@pie-lib/feedback'; +import defaults from './defaults'; + const log = debug('@pie-element:select-text:controller'); const buildTokens = (tokens, evaluateMode) => { @@ -83,35 +85,8 @@ export const outcome = (question, session, env) => { export function createConfigModel(model = {}) { return new Promise(resolve => { - const tokens = () => [ - { - text: 'Rachel cut out 8 stars in 6 minutes.', - start: 0, - end: 36, - }, - { - text: 'Lovelle cut out 6 stars in 4 minutes.', - start: 37, - end: 74, - }, - { - text: 'Lovelle and Rachel cut the same number of stars in 6 minutes.', - start: 117, - end: 177 - } - ]; - - const sensibleDefaults = { - highlightChoices: true, - maxSelections: 2, - prompt: 'What sentences contain the character 6 in them?', - text: - 'Rachel cut out 8 stars in 6 minutes. Lovelle cut out 6 stars in 4 minutes. Rachel cut out 4 more stars than Lovelle. Lovelle and Rachel cut the same number of stars in 6 minutes.', - tokens: tokens(), - }; - resolve({ - ...sensibleDefaults, + ...defaults, ...model }); }); From 3190cc63b817deaf1d829889d96dce8e4cf8d9d4 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 17:48:36 +0200 Subject: [PATCH 41/42] chore(text-entry): place default values in a separate file for controller --- packages/text-entry/configure/src/defaults.js | 18 +++++++++++ packages/text-entry/configure/src/index.js | 31 ++++--------------- 2 files changed, 24 insertions(+), 25 deletions(-) create mode 100644 packages/text-entry/configure/src/defaults.js diff --git a/packages/text-entry/configure/src/defaults.js b/packages/text-entry/configure/src/defaults.js new file mode 100644 index 0000000000..3124d720c1 --- /dev/null +++ b/packages/text-entry/configure/src/defaults.js @@ -0,0 +1,18 @@ +export default { + correctResponses: { + values: ['mutt', 'hound'], + ignoreWhitespace: true, + ignoreCase: false + }, + partialResponses: { + values: ['mutty'], + ignoreWhitespace: true, + ignoreCase: true, + awardPercentage: '50' + }, + answerBlankSize: '10', + answerAlignment: 'left', + prompt: 'Question Prompt goes here', + allowDecimal: true, + allowThousandsSeparator: true +}; diff --git a/packages/text-entry/configure/src/index.js b/packages/text-entry/configure/src/index.js index c695b4a9ee..be4a0c128e 100644 --- a/packages/text-entry/configure/src/index.js +++ b/packages/text-entry/configure/src/index.js @@ -4,34 +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:text-entry:configure'); export default class TextEntryConfigure extends HTMLElement { - static prepareModelObject = (model = {}) => { - const sensibleDefaults = { - correctResponses: { - values: ['mutt', 'hound'], - ignoreWhitespace: true, - ignoreCase: false - }, - partialResponses: { - values: ['mutty'], - ignoreWhitespace: true, - ignoreCase: true, - awardPercentage: '50' - }, - answerBlankSize: '10', - answerAlignment: 'left', - prompt: 'Question Prompt goes here', - allowDecimal: true, - allowThousandsSeparator: true - }; - - return { - ...sensibleDefaults, - ...model, - }; - }; + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); From 00177cda5d7f70445f73d31069542be58a58e068 Mon Sep 17 00:00:00 2001 From: Sergiu Lucaci Date: Thu, 7 Mar 2019 18:17:47 +0200 Subject: [PATCH 42/42] chore(categorize): use model as a parameter for the config middleware --- packages/categorize/configure/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/categorize/configure/src/index.js b/packages/categorize/configure/src/index.js index 2c791042d5..da8e5ba16c 100644 --- a/packages/categorize/configure/src/index.js +++ b/packages/categorize/configure/src/index.js @@ -16,7 +16,7 @@ export default class CategorizeConfigure extends HTMLElement { }); set model(m) { - this._model = CategorizeConfigure.prepareModelObject(); + this._model = CategorizeConfigure.prepareModelObject(m); this.render(); }