From 0424c2b23c9c1bd0e622dd89dc1dee7ded865c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santanch=C3=A8?= Date: Mon, 7 Sep 2020 12:56:30 -0300 Subject: [PATCH] feat (theme): note themes configuration via json --- .../public/dccs/components/dcc-button.js | 13 +++---------- src/adonisjs/public/player/js/player.js | 10 ++++++++-- src/adonisjs/public/player/js/state.js | 18 +++++++++++++++++- .../templates/simple/case/quiz_sequence.md | 2 +- .../public/templates/simple/case/quiz_short.md | 10 +++++----- .../public/themes/simple/note_references.html | 12 ++++++++++++ src/adonisjs/public/themes/simple/theme.json | 4 +++- src/adonisjs/public/translator/translator.js | 4 ++++ 8 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 src/adonisjs/public/themes/simple/note_references.html diff --git a/src/adonisjs/public/dccs/components/dcc-button.js b/src/adonisjs/public/dccs/components/dcc-button.js index adb55974b..27913aeee 100644 --- a/src/adonisjs/public/dccs/components/dcc-button.js +++ b/src/adonisjs/public/dccs/components/dcc-button.js @@ -133,25 +133,18 @@ class DCCButton extends DCCBlock { _computeTrigger () { if (this._active) { + let message = { sourceType: DCCButton.elementTag } if (this.hasAttribute('variable')) { const v = (this.variable.includes(':')) ? this.variable.substring(0, this.variable.indexOf(':')) : this.variable - console.log('=== trigger variable') - console.log('var/' + v + '/changed') - console.log((this.variable.endsWith(':label')) ? this.label : this.message) - MessageBus.ext.publish('var/' + v + '/changed', - { - sourceType: DCCButton.elementTag, - value: (this.variable.endsWith(':label')) ? this.label : this.message - }) + message.value = (this.variable.endsWith(':label')) ? this.label : this.message + MessageBus.ext.publish('var/' + v + '/changed', message) } if (this.hasAttribute('label') || this.hasAttribute('topic')) { if (this.hasAttribute('topic') && this.topic.endsWith('/navigate')) { this._active = false } const topic = (this.hasAttribute('topic')) ? this.topic : 'button/' + this.label + '/clicked' - const message = {} if (this.hasAttribute('message')) { message.value = this.message } - MessageBus.ext.publish(topic, message) } } diff --git a/src/adonisjs/public/player/js/player.js b/src/adonisjs/public/player/js/player.js index f02b1f5b6..e6206ac5f 100644 --- a/src/adonisjs/public/player/js/player.js +++ b/src/adonisjs/public/player/js/player.js @@ -337,8 +337,14 @@ class PlayerManager { this._knots[knotName].categories.includes('script')) { MetaPlayer.player.play(this._knots[knotName], this._state) } else { const knot = await Translator.instance.generateHTML( this._knots[knotName]) - if (this._knots[knotName].categories && - this._knots[knotName].categories.includes('note')) { this.presentNote(knot) } else { this.presentKnot(knot) } + console.log('=== theme settings') + console.log(Translator.instance.themeSettings.note) + let note = false + if (this._knots[knotName].categories && Translator.instance.themeSettings && + Translator.instance.themeSettings.note) + note = this._knots[knotName].categories.find( + cat => Translator.instance.themeSettings.note.includes(cat)) + if (note) { this.presentNote(knot) } else { this.presentKnot(knot) } } } MessageBus.ext.publish('knot/' + knotName + '/start') diff --git a/src/adonisjs/public/player/js/state.js b/src/adonisjs/public/player/js/state.js index 8954c16b7..6772e7ecb 100644 --- a/src/adonisjs/public/player/js/state.js +++ b/src/adonisjs/public/player/js/state.js @@ -124,20 +124,31 @@ class PlayState { variableGet (topic, message) { let id = MessageBus.extractLevel(topic, 2) + /* console.log('=== variable request') console.log(id) console.log('=== variables') console.log(this._state.variables) + */ + + + if (id.startsWith('Previous.')) { + const previousKnot = this.historyPreviousId() + if (previousKnot != null) { id = previousKnot + '.' + id.substring(9) } + } // tries to give a scope to the variable if (id != null && this._state.variables[id] == null) { const currentKnot = this.historyCurrent() if (currentKnot != null && - this._state.variables[currentKnot + '.' + id] != null) { id = currentKnot + '.' + id } + this._state.variables[currentKnot + '.' + id] != null) { id = currentKnot + '.' + id } } if (id != null) { + console.log('=== variable get') + console.log(id) + console.log(this._state.variables[id]) MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message), this._state.variables[id]) } @@ -173,6 +184,11 @@ class PlayState { return (this._state.history.length > 1) } + historyPreviousId() { + return (this.historyHasPrevious()) + ? this._state.history[this._state.history.length - 2] : null; + } + historyCurrent () { let current = null if (this._state.history.length > 0) { current = this._state.history[this._state.history.length - 1] } diff --git a/src/adonisjs/public/templates/simple/case/quiz_sequence.md b/src/adonisjs/public/templates/simple/case/quiz_sequence.md index c56c76360..26ef80e40 100644 --- a/src/adonisjs/public/templates/simple/case/quiz_sequence.md +++ b/src/adonisjs/public/templates/simple/case/quiz_sequence.md @@ -36,7 +36,7 @@ Write here the **feedback**. # Note (note) -**You answered:** ^Presentation.input1^. +**You answered:** ^Previous.input1^.
^parameter^ diff --git a/src/adonisjs/public/templates/simple/case/quiz_short.md b/src/adonisjs/public/templates/simple/case/quiz_short.md index 47c02f94c..726b793cc 100644 --- a/src/adonisjs/public/templates/simple/case/quiz_short.md +++ b/src/adonisjs/public/templates/simple/case/quiz_short.md @@ -3,28 +3,28 @@ Write here the **stem** of your quiz. > Write here the **lead-in** of your quiz. -+ Answer-key <-> "Feedback for Answer-key" ++ Answer-key <-> Presentation References "Feedback for Answer-key" + Distractor 1 <-> "Feedback for Distractor 1" + Distractor 2 <-> "Feedback for Distractor 2" + Distractor 3 <-> "Feedback for Distractor 3" * Next Case -> Case.Next -# Presentation Note (note) +# Note (note) -**You answered:** ^Presentation.input1^. +**You answered:** ^Previous.input1^.
^parameter^ # Presentation References (note) -**You answered:** ^Presentation.input1^. +**You answered:** ^Previous.input1^.
^parameter^ References <-> References -# References (note) +# References (note_references) * [Enter References](References) diff --git a/src/adonisjs/public/themes/simple/note_references.html b/src/adonisjs/public/themes/simple/note_references.html new file mode 100644 index 000000000..92504cf07 --- /dev/null +++ b/src/adonisjs/public/themes/simple/note_references.html @@ -0,0 +1,12 @@ +
+
+
+ + {knot} + +
+
+
+
+ +
\ No newline at end of file diff --git a/src/adonisjs/public/themes/simple/theme.json b/src/adonisjs/public/themes/simple/theme.json index 9e26dfeeb..08a3b584d 100644 --- a/src/adonisjs/public/themes/simple/theme.json +++ b/src/adonisjs/public/themes/simple/theme.json @@ -1 +1,3 @@ -{} \ No newline at end of file +{ + "note": ["note", "note_references"] +} \ No newline at end of file diff --git a/src/adonisjs/public/translator/translator.js b/src/adonisjs/public/translator/translator.js index d645cab13..7e1aeeb6f 100644 --- a/src/adonisjs/public/translator/translator.js +++ b/src/adonisjs/public/translator/translator.js @@ -26,6 +26,10 @@ class Translator { return (this.authoringRender) ? ' author' : '' } + get themeSettings () { + return this._themeSettings; + } + _authorAttrSub (superseq) { return (this.authoringRender && superseq == -1) ? ' author' : '' }