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 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 9d3671ce2c..abfaaca678 100644 --- a/packages/calculator/configure/src/index.js +++ b/packages/calculator/configure/src/index.js @@ -3,14 +3,21 @@ 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 prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); + constructor() { super(); this.onModelChanged = this.onModelChanged.bind(this); } set model(s) { - this._model = s; + this._model = Calculator.prepareModelObject(s); this._render(); } 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 07e1b1a840..da8e5ba16c 100644 --- a/packages/categorize/configure/src/index.js +++ b/packages/categorize/configure/src/index.js @@ -7,9 +7,16 @@ import { InsertImageEvent } from '@pie-framework/pie-configure-events'; +import defaults from './defaults'; + export default class CategorizeConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); + set model(m) { - this._model = m; + this._model = CategorizeConfigure.prepareModelObject(m); 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 b96730c38a..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'); @@ -33,6 +34,14 @@ export const getCorrectness = (question, session, env) => { }); }; +export const createConfigModel = (model = {}) => + new Promise(resolve => { + resolve({ + ...defaults, + ...model, + }) + }); + export const model = (question, session, env) => new Promise(resolve => { const correctPromise = getCorrectness(question, session, env); 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 060bbca64f..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 => {}; /** * @@ -10,9 +12,14 @@ 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 = {}) => ({ + ...defaults, + ...model, + }); + set model(m) { - this._model = m; + this._model = ExtendedTextEntry.prepareModelObject(m); this.render(); } 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 059e5b524d..946902c002 100644 --- a/packages/extended-text-entry/controller/src/index.js +++ b/packages/extended-text-entry/controller/src/index.js @@ -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 createConfigModel(model = {}) { + log('[createConfigModel]', model); + + return { + ...defaults, + ...model, + }; +} + export async function model(model, session, env) { log('[model]', model); 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 ffb0bb2e45..9c6b1cb20e 100644 --- a/packages/function-entry/configure/src/index.js +++ b/packages/function-entry/configure/src/index.js @@ -4,16 +4,22 @@ 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 = {}) => ({ + ...defaults, + ...model, + }); constructor() { super(); } set model(m) { - this._model = m; + this._model = FunctionEntryConfigure.prepareModelObject(m); this._render(); } 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 b79b5e6ecb..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() : ''); @@ -14,6 +16,15 @@ const isResponseCorrect = (correctResponse, value) => { return processedValue.equals(cr); }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + ...defaults, + ...model, + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const { showFormattingHelp, equation, feedback } = question; 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 3da689359b..93edbf7ed0 100755 --- a/packages/inline-choice/configure/src/index.js +++ b/packages/inline-choice/configure/src/index.js @@ -5,14 +5,23 @@ 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 prepareModelObject = (model = {}) => ({ + ...defaults, + ...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(); } 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 0bf8a3fb12..2b378130c4 100644 --- a/packages/inline-choice/controller/src/index.js +++ b/packages/inline-choice/controller/src/index.js @@ -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 createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + ...defaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const getResult = () => { 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 b0477bd4fe..9b29220de7 100644 --- a/packages/match/configure/src/index.js +++ b/packages/match/configure/src/index.js @@ -8,15 +8,22 @@ 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 = {}) => ({ + ...defaults, + ...model, + }); + constructor() { super(); } set model(m) { - this._model = m; + this._model = MatchConfigure.prepareModelObject(m); this._render(); } 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 fc46575fd9..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 = ( @@ -98,6 +100,15 @@ export const outcome = (question, session, env) => { }); }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + ...defaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const correctness = getCorrectness(question, env, session.answers); 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 0fb2427b26..d908a93743 100644 --- a/packages/math-inline/configure/src/index.js +++ b/packages/math-inline/configure/src/index.js @@ -4,15 +4,22 @@ 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 = {}) => ({ + ...defaults, + ...model, + }); + constructor() { super(); } set model(m) { - this._model = m; + this._model = MathInlineConfigure.prepareModelObject(m); this._render(); } 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 de6c5e5dc8..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 = ( @@ -71,6 +73,17 @@ const getCorrectness = (question, env, answers) => { } }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + config: { + ...defaults, + ...model + } + }); + }); +} + export function model(question, session, env) { return new Promise(resolve => { const correctness = getCorrectness(question, env, session.answers); 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 aedbcf4953..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 = { @@ -59,7 +61,12 @@ const prepareCustomizationObject = (configure, model) => { }; }; -export default class extends HTMLElement { +export default class MultipleChoice extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...sensibleDefaults, + ...model, + }); + constructor() { super(); this.onModelChanged = this.onModelChanged.bind(this); @@ -67,7 +74,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(); } 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 efc78dd240..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 => { @@ -25,6 +27,15 @@ const prepareChoice = (mode, defaultFeedback) => choice => { return out; }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + ...defaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise((resolve, reject) => { const defaultFeedback = Object.assign( 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 a13b25de6c..72cec560cd 100644 --- a/packages/number-line/configure/src/index.js +++ b/packages/number-line/configure/src/index.js @@ -2,13 +2,20 @@ import Main from './main'; import React from 'react'; import ReactDOM from 'react-dom'; +import defaults from './defaults'; + export default class NumberLineConfigReactElement extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); + constructor() { super(); } set model(s) { - this._model = s; + this._model = NumberLineConfigReactElement.prepareModelObject(s); this._rerender(); } 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 d4d6aecd9b..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: { @@ -141,6 +143,20 @@ export function normalize(question) { }); } +export function createConfigModel(model = {}) { + return new Promise(resolve => { + const out = { + config: { + ...defaults, + ...model + }, + colorContrast: 'black_on_white', + }; + + resolve(omitBy(out, v => !v)); + }); +} + export function model(question, session, env) { if (!question) { return Promise.reject(new Error('question is null')); 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(); } 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 439cc291b6..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) { @@ -70,6 +73,15 @@ function shuffle(session, choices) { } } +export function createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + ...defaults, + ...model + }); + }); +} + export function model(question, session, env) { return new Promise((resolve, reject) => { const base = {}; 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 1382713f72..7a8f651b16 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,6 +18,11 @@ const defaultModel = () => ({ }); export default class RulerConfigure extends HTMLElement { + static prepareModelObject = (model = {}) => ({ + ...defaults, + ...model, + }); + connectedCallback() { setTimeout(() => { if (!this._model) { @@ -27,7 +34,7 @@ export default class RulerConfigure extends HTMLElement { } set model(m) { - this._model = m; + this._model = RulerConfigure.prepareModelObject(m); this.render(); } 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(); } 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 98277cfc7b..59080fb4d7 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) => { @@ -81,6 +83,15 @@ export const outcome = (question, session, env) => { }); }; +export function createConfigModel(model = {}) { + return new Promise(resolve => { + resolve({ + ...defaults, + ...model + }); + }); +} + export const model = (question, session, env) => { return new Promise(resolve => { log('[model]', 'question: ', question); 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 8e2a598d57..be4a0c128e 100644 --- a/packages/text-entry/configure/src/index.js +++ b/packages/text-entry/configure/src/index.js @@ -4,15 +4,22 @@ 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 = {}) => ({ + ...defaults, + ...model, + }); + constructor() { super(); } set model(m) { - this._model = m; + this._model = TextEntryConfigure.prepareModelObject(m); this._render(); }