MOBILE-2272 quiz: Use settings name instead of displayoptions

main
Dani Palou 2020-11-06 11:19:09 +01:00
parent 07af88d5d9
commit 3df105b03b
4 changed files with 32 additions and 29 deletions

View File

@ -1576,12 +1576,12 @@ export class AddonModQuizProvider {
for (let i = 0; i < result.questions.length; i++) { for (let i = 0; i < result.questions.length; i++) {
const question = result.questions[i]; const question = result.questions[i];
if (!question.displayoptions) { if (!question.settings) {
// Site doesn't return displayoptions, stop. // Site doesn't return settings, stop.
break; break;
} }
question.displayoptions = this.utils.objectToKeyValueMap(question.displayoptions, 'name', 'value'); question.settings = this.textUtils.parseJSON(question.settings, null);
} }
return result; return result;

View File

@ -56,14 +56,14 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
* @return Whether units are in a separate field. * @return Whether units are in a separate field.
*/ */
hasSeparateUnitField(question: any): boolean { hasSeparateUnitField(question: any): boolean {
if (!question.displayoptions) { if (!question.settings) {
const element = this.domUtils.convertToElement(question.html); const element = this.domUtils.convertToElement(question.html);
return !!(element.querySelector('select[name*=unit]') || element.querySelector('input[type="radio"]')); return !!(element.querySelector('select[name*=unit]') || element.querySelector('input[type="radio"]'));
} }
return question.displayoptions.showunits === AddonQtypeCalculatedHandler.UNITRADIO || return question.settings.unitdisplay === AddonQtypeCalculatedHandler.UNITRADIO ||
question.displayoptions.showunits === AddonQtypeCalculatedHandler.UNITSELECT; question.settings.unitdisplay === AddonQtypeCalculatedHandler.UNITSELECT;
} }
/** /**
@ -85,7 +85,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
return 0; return 0;
} }
if (!question.displayoptions) { if (!question.settings) {
if (this.hasSeparateUnitField(question)) { if (this.hasSeparateUnitField(question)) {
return this.isValidValue(answers['unit']) ? 1 : 0; return this.isValidValue(answers['unit']) ? 1 : 0;
} }
@ -94,7 +94,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
return -1; return -1;
} }
if (question.displayoptions.showunits != AddonQtypeCalculatedHandler.UNITINPUT && parsedAnswer.unit) { if (question.settings.unitdisplay != AddonQtypeCalculatedHandler.UNITINPUT && parsedAnswer.unit) {
// There should be no units or be outside of the input, not valid. // There should be no units or be outside of the input, not valid.
return 0; return 0;
} }
@ -104,8 +104,8 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
return 0; return 0;
} }
if (question.displayoptions.showunits == AddonQtypeCalculatedHandler.UNITINPUT && if (question.settings.unitdisplay == AddonQtypeCalculatedHandler.UNITINPUT &&
question.displayoptions.unitgradingtype == AddonQtypeCalculatedHandler.UNITGRADED && question.settings.unitgradingtype == AddonQtypeCalculatedHandler.UNITGRADED &&
!this.isValidValue(parsedAnswer.unit)) { !this.isValidValue(parsedAnswer.unit)) {
// Unit not supplied inside the input and it's required. // Unit not supplied inside the input and it's required.
return 0; return 0;
@ -191,7 +191,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
let unitsLeft = false; let unitsLeft = false;
let match = null; let match = null;
if (!question.displayoptions) { if (!question.settings) {
// We don't know if units should be before or after so we check both. // We don't know if units should be before or after so we check both.
match = answer.match(new RegExp('^' + regexString)); match = answer.match(new RegExp('^' + regexString));
if (!match) { if (!match) {
@ -199,7 +199,7 @@ export class AddonQtypeCalculatedHandler implements CoreQuestionHandler {
match = answer.match(new RegExp(regexString + '$')); match = answer.match(new RegExp(regexString + '$'));
} }
} else { } else {
unitsLeft = question.displayoptions.unitsleft == '1'; unitsLeft = question.settings.unitsleft == '1';
regexString = unitsLeft ? regexString + '$' : '^' + regexString; regexString = unitsLeft ? regexString + '$' : '^' + regexString;
match = answer.match(new RegExp(regexString)); match = answer.match(new RegExp(regexString));

View File

@ -74,10 +74,10 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler {
* @return Allowed options. * @return Allowed options.
*/ */
protected getAllowedOptions(question: any): {text: boolean, attachments: boolean} { protected getAllowedOptions(question: any): {text: boolean, attachments: boolean} {
if (question.displayoptions) { if (question.settings) {
return { return {
text: question.displayoptions.responseformat != 'noinline', text: question.settings.responseformat != 'noinline',
attachments: question.displayoptions.attachments != '0', attachments: question.settings.attachments != '0',
}; };
} else { } else {
const element = this.domUtils.convertToElement(question.html); const element = this.domUtils.convertToElement(question.html);
@ -162,11 +162,11 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler {
const attachments = CoreFileSession.instance.getFiles(component, questionComponentId); const attachments = CoreFileSession.instance.getFiles(component, questionComponentId);
if (!allowedOptions.text) { if (!allowedOptions.text) {
return attachments && attachments.length >= Number(question.displayoptions.attachmentsrequired) ? 1 : 0; return attachments && attachments.length >= Number(question.settings.attachmentsrequired) ? 1 : 0;
} }
return (hasTextAnswer || question.displayoptions.responserequired == '0') && return (hasTextAnswer || question.settings.responserequired == '0') &&
(attachments && attachments.length > Number(question.displayoptions.attachmentsrequired)) ? 1 : 0; (attachments && attachments.length > Number(question.settings.attachmentsrequired)) ? 1 : 0;
} }
/** /**

View File

@ -107,8 +107,8 @@ export class CoreQuestionBaseComponent {
this.question.select = selectModel; this.question.select = selectModel;
// Check which one should be displayed first: the select or the input. // Check which one should be displayed first: the select or the input.
if (this.question.displayoptions) { if (this.question.settings) {
this.question.selectFirst = this.question.displayoptions.unitsleft == '1'; this.question.selectFirst = this.question.settings.unitsleft == '1';
} else { } else {
const input = questionEl.querySelector('input[type="text"][name*=answer]'); const input = questionEl.querySelector('input[type="text"][name*=answer]');
this.question.selectFirst = this.question.selectFirst =
@ -165,8 +165,8 @@ export class CoreQuestionBaseComponent {
} }
// Check which one should be displayed first: the options or the input. // Check which one should be displayed first: the options or the input.
if (this.question.displayoptions) { if (this.question.settings) {
this.question.optionsFirst = this.question.displayoptions.unitsleft == '1'; this.question.optionsFirst = this.question.settings.unitsleft == '1';
} else { } else {
const input = questionEl.querySelector('input[type="text"][name*=answer]'); const input = questionEl.querySelector('input[type="text"][name*=answer]');
this.question.optionsFirst = this.question.optionsFirst =
@ -216,11 +216,11 @@ export class CoreQuestionBaseComponent {
const textarea = <HTMLTextAreaElement> questionEl.querySelector('textarea[name*=_answer]'); const textarea = <HTMLTextAreaElement> questionEl.querySelector('textarea[name*=_answer]');
const answerDraftIdInput = <HTMLInputElement> questionEl.querySelector('input[name*="_answer:itemid"]'); const answerDraftIdInput = <HTMLInputElement> questionEl.querySelector('input[name*="_answer:itemid"]');
if (this.question.displayoptions) { if (this.question.settings) {
this.question.allowsAttachments = this.question.displayoptions.attachments != '0'; this.question.allowsAttachments = this.question.settings.attachments != '0';
this.question.allowsAnswerFiles = this.question.displayoptions.responseformat == 'editorfilepicker'; this.question.allowsAnswerFiles = this.question.settings.responseformat == 'editorfilepicker';
this.question.isMonospaced = this.question.displayoptions.responseformat == 'monospaced'; this.question.isMonospaced = this.question.settings.responseformat == 'monospaced';
this.question.isPlainText = this.question.isMonospaced || this.question.displayoptions.responseformat == 'plain'; this.question.isPlainText = this.question.isMonospaced || this.question.settings.responseformat == 'plain';
} else { } else {
this.question.allowsAttachments = !!questionEl.querySelector('div[id*=filemanager]'); this.question.allowsAttachments = !!questionEl.querySelector('div[id*=filemanager]');
this.question.allowsAnswerFiles = !!answerDraftIdInput; this.question.allowsAnswerFiles = !!answerDraftIdInput;
@ -282,8 +282,11 @@ export class CoreQuestionBaseComponent {
}; };
} }
this.question.attachmentsMaxFiles = Number(this.question.displayoptions.attachments); if (this.question.settings) {
this.question.attachmentsAcceptedTypes = this.question.displayoptions.filetypeslist; this.question.attachmentsMaxFiles = Number(this.question.settings.attachments);
this.question.attachmentsAcceptedTypes = this.question.settings.filetypeslist &&
this.question.settings.filetypeslist.join(',');
}
if (fileManagerUrl) { if (fileManagerUrl) {
const params = CoreUrlUtils.instance.extractUrlParams(fileManagerUrl); const params = CoreUrlUtils.instance.extractUrlParams(fileManagerUrl);