diff --git a/packages/app/obojobo-document-engine/src/scripts/viewer/stores/assessment-state-helpers.js b/packages/app/obojobo-document-engine/src/scripts/viewer/stores/assessment-state-helpers.js
index 2b8f69b464..5ec964fcab 100644
--- a/packages/app/obojobo-document-engine/src/scripts/viewer/stores/assessment-state-helpers.js
+++ b/packages/app/obojobo-document-engine/src/scripts/viewer/stores/assessment-state-helpers.js
@@ -202,7 +202,7 @@ class AssessmentStateHelpers {
const assessmentModel = OboModel.models[assessmentId]
if (assessment.questionResponses && assessment.questionResponses.length > 0) {
- const context = `assessment:${assessmentId}:${assessment.attemptId}`
+ const context = this.composeNavContextString(assessmentId, assessment.attemptId)
const contextState = QuestionStore.getOrCreateContextState(context)
@@ -240,6 +240,7 @@ class AssessmentStateHelpers {
}
this.setAssessmentQuestionBank(assessmentModel, assessment.questions)
+ this.setAssessmentAttemptVariables(assessmentModel, assessment.attemptId, assessment.state.variables)
this.updateNavContextAndMenu(assessmentModel, assessment.attemptId)
this.signalAttemptStarted(assessmentModel)
@@ -254,6 +255,14 @@ class AssessmentStateHelpers {
Array.from(questions).forEach(child => qb.children.add(OboModel.create(child)))
}
+ static setAssessmentAttemptVariables(assessmentModel, attemptId, variables) {
+ const assessmentId = assessmentModel.get('id')
+ const context = this.composeNavContextString(assessmentId, attemptId)
+ Dispatcher.trigger('variables:addContext', {
+ value: { context, variables }
+ })
+ }
+
static updateNavContextAndMenu(assessmentModel, attemptId) {
const assessmentId = assessmentModel.get('id')
diff --git a/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.js b/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.js
index e6be37269c..8cd953b20c 100644
--- a/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.js
+++ b/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.js
@@ -1,6 +1,5 @@
import Common from 'Common'
import VariableUtil from '../util/variable-util'
-// import VariableGenerator from './variable-store/variable-generator'
const { Store } = Common.flux
const { Dispatcher } = Common.flux
@@ -15,10 +14,15 @@ const getNewContextState = () => {
class VariableStore extends Store {
constructor() {
super('variableStore')
+
+ Dispatcher.on({
+ 'variables:addContext': payload => {
+ this._addMultiple(payload.value.context, payload.value.variables)
+ }
+ })
}
_addMultiple(context, values) {
- console.log('add mult', context, values, this)
values.forEach(({ id, value }) => {
const [ownerId, varName] = id.split(':')
this._add(context, ownerId, varName, value)
@@ -62,7 +66,6 @@ class VariableStore extends Store {
}
}
- // this._addVariablesForModel('practice', variableState)
this._addMultiple('practice', variableValues)
}
diff --git a/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.old.js b/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.old.js
deleted file mode 100644
index 468acb9c8f..0000000000
--- a/packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.old.js
+++ /dev/null
@@ -1,208 +0,0 @@
-import Common from 'Common'
-import VariableUtil from '../util/varible-util'
-import VariableGenerator from './variable-store/variable-generator'
-
-const { Store } = Common.flux
-const { Dispatcher } = Common.flux
-
-const getNewContextState = () => {
- return {
- defs: {},
- values: {},
- varNamesByOwnerId: {}
- }
-}
-
-class VariableStore extends Store {
- constructor() {
- super('variableStore')
-
- Dispatcher.on({
- 'variable:clear': this.clear.bind(this),
- 'variable:clearAll': this.clearAll.bind(this),
- 'variable:setValue': this.setValue.bind(this),
- 'variable:regenerateValue': this.regenerateValue.bind(this)
- })
- }
-
- _clearValue(context, ownerId, varName) {
- const contextState = this.getOrCreateContextState(context)
- const key = VariableUtil.getKey(ownerId, varName)
-
- delete contextState.values[key]
- }
-
- _setValue(context, ownerId, varName, value) {
- const contextState = this.getOrCreateContextState(context)
- const key = VariableUtil.getKey(ownerId, varName)
-
- contextState.values[key] = value
- }
-
- _setDefinition(context, ownerId, varName, definition) {
- const contextState = this.getOrCreateContextState(context)
- const key = VariableUtil.getKey(ownerId, varName)
-
- contextState.defs[key] = definition
- }
-
- _add(context, ownerId, varName, varDefintion, generateValue) {
- const contextState = this.getOrCreateContextState(context)
-
- this._setDefinition(context, ownerId, varName, varDefintion)
-
- if (!contextState.varNamesByOwnerId[ownerId]) {
- contextState.varNamesByOwnerId[ownerId] = {}
- }
- contextState.varNamesByOwnerId[ownerId][varName] = true
-
- if (generateValue) {
- this._generateValue(context, ownerId, varName)
- }
- }
-
- _addMultiple(context, ownerId, variableDefinitions = [], generateValue) {
- variableDefinitions.forEach(v => {
- this._add(context, ownerId, v.name, { ...v }, generateValue)
- })
- }
-
- _remove(context, ownerId, varName) {
- const contextState = this.getOrCreateContextState(context)
-
- this._clearValue(context, ownerId, varName)
- const key = VariableUtil.getKey(ownerId, varName)
-
- delete contextState.defs[key]
- delete contextState.varNamesByOwnerId[ownerId][varName]
-
- if (Object.keys(contextState.varNamesByOwnerId[ownerId]).length === 0) {
- delete contextState.varNamesByOwnerId[ownerId]
- }
- }
-
- _removeAll(context, ownerId) {
- const contextState = this.getOrCreateContextState(context)
-
- Object.keys(contextState.varNamesByOwnerId[ownerId]).forEach(varName => {
- this._remove(context, ownerId, varName)
- })
- }
-
- _generateValue(context, ownerId, varName) {
- this.getOrCreateContextState(context)
-
- const value = VariableGenerator.generateOne(
- VariableUtil.getDefinition(context, this.state, ownerId, varName)
- )
-
- this._setValue(context, ownerId, varName, value)
-
- return value
- }
-
- _addVariablesForModel(context, model) {
- if (model.vars) {
- this._addMultiple(context, model.get('id'), model.vars, true)
- }
-
- if (model.children) {
- model.children.models.forEach(child => this._addVariablesForModel(context, child))
- }
- }
-
- clear(payload) {
- const ownerId = payload.value.id
- const varName = payload.value.name
- const context = payload.value.context
-
- this._clear(context, ownerId, varName)
-
- this.triggerChange()
-
- Dispatcher.trigger('variable:cleared', { context, id: ownerId, name: varName })
- }
-
- clearAll(payload) {
- const contextState = this.getOrCreateContextState(context)
-
- const ownerId = payload.value.id
- const context = payload.value.context
-
- Object.keys(contextState.varNamesByOwnerId[ownerId]).forEach(varName => {
- this._clear(context, ownerId, varName)
- })
-
- this.triggerChange()
-
- Dispatcher.trigger('variable:clearedAll', { context, id: ownerId })
- }
-
- setValue(payload) {
- const ownerId = payload.value.id
- const varName = payload.value.name
- const value = payload.value.value
- const context = payload.value.context
-
- this._setValue(context, ownerId, varName)
-
- this.triggerChange()
-
- Dispatcher.trigger('variable:valueSet', { context, id: ownerId, name: varName, value })
- }
-
- regenerateValue(payload) {
- const ownerId = payload.value.id
- const varName = payload.value.name
- const context = payload.value.context
-
- const value = this._generateValue(context, ownerId, varName)
-
- this.triggerChange()
-
- Dispatcher.trigger('variable:valueRegenerated', { context, id: ownerId, name: varName, value })
- }
-
- getContextState(context) {
- return this.state.contexts[context] || null
- }
-
- hasContextState(context) {
- return this.getContextState(context) !== null
- }
-
- getOrCreateContextState(context) {
- let contextState = this.getContextState(context)
-
- if (!contextState) {
- contextState = getNewContextState()
- this.state.contexts[context] = contextState
- }
-
- return contextState
- }
-
- init(model) {
- this.state = {
- contexts: {
- practice: getNewContextState()
- }
- }
-
- this._addVariablesForModel('practice', model)
- }
-
- getState() {
- return this.state
- }
-
- setState(newState) {
- this.state = newState
- }
-}
-
-const variableStore = new VariableStore()
-
-window.__vs = variableStore
-
-export default variableStore
diff --git a/packages/app/obojobo-document-engine/src/scripts/viewer/util/variable-util.js b/packages/app/obojobo-document-engine/src/scripts/viewer/util/variable-util.js
index 1c81202a96..ce9e65e9cf 100644
--- a/packages/app/obojobo-document-engine/src/scripts/viewer/util/variable-util.js
+++ b/packages/app/obojobo-document-engine/src/scripts/viewer/util/variable-util.js
@@ -1,7 +1,3 @@
-import Common from 'Common'
-
-const { Dispatcher } = Common.flux
-
const VariableUtil = {
getKey(ownerId, varName) {
return `${ownerId}:${varName}`
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/action-button-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/action-button-node-parser.js
index ee48d48eae..4b873c76be 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/action-button-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/action-button-node-parser.js
@@ -1,5 +1,6 @@
const textGroupParser = require('../text-group-parser')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const processAttrs = require('../process-attrs')
@@ -8,10 +9,11 @@ const actionButtonNodeParser = node => {
const attrs = processAttrs(node.content, ['triggers', 'textGroup', 'actions'])
const textGroupXML = textGroupParser(node.content.textGroup)
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
return (
- `
` + textGroupXML + triggersXML + objectivesXML + `
`
+ return `` + textGroupXML + triggersXML + objectivesXML + varsXML `
`
}
module.exports = codeNodeParser
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/content-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/content-node-parser.js
index f1f8ea958e..f3d07afcb8 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/content-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/content-node-parser.js
@@ -1,10 +1,12 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const contentNodeParser = (node, childrenParser) => {
const id = node.id ? ` id="${node.id}"` : ''
const attrs = processAttrs(node.content, ['triggers'])
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
return (
@@ -12,6 +14,7 @@ const contentNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/excerpt-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/excerpt-node-parser.js
index 5c8d125581..c6337291e0 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/excerpt-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/excerpt-node-parser.js
@@ -1,5 +1,6 @@
const processTriggers = require('../process-triggers')
const processAttrs = require('../process-attrs')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const excerptNodeParser = (node, childrenParser) => {
@@ -7,6 +8,7 @@ const excerptNodeParser = (node, childrenParser) => {
const attrs = processAttrs(node.content, ['triggers', 'actions'])
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
return (
@@ -14,6 +16,7 @@ const excerptNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/figure-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/figure-node-parser.js
index f7c6945041..7cf3b0c8af 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/figure-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/figure-node-parser.js
@@ -1,15 +1,17 @@
const textGroupParser = require('../text-group-parser')
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const figureNodeParser = node => {
const id = node.id ? ` id="${node.id}"` : ''
const textGroupXML = textGroupParser(node.content.textGroup)
const triggersXML = processTriggers(node.content.triggers)
const attrs = processAttrs(node.content, ['textGroup', 'triggers', 'actions'])
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
- return ``
+ return ``
}
module.exports = figureNodeParser
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/heading-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/heading-node-parser.js
index af3f7c44d5..bc6f503719 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/heading-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/heading-node-parser.js
@@ -1,6 +1,7 @@
const textGroupParser = require('../text-group-parser')
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const headingNodeParser = node => {
const id = node.id ? ` id="${node.id}"` : ''
@@ -10,6 +11,7 @@ const headingNodeParser = node => {
: ''
const textGroupXML = textGroupParser(node.content.textGroup)
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
const attrs = processAttrs(node.content, ['triggers', 'textGroup'])
@@ -18,6 +20,7 @@ const headingNodeParser = node => {
textGroupXML +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/html-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/html-node-parser.js
index f5def6b1a4..c603e6eba8 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/html-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/html-node-parser.js
@@ -1,13 +1,15 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const htmlNodeParser = node => {
const id = node.id ? ` id="${node.id}"` : ''
const attrs = processAttrs(node.content, ['triggers', 'actions'])
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
if (triggersXML) {
- return `${triggersXML}` + objectivesXML + ``
+ return `${triggersXML}` + objectivesXML + varsXML + ``
}
return `