Skip to content

Commit

Permalink
Provide feedback from the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
benburton committed Jan 30, 2017
1 parent 0272f64 commit 448310d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
8 changes: 7 additions & 1 deletion controller/src/index.js
Expand Up @@ -14,7 +14,13 @@ export function outcome(question, session) {
export function model(question, session, env) {

return new Promise((resolve) => {
resolve(question);
var response = {};
if (env.mode === 'evaluate') {
let correct = session && session.answer && session.answer === question.answer;
response.result = correct;
response.feedback = correct ? question.feedback.correct : question.feedback.incorrect;
}
resolve(response);
});

}
8 changes: 6 additions & 2 deletions docs/demo/config.json
Expand Up @@ -6,7 +6,11 @@
{
"id": "1",
"element": "pie-toggle",
"answer": true
"answer": true,
"feedback": {
"correct": "Correct!",
"incorrect": "Incorrect!"
}
}
]
}
}
15 changes: 14 additions & 1 deletion src/index.js
Expand Up @@ -27,13 +27,26 @@ export default class Toggle extends HTMLElement {
}

_rerender() {
let feedback = (function(model) {
if (model && model.feedback) {
return [
"<div class='feedback'>",
model.feedback,
"</div>"
].join('\n');
} else {
return "";
}
}(this._model));

let checked = this._session ? this._session.answer : false;

this.innerHTML = [
'<label class="switch">',
'<input type="checkbox" ', (checked ? 'checked=""' : ''), '>',
'<div class="slider round"></div>',
'</label>'
'</label>',
feedback
].join('\n');

this.getElementsByTagName('input')[0].addEventListener('change', (e) => {
Expand Down

0 comments on commit 448310d

Please sign in to comment.