Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(general): allow empty model initialization #126

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fd2834c
chore(calculator): initialize empty README
sergiulucaci Mar 5, 2019
d5f5795
chore(calculator): handle the use case where the model is incomplete/…
sergiulucaci Mar 5, 2019
5f8749d
chore(extended-text-entry): implement controller method for model ini…
sergiulucaci Mar 6, 2019
989d60c
chore(extended-text-entry): implement config middleware to prepare th…
sergiulucaci Mar 6, 2019
dec4391
chore(calculator): make config calculator defaults sensible
sergiulucaci Mar 6, 2019
34376ce
chore(function-entry): implement config middleware to prepare the mo…
sergiulucaci Mar 6, 2019
93c734e
chore(function-entry): implement controller method for model initiali…
sergiulucaci Mar 6, 2019
df1537a
chore(inline-choice): implement config middleware to prepare the mode…
sergiulucaci Mar 6, 2019
1679eed
chore(inline-choice): implement controller method for model initializ…
sergiulucaci Mar 6, 2019
c03e445
chore(graph-lines): implement config middleware to prepare the model …
sergiulucaci Mar 6, 2019
3007538
chore(graph-lines): accept model as a parameter for the config middle…
sergiulucaci Mar 6, 2019
fd9d94c
chore(graph-lines): undo config middleware changes
sergiulucaci Mar 6, 2019
c6ae996
chore(categorize): implement config middleware to prepare the model o…
sergiulucaci Mar 6, 2019
4c742fd
chore(categorize): implement controller method for model initialization
sergiulucaci Mar 6, 2019
c1c92e8
chore(match): implement config middleware to prepare the model object…
sergiulucaci Mar 6, 2019
bc48a40
chore(match): implement controller method for model initialization
sergiulucaci Mar 6, 2019
3c3a3ab
chore(math-inline): implement config middleware to prepare the model …
sergiulucaci Mar 6, 2019
05a40ee
chore(math-inline): implement controller method for model initialization
sergiulucaci Mar 6, 2019
2682307
chore(multiple-choice): implement config middleware to prepare the mo…
sergiulucaci Mar 6, 2019
4ed98d7
chore(multiple-choice): implement controller method for model initial…
sergiulucaci Mar 6, 2019
1db1490
chore(number-line): implement config middleware to prepare the model …
sergiulucaci Mar 7, 2019
12fac70
chore(number-line): implement controller method for model initialization
sergiulucaci Mar 7, 2019
b106fed
chore(placement-ordering): implement config middleware to prepare the…
sergiulucaci Mar 7, 2019
6b6e76e
chore(placement-ordering): implement controller method for model init…
sergiulucaci Mar 7, 2019
b473602
chore(ruler): implement config middleware to prepare the model object…
sergiulucaci Mar 7, 2019
8d77c4c
chore(select-text): implement config middleware to prepare the model …
sergiulucaci Mar 7, 2019
444533d
chore(select-text): implement controller method for model initialization
sergiulucaci Mar 7, 2019
a4c4dfd
chore(text-configure): implement config middleware to prepare the mod…
sergiulucaci Mar 7, 2019
52ad744
chore(calculator): place default values in a separate file
sergiulucaci Mar 7, 2019
c87a0a7
chore(categorize): place default values in a separate file
sergiulucaci Mar 7, 2019
b9eea39
chore(extended-text-entry): place default values in a separate file f…
sergiulucaci Mar 7, 2019
818f6a2
chore(function-entry): place default values in a separate file for bo…
sergiulucaci Mar 7, 2019
80af1f0
chore(inline-choice): place default values in a separate file for bot…
sergiulucaci Mar 7, 2019
8976eb1
chore(match): place default values in a separate file for both config…
sergiulucaci Mar 7, 2019
94101dd
chore(math-inline): place default values in a separate file for both …
sergiulucaci Mar 7, 2019
4c2caae
chore(multiple-choice): place default values in a separate file for b…
sergiulucaci Mar 7, 2019
354d21a
chore(number-line): place default values in a separate file for both …
sergiulucaci Mar 7, 2019
d572c85
chore(number-line): place default values in a separate file for contr…
sergiulucaci Mar 7, 2019
d693791
chore(number-line): place default values in a separate file for config
sergiulucaci Mar 7, 2019
b4346d2
chore(select-text): place default values in a separate file for contr…
sergiulucaci Mar 7, 2019
3190cc6
chore(text-entry): place default values in a separate file for contro…
sergiulucaci Mar 7, 2019
bfb211b
Merge branch 'develop' into chore/elements-model-initialization
sergiulucaci Mar 7, 2019
00177cd
chore(categorize): use model as a parameter for the config middleware
sergiulucaci Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @pie-element/calculator
3 changes: 3 additions & 0 deletions packages/calculator/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
mode: 'basic',
};
11 changes: 9 additions & 2 deletions packages/calculator/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
53 changes: 53 additions & 0 deletions packages/categorize/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export default {
choices: [
{
id: '0',
content: '<span mathjax="" data-latex="">420\\text{ cm}=4.2\\text{ meters}</span>'
},
{
id: '1',
content: '<span mathjax="" data-latex="" data-raw="3.4\\text{ kg}=350\\text{ g}">3.4\\text{ kg}=340\\text{ g}</span>'
},
],
categories: [
{
id: '0',
label: 'Equivalent',
choices: [
{
id: '0',
content: '<span mathjax="" data-latex="">420\\text{ cm}=4.2\\text{ meters}</span>'
},
]
},
{
id: '1',
label: '<b>NOT </b>equivalent',
choices: [
{
id: '1',
content: '<span mathjax="" data-latex="">3.4\\text{ kg}=340\\text{ g}</span>'
},
]
}
],
correctResponse: [
{
category: '0',
choices: ['0']
},
{
category: '1',
choices: ['1']
}
],
config: {
choices: {
columns: 2,
position: 'below',
},
categories: {
columns: 2
}
}
};
9 changes: 8 additions & 1 deletion packages/categorize/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

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

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

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

import defaults from './defaults';

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

set model(m) {
this._model = m;
this._model = ExtendedTextEntry.prepareModelObject(m);
this.render();
}

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

import defaults from './defaults';

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

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

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

Expand Down
4 changes: 4 additions & 0 deletions packages/function-entry/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
equation: '3x+2',
showFormattingHelp: true,
};
8 changes: 7 additions & 1 deletion packages/function-entry/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

import defaults from './defaults';

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

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

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

export function model(question, session, env) {
return new Promise(resolve => {
const { showFormattingHelp, equation, feedback } = question;
Expand Down
24 changes: 24 additions & 0 deletions packages/inline-choice/configure/src/defaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
choices: [
{
correct: true,
value: 'sweden',
label: 'Sweden'
},
{
value: 'iceland',
label: 'Iceland',
feedback: {
type: 'default'
}
},
{
value: 'finland',
label: 'Finland',
feedback: {
type: 'custom',
value: 'Nokia was founded in Finland.'
}
}
]
};
13 changes: 11 additions & 2 deletions packages/inline-choice/configure/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

import defaults from './defaults';

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

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

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

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