From 1f35d07e3c662834095f5f74cbcedbf1529fd4f3 Mon Sep 17 00:00:00 2001
From: Brandon Stull
Date: Fri, 3 Nov 2023 11:52:13 -0400
Subject: [PATCH] #554 Adjusted all relevant obonode converters and JSON to XML
parsers to add variable support. Created migration to add a 'state' column to
visits for tracking variable values per visit, for use in tracking those same
generated values when starting an assessment attempt. Added support for
variable usage in assessment attempt and review contexts.
---
.../viewer/stores/assessment-state-helpers.js | 11 +-
.../scripts/viewer/stores/variable-store.js | 9 +-
.../viewer/stores/variable-store.old.js | 208 ------------------
.../src/scripts/viewer/util/variable-util.js | 4 -
.../src/parsers/action-button-node-parser.js | 4 +-
.../src/parsers/assessment-node-parser.js | 3 +
.../src/parsers/break-node-parser.js | 4 +-
.../src/parsers/code-node-parser.js | 4 +-
.../src/parsers/content-node-parser.js | 3 +
.../src/parsers/excerpt-node-parser.js | 3 +
.../src/parsers/figure-node-parser.js | 4 +-
.../src/parsers/heading-node-parser.js | 3 +
.../src/parsers/html-node-parser.js | 4 +-
.../src/parsers/iframe-node-parser.js | 4 +-
.../src/parsers/list-node-parser.js | 4 +-
.../src/parsers/materia-node-parser.js | 4 +-
.../src/parsers/math-equation-node-parser.js | 4 +-
.../src/parsers/mc-answer-node-parser.js | 3 +
.../src/parsers/mc-choice-node-parser.js | 3 +
.../src/parsers/mc-feedback-node-parser.js | 3 +
.../src/parsers/mcAssessmentNodeParser.js | 3 +
.../src/parsers/page-node-parser.js | 4 +-
.../src/parsers/question-bank-node-parser.js | 3 +
.../src/parsers/question-node-parser.js | 3 +
.../src/parsers/table-node-parser.js | 3 +
.../src/parsers/text-node-parser.js | 4 +-
.../src/parsers/youtube-node-parser.js | 4 +-
.../20231027205008-modify-visits-add-state.js | 32 +++
.../server/models/variable-generator.js | 14 --
.../obojobo-express/server/models/visit.js | 19 +-
.../server/routes/api/visits.js | 11 +-
.../obojobo-chunks-action-button/converter.js | 1 +
.../obonode/obojobo-chunks-code/converter.js | 1 +
.../obojobo-chunks-excerpt/converter.js | 1 +
.../obojobo-chunks-figure/converter.js | 1 +
.../obonode/obojobo-chunks-html/converter.js | 1 +
.../obojobo-chunks-iframe/converter.js | 1 +
.../obonode/obojobo-chunks-list/converter.js | 1 +
.../obojobo-chunks-materia/converter.js | 1 +
.../obojobo-chunks-math-equation/converter.js | 1 +
.../converter.js | 1 +
.../obojobo-chunks-question-bank/converter.js | 1 +
.../obojobo-chunks-question/converter.js | 1 +
.../obonode/obojobo-chunks-table/converter.js | 1 +
.../obojobo-chunks-youtube/converter.js | 1 +
.../obonode/obojobo-pages-page/converter.js | 3 +-
.../components/full-review/index.js | 14 ++
.../server/attempt-start.js | 7 +-
48 files changed, 180 insertions(+), 247 deletions(-)
delete mode 100644 packages/app/obojobo-document-engine/src/scripts/viewer/stores/variable-store.old.js
create mode 100644 packages/app/obojobo-express/server/migrations/20231027205008-modify-visits-add-state.js
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 + ``
+ `` + textGroupXML + triggersXML + objectivesXML + varsXML + ``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/assessment-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/assessment-node-parser.js
index b4fdb140dd..3b92949e6c 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/assessment-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/assessment-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 assessmentNodeParser = (node, childrenParser) => {
@@ -8,6 +9,7 @@ const assessmentNodeParser = (node, childrenParser) => {
const scoreActionsXML = scoreActionsParser(node.content.scoreActions, childrenParser)
const rubricXML = rubricParser(node.content.rubric)
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
return (
@@ -17,6 +19,7 @@ const assessmentNodeParser = (node, childrenParser) => {
rubricXML +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/break-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/break-node-parser.js
index be9243df91..f783bf4fc8 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/break-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/break-node-parser.js
@@ -1,14 +1,16 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const breakNodeParser = 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 `
`
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/code-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/code-node-parser.js
index 86e6274d3b..e13d473d32 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/code-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/code-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 codeNodeParser = node => {
const id = node.id ? ` id="${node.id}"` : ''
const attrs = processAttrs(node.content, ['triggers', 'textGroup'])
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 ``
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/iframe-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/iframe-node-parser.js
index 8fa39f50b0..ff1850ba02 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/iframe-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/iframe-node-parser.js
@@ -1,15 +1,17 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const iFrameNodeParser = 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 ``
+ return ``
}
return ``
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/list-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/list-node-parser.js
index 3f67074135..fa38123d45 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/list-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/list-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 listNodeParser = node => {
@@ -10,9 +11,10 @@ const listNodeParser = node => {
const listStyles = listStylesParser(node.content.listStyles)
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 `` + listStyles + textGroupXML + triggersXML + objectivesXML + `
`
+ return `` + listStyles + textGroupXML + triggersXML + objectivesXML + varsXML + `
`
}
const listStylesParser = listStyles => {
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/materia-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/materia-node-parser.js
index 5581b5c460..60f502f667 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/materia-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/materia-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 materiaNodeParser = node => {
@@ -8,10 +9,11 @@ const materiaNodeParser = node => {
const attrs = processAttrs(node.content, ['triggers', 'actions'])
const triggersXML = processTriggers(node.content.triggers)
const textGroupXML = textGroupParser(node.content.textGroup)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
if (textGroupXML || triggersXML) {
- return `${textGroupXML}${triggersXML}${objectivesXML}`
+ return `${textGroupXML}${triggersXML}${objectivesXML}${varsXML}`
}
return ``
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/math-equation-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/math-equation-node-parser.js
index 522436b636..0f8135b588 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/math-equation-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/math-equation-node-parser.js
@@ -1,15 +1,17 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const mathEquationNodeParser = 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 ``
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/mc-answer-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/mc-answer-node-parser.js
index 3dc686e531..3168016287 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/mc-answer-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/mc-answer-node-parser.js
@@ -1,11 +1,13 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const mcAnswerNodeParser = (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 (
@@ -13,6 +15,7 @@ const mcAnswerNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/mc-choice-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/mc-choice-node-parser.js
index 92c5a528e0..1530914adf 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/mc-choice-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/mc-choice-node-parser.js
@@ -1,11 +1,13 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const mcChoiceNodeParser = (node, childrenParser) => {
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)
return (
@@ -13,6 +15,7 @@ const mcChoiceNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/mc-feedback-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/mc-feedback-node-parser.js
index 9a890ded90..61d249bcad 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/mc-feedback-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/mc-feedback-node-parser.js
@@ -1,11 +1,13 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const mcFeedbackNodeParser = (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 (
@@ -13,6 +15,7 @@ const mcFeedbackNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/mcAssessmentNodeParser.js b/packages/app/obojobo-document-json-parser/src/parsers/mcAssessmentNodeParser.js
index f02f2560f7..7e33cff6e1 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/mcAssessmentNodeParser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/mcAssessmentNodeParser.js
@@ -1,11 +1,13 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const mcAssessmentNodeParser = (node, childrenParser) => {
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)
return (
@@ -13,6 +15,7 @@ const mcAssessmentNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/page-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/page-node-parser.js
index edb59b5c40..e23e4493ba 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/page-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/page-node-parser.js
@@ -1,15 +1,17 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const pageNodeParser = (node, childrenParser) => {
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)
return (
- `` + childrenParser(node.children) + triggersXML + objectivesXML + ``
+ `` + childrenParser(node.children) + triggersXML + objectivesXML + varsXML + ``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/question-bank-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/question-bank-node-parser.js
index 1c5d39f91f..ab974b1122 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/question-bank-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/question-bank-node-parser.js
@@ -1,11 +1,13 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const questionBankNodeParser = (node, childrenParser) => {
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)
return (
@@ -13,6 +15,7 @@ const questionBankNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/question-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/question-node-parser.js
index 74c62dbe47..b2e5a367ce 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/question-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/question-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 questionNodeParser = (node, childrenParser) => {
@@ -13,6 +14,7 @@ const questionNodeParser = (node, childrenParser) => {
}
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
return (
@@ -21,6 +23,7 @@ const questionNodeParser = (node, childrenParser) => {
childrenParser(node.children) +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/table-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/table-node-parser.js
index 90ecf3eede..c2f8238fd7 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/table-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/table-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 tableNodeParser = node => {
@@ -13,6 +14,7 @@ const tableNodeParser = node => {
const attrs = processAttrs(node.content, ['triggers', 'textGroup'])
const textGroupXML = textGroupParser(node.content.textGroup.textGroup)
const triggersXML = processTriggers(node.content.triggers)
+ const varsXML = processVars(node.content.variables)
const objectivesXML = processObjectives(node.content.objectives)
return (
@@ -20,6 +22,7 @@ const tableNodeParser = node => {
textGroupXML +
triggersXML +
objectivesXML +
+ varsXML +
``
)
}
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/text-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/text-node-parser.js
index c928033acb..ec595d11e1 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/text-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/text-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 textNodeParser = node => {
@@ -8,9 +9,10 @@ const textNodeParser = node => {
const attrs = processAttrs(node.content, ['triggers', 'textGroup'])
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 = textNodeParser
diff --git a/packages/app/obojobo-document-json-parser/src/parsers/youtube-node-parser.js b/packages/app/obojobo-document-json-parser/src/parsers/youtube-node-parser.js
index 9b44b71a1f..50d9f864d3 100644
--- a/packages/app/obojobo-document-json-parser/src/parsers/youtube-node-parser.js
+++ b/packages/app/obojobo-document-json-parser/src/parsers/youtube-node-parser.js
@@ -1,6 +1,7 @@
const xmlEncode = require('../xml-encode')
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')
+const processVars = require('../process-vars')
const processObjectives = require('../process-objectives')
const youTubeNodeParser = node => {
@@ -8,10 +9,11 @@ const youTubeNodeParser = node => {
const videoId = xmlEncode(node.content.videoId)
const attrs = processAttrs(node.content, ['triggers'])
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 ``
diff --git a/packages/app/obojobo-express/server/migrations/20231027205008-modify-visits-add-state.js b/packages/app/obojobo-express/server/migrations/20231027205008-modify-visits-add-state.js
new file mode 100644
index 0000000000..d778ac0380
--- /dev/null
+++ b/packages/app/obojobo-express/server/migrations/20231027205008-modify-visits-add-state.js
@@ -0,0 +1,32 @@
+'use strict';
+
+var dbm;
+var type;
+var seed;
+
+/**
+ * We receive the dbmigrate dependency from dbmigrate initially.
+ * This enables us to not have to rely on NODE_PATH.
+ */
+exports.setup = function(options, seedLink) {
+ dbm = options.dbmigrate;
+ type = dbm.dataType;
+ seed = seedLink;
+};
+
+exports.up = function(db) {
+ return db
+ .addColumn('visits', 'state', {
+ type: 'jsonb'
+ })
+};
+
+exports.down = function(db) {
+ return db.removeColumn('visits', 'state', {
+ type: 'jsonb'
+ })
+};
+
+exports._meta = {
+ "version": 1
+};
diff --git a/packages/app/obojobo-express/server/models/variable-generator.js b/packages/app/obojobo-express/server/models/variable-generator.js
index 1979898bb1..4e8d3c1ba7 100644
--- a/packages/app/obojobo-express/server/models/variable-generator.js
+++ b/packages/app/obojobo-express/server/models/variable-generator.js
@@ -173,16 +173,6 @@ class VariableGenerator {
// }
generateOne(def) {
- // if (def.type === 'set') {
- // return this.getSet(def)
- // }
-
- // if (!def.name) {
- // throw 'Missing required name property!'
- // }
-
- console.log('generateOne', def)
-
let value = null
switch (def.type) {
@@ -219,10 +209,6 @@ class VariableGenerator {
throw 'Unexpected type!'
}
- // return {
- // name: def.name,
- // value
- // }
return value
}
diff --git a/packages/app/obojobo-express/server/models/visit.js b/packages/app/obojobo-express/server/models/visit.js
index 09f3533c46..4cb1402754 100644
--- a/packages/app/obojobo-express/server/models/visit.js
+++ b/packages/app/obojobo-express/server/models/visit.js
@@ -103,6 +103,8 @@ class Visit {
for (const prop in visitProps) {
this[prop] = visitProps[prop]
}
+
+ this.updateState.bind(this)
}
get draftDocument() {
@@ -119,7 +121,7 @@ class Visit {
return db
.one(
`
- SELECT id, user_id, is_active, is_preview, draft_id, draft_content_id, resource_link_id, score_importable
+ SELECT id, user_id, is_active, is_preview, draft_id, draft_content_id, resource_link_id, score_importable, state
FROM visits
WHERE id = $[visitId]
${requireIsActive ? 'AND is_active = true' : ''}
@@ -157,6 +159,21 @@ class Visit {
isPreview: true
})
}
+
+ updateState(state) {
+ return db
+ .none(
+ `
+ UPDATE visits
+ SET state=$[state]
+ WHERE id=$[visitId]
+ `,
+ {visitId: this.id, state}
+ )
+ .then(() => {
+ this.state = state
+ })
+ }
}
Visit.EVENT_NEW_VISIT = 'EVENT_NEW_VISIT'
diff --git a/packages/app/obojobo-express/server/routes/api/visits.js b/packages/app/obojobo-express/server/routes/api/visits.js
index 9c193bfa3e..f4f30918bf 100644
--- a/packages/app/obojobo-express/server/routes/api/visits.js
+++ b/packages/app/obojobo-express/server/routes/api/visits.js
@@ -22,9 +22,18 @@ const getDraftAndStartVisitProps = (req, res) => {
const getVariables = (req, res) => {
const variableValues = []
+ if (req.currentVisit.state && req.currentVisit.state.variables) {
+ return req.currentVisit.state.variables
+ }
return req.currentDocument
.yell('internal:generateVariables', req, res, variableValues)
- .then(() => variableValues)
+ .then(() => {
+ req.currentVisit.updateState({
+ ...req.currentVisit.state,
+ variables: variableValues
+ })
+ return variableValues
+ })
}
router
diff --git a/packages/obonode/obojobo-chunks-action-button/converter.js b/packages/obonode/obojobo-chunks-action-button/converter.js
index 2a9b31dea1..09290c2c49 100644
--- a/packages/obonode/obojobo-chunks-action-button/converter.js
+++ b/packages/obonode/obojobo-chunks-action-button/converter.js
@@ -22,6 +22,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
textGroup: [labelLine],
align: node.content.align
})
diff --git a/packages/obonode/obojobo-chunks-code/converter.js b/packages/obonode/obojobo-chunks-code/converter.js
index 0ea1f4c54a..ebc9d65f77 100644
--- a/packages/obonode/obojobo-chunks-code/converter.js
+++ b/packages/obonode/obojobo-chunks-code/converter.js
@@ -42,6 +42,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
textGroup
})
}
diff --git a/packages/obonode/obojobo-chunks-excerpt/converter.js b/packages/obonode/obojobo-chunks-excerpt/converter.js
index 803156f13b..4f9f87d5e2 100644
--- a/packages/obonode/obojobo-chunks-excerpt/converter.js
+++ b/packages/obonode/obojobo-chunks-excerpt/converter.js
@@ -31,6 +31,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
citation: citationText,
bodyStyle: node.content.bodyStyle,
topEdge: node.content.topEdge,
diff --git a/packages/obonode/obojobo-chunks-figure/converter.js b/packages/obonode/obojobo-chunks-figure/converter.js
index 09070e5008..d55943b22e 100644
--- a/packages/obonode/obojobo-chunks-figure/converter.js
+++ b/packages/obonode/obojobo-chunks-figure/converter.js
@@ -23,6 +23,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
textGroup: [captionLine],
alt: node.content.alt,
url: node.content.url,
diff --git a/packages/obonode/obojobo-chunks-html/converter.js b/packages/obonode/obojobo-chunks-html/converter.js
index 597d94638c..e094a0cc05 100644
--- a/packages/obonode/obojobo-chunks-html/converter.js
+++ b/packages/obonode/obojobo-chunks-html/converter.js
@@ -15,6 +15,7 @@ const slateToObo = node => ({
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
html: Node.string(node)
})
})
diff --git a/packages/obonode/obojobo-chunks-iframe/converter.js b/packages/obonode/obojobo-chunks-iframe/converter.js
index 02f7f888d0..563b436edf 100644
--- a/packages/obonode/obojobo-chunks-iframe/converter.js
+++ b/packages/obonode/obojobo-chunks-iframe/converter.js
@@ -18,6 +18,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
src: node.content.src,
title: node.content.title,
type: node.content.type,
diff --git a/packages/obonode/obojobo-chunks-list/converter.js b/packages/obonode/obojobo-chunks-list/converter.js
index 7537b42cbc..c07edd74d4 100644
--- a/packages/obonode/obojobo-chunks-list/converter.js
+++ b/packages/obonode/obojobo-chunks-list/converter.js
@@ -77,6 +77,7 @@ const slateToObo = node => {
spacing: node.content.spacing,
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
listStyles: {
type: node.content.listStyles.type,
indents
diff --git a/packages/obonode/obojobo-chunks-materia/converter.js b/packages/obonode/obojobo-chunks-materia/converter.js
index 9051c19dac..40c365fe0b 100644
--- a/packages/obonode/obojobo-chunks-materia/converter.js
+++ b/packages/obonode/obojobo-chunks-materia/converter.js
@@ -22,6 +22,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
textGroup: [captionLine],
src: node.content.src,
widgetEngine: node.content.widgetEngine,
diff --git a/packages/obonode/obojobo-chunks-math-equation/converter.js b/packages/obonode/obojobo-chunks-math-equation/converter.js
index 5ea79a7dd4..43ba040382 100644
--- a/packages/obonode/obojobo-chunks-math-equation/converter.js
+++ b/packages/obonode/obojobo-chunks-math-equation/converter.js
@@ -14,6 +14,7 @@ const slateToObo = node => ({
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
latex: node.content.latex,
alt: node.content.alt,
align: node.content.align,
diff --git a/packages/obonode/obojobo-chunks-multiple-choice-assessment/converter.js b/packages/obonode/obojobo-chunks-multiple-choice-assessment/converter.js
index b379712ceb..87290a4401 100644
--- a/packages/obonode/obojobo-chunks-multiple-choice-assessment/converter.js
+++ b/packages/obonode/obojobo-chunks-multiple-choice-assessment/converter.js
@@ -37,6 +37,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
responseType,
shuffle: node.content.shuffle
})
diff --git a/packages/obonode/obojobo-chunks-question-bank/converter.js b/packages/obonode/obojobo-chunks-question-bank/converter.js
index ccb861f7f1..3aefdd8f4f 100644
--- a/packages/obonode/obojobo-chunks-question-bank/converter.js
+++ b/packages/obonode/obojobo-chunks-question-bank/converter.js
@@ -43,6 +43,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
choose: getChooseValue(node.content.chooseAll, node.content.choose),
select: node.content.select,
collapsed: node.content.collapsed
diff --git a/packages/obonode/obojobo-chunks-question/converter.js b/packages/obonode/obojobo-chunks-question/converter.js
index 932b13e968..3e792a1190 100644
--- a/packages/obonode/obojobo-chunks-question/converter.js
+++ b/packages/obonode/obojobo-chunks-question/converter.js
@@ -21,6 +21,7 @@ const slateToObo = node => {
const content = {
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
type: node.content.type,
revealAnswer: node.content.revealAnswer,
collapsed: node.content.collapsed
diff --git a/packages/obonode/obojobo-chunks-table/converter.js b/packages/obonode/obojobo-chunks-table/converter.js
index 9cd952b503..6327b26262 100644
--- a/packages/obonode/obojobo-chunks-table/converter.js
+++ b/packages/obonode/obojobo-chunks-table/converter.js
@@ -33,6 +33,7 @@ const slateToObo = node => {
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
header: node.content.header,
display: node.content.display,
textGroup: {
diff --git a/packages/obonode/obojobo-chunks-youtube/converter.js b/packages/obonode/obojobo-chunks-youtube/converter.js
index 166cccb3de..d884db712b 100644
--- a/packages/obonode/obojobo-chunks-youtube/converter.js
+++ b/packages/obonode/obojobo-chunks-youtube/converter.js
@@ -14,6 +14,7 @@ const slateToObo = node => ({
content: withoutUndefined({
triggers: node.content.triggers,
objectives: node.content.objectives,
+ variables: node.content.variables,
videoId: node.content.videoId,
startTime: node.content.startTime,
endTime: node.content.endTime
diff --git a/packages/obonode/obojobo-pages-page/converter.js b/packages/obonode/obojobo-pages-page/converter.js
index ea0eec1898..bf8f4c1625 100644
--- a/packages/obonode/obojobo-pages-page/converter.js
+++ b/packages/obonode/obojobo-pages-page/converter.js
@@ -14,7 +14,8 @@ const slateToObo = node => ({
children: node.children.map(child => Component.helpers.slateToObo(child)),
content: withoutUndefined({
triggers: node.content.triggers,
- objectives: node.content.objectives
+ objectives: node.content.objectives,
+ variables: node.content.variables
})
})
diff --git a/packages/obonode/obojobo-sections-assessment/components/full-review/index.js b/packages/obonode/obojobo-sections-assessment/components/full-review/index.js
index bf50545142..c8cc339a0d 100644
--- a/packages/obonode/obojobo-sections-assessment/components/full-review/index.js
+++ b/packages/obonode/obojobo-sections-assessment/components/full-review/index.js
@@ -11,6 +11,7 @@ const { AssessmentUtil } = Viewer.util
const { NavUtil } = Viewer.util
const { OboModel } = Common.models
const { Button, ButtonBar, MoreInfoButton } = Common.components
+const { Dispatcher } = Common.flux
class AssessmentReviewView extends React.Component {
componentDidMount() {
@@ -20,6 +21,19 @@ class AssessmentReviewView extends React.Component {
)
NavUtil.setContext(`assessmentReview:${lastAttempt.id}`)
+
+ // no real way of knowing whether this has been done before, so make sure variable contexts
+ // exist for all attempts
+ // the variable store should prevent duplicates on its own
+ this.props.attempts.forEach(attempt => {
+ const attemptContext = `assessmentReview:${attempt.id}`
+ Dispatcher.trigger('variables:addContext', {
+ value: {
+ context: attemptContext,
+ variables: attempt.state.variables
+ }
+ })
+ })
}
render() {
diff --git a/packages/obonode/obojobo-sections-assessment/server/attempt-start.js b/packages/obonode/obojobo-sections-assessment/server/attempt-start.js
index 5f4934038c..8ed1408972 100644
--- a/packages/obonode/obojobo-sections-assessment/server/attempt-start.js
+++ b/packages/obonode/obojobo-sections-assessment/server/attempt-start.js
@@ -30,6 +30,7 @@ const startAttempt = (req, res) => {
attemptHistory: null,
numAttemptsTaken: null,
questionUsesMap: null,
+ variables: req.currentVisit.state.variables ?? null,
resourceLinkId: req.currentVisit.resource_link_id
}
@@ -87,7 +88,8 @@ const startAttempt = (req, res) => {
req.currentDocument.contentId,
req.body.assessmentId,
{
- chosen: attemptState.chosen
+ chosen: attemptState.chosen,
+ variables: attemptState.variables
},
req.currentVisit.is_preview,
req.currentVisit.resource_link_id
@@ -142,7 +144,8 @@ const getState = assessmentProperties => {
})
return {
- chosen: chosenAssessment
+ chosen: chosenAssessment,
+ variables: assessmentProperties.variables ?? null
}
}