fix: parse description/label as children (#300)
* fix: parse description/label as children * fix: bounce problem tag attributes to advanced
This commit is contained in:
@@ -28,6 +28,28 @@ export const nonQuestionKeys = [
|
||||
'textline',
|
||||
];
|
||||
|
||||
export const responseKeys = [
|
||||
'multiplechoiceresponse',
|
||||
'numericalresponse',
|
||||
'optionresponse',
|
||||
'stringresponse',
|
||||
'choiceresponse',
|
||||
'multiplechoiceresponse',
|
||||
'truefalseresponse',
|
||||
'optionresponse',
|
||||
'numericalresponse',
|
||||
'stringresponse',
|
||||
'customresponse',
|
||||
'symbolicresponse',
|
||||
'coderesponse',
|
||||
'externalresponse',
|
||||
'formularesponse',
|
||||
'schematicresponse',
|
||||
'imageresponse',
|
||||
'annotationresponse',
|
||||
'choicetextresponse',
|
||||
];
|
||||
|
||||
export const stripNonTextTags = ({ input, tag }) => {
|
||||
const stripedTags = {};
|
||||
Object.entries(input).forEach(([key, value]) => {
|
||||
@@ -313,12 +335,7 @@ export class OLXParser {
|
||||
};
|
||||
const builder = new XMLBuilder(options);
|
||||
const problemArray = _.get(this.questionData[0], problemType) || this.questionData;
|
||||
/* TODO: How do we uniquely identify the description?
|
||||
In order to parse description, there should be two states
|
||||
and settings should be introduced to edit the label and description.
|
||||
In turn editing the settings update the state and then it can be added to
|
||||
the parsed OLX.
|
||||
*/
|
||||
|
||||
const questionArray = [];
|
||||
problemArray.forEach(tag => {
|
||||
const tagName = Object.keys(tag)[0];
|
||||
@@ -327,6 +344,16 @@ export class OLXParser {
|
||||
throw new Error('Script Tag, reverting to Advanced Editor');
|
||||
}
|
||||
questionArray.push(tag);
|
||||
} else if (responseKeys.includes(tagName)) {
|
||||
/* <label> and <description> tags often are both valid olx as siblings or children of response type tags.
|
||||
They, however, do belong in the question, so we append them to the question.
|
||||
*/
|
||||
tag[tagName].forEach(subTag => {
|
||||
const subTagName = Object.keys(subTag)[0];
|
||||
if (subTagName === 'label' || subTagName === 'description') {
|
||||
questionArray.push(subTag);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
const questionString = builder.build(questionArray);
|
||||
@@ -428,6 +455,11 @@ export class OLXParser {
|
||||
if (_.isEmpty(this.problem)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (Object.keys(this.problem).some((key) => key.indexOf('@_') !== -1)) {
|
||||
throw new Error('Misc Attributes asscoiated with problem, opening in advanced editor');
|
||||
}
|
||||
|
||||
let answersObject = {};
|
||||
let additionalAttributes = {};
|
||||
let groupFeedbackList = [];
|
||||
|
||||
Reference in New Issue
Block a user