Skip to content

Commit

Permalink
Fix: PartlyCorrect feedback fallback values (#416)
Browse files Browse the repository at this point in the history
* Fix: PartlyCorrect feedback fallback values

* Changing feedback ternery structure for Incorrect

* [WIP] Reducing duplicated code

* Fix: Tidy up of feedback object building

* Adding missing semicolons

* Further refactor (#421)

---------

Co-authored-by: Oliver Foster <[email protected]>
  • Loading branch information
1 parent b4cd40e commit c093556
Showing 1 changed file with 52 additions and 95 deletions.
147 changes: 52 additions & 95 deletions js/models/questionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,108 +242,65 @@ class QuestionModel extends ComponentModel {

}

getFeedback (_feedback = this.get('_feedback')) {
if (!_feedback) return {};
getFeedback(feedback = this.get('_feedback')) {
if (!feedback) return {};

const isFinal = (this.get('_attemptsLeft') === 0);
const correctness = this.get('_isCorrect')
const isCorrect = this.get('_isCorrect');
const correctness = isCorrect
? 'correct'
: this.isPartlyCorrect()
? 'partlyCorrect'
: 'incorrect';

// global feedback altTitle / title / _classes
let {
altTitle,
title,
_classes
} = _feedback;

altTitle = altTitle || Adapt.course.get('_globals')._accessibility.altFeedbackTitle || '';
title = title || this.get('displayTitle') || this.get('title') || '';

switch (correctness) {
case 'correct': {
if (typeof _feedback.correct === 'string') {
// old style
return {
// add higher values
altTitle,
title,
_classes,
body: _feedback.correct
};
}
// new style
const feedbackCorrect = _feedback._correct;
const feedbackConfig = {
// add higher values
...feedbackCorrect || {},
altTitle: feedbackCorrect?.altTitle || altTitle,
title: feedbackCorrect?.title || title,
_classes: feedbackCorrect?._classes || _classes
};
if (feedbackConfig?._graphic?._src && !feedbackConfig?._imageAlignment) {
feedbackConfig._imageAlignment = 'right';
}
return feedbackConfig;
}

case 'partlyCorrect': {
if (typeof _feedback._partlyCorrect === 'object') {
// old style
return {
// add higher values
altTitle,
title,
_classes,
body: !isFinal
? _feedback._partlyCorrect?.notFinal || _feedback._incorrect?.notFinal || ''
: _feedback._partlyCorrect?.final || _feedback._incorrect?.final || ''
};
}
// new style
const feedbackPartlyCorrect = !isFinal ? _feedback._partlyCorrectNotFinal || _feedback._incorrectNotFinal : _feedback._partlyCorrectFinal || _feedback._incorrectFinal;
const feedbackConfig = {
// add higher values
...feedbackPartlyCorrect || {},
altTitle: feedbackPartlyCorrect?.altTitle || altTitle,
title: feedbackPartlyCorrect?.title || title,
_classes: feedbackPartlyCorrect?._classes || _classes
};
if (feedbackConfig?._graphic?._src && !feedbackConfig?._imageAlignment) {
feedbackConfig._imageAlignment = 'right';
}
return feedbackConfig;
}
case 'incorrect': {
if (typeof _feedback._incorrect === 'object') {
// old style
return {
// add higher values
altTitle,
title,
_classes,
body: !isFinal
? (_feedback._incorrect.notFinal || _feedback._incorrect.final)
: _feedback._incorrect.final
};
}
// new style
const feedbackIncorrect = !isFinal ? (_feedback._incorrectNotFinal || _feedback._incorrectFinal) : _feedback._incorrectFinal;
const feedbackConfig = {
// add higher values
...feedbackIncorrect || {},
altTitle: feedbackIncorrect?.altTitle || altTitle,
title: feedbackIncorrect?.title || title,
_classes: feedbackIncorrect?._classes || _classes
};
if (feedbackConfig?._graphic?._src && !feedbackConfig?._imageAlignment) {
feedbackConfig._imageAlignment = 'right';
}
return feedbackConfig;
}
const isLegacyConfig = (typeof feedback.correct === 'string') ||
(typeof feedback._partlyCorrect === 'object') ||
(typeof feedback._incorrect === 'object');

const getLegacyConfigObject = () => {
const subPart = isFinal ? 'final' : 'notFinal';
return {
body: (
isCorrect
? feedback.correct
: feedback[`_${correctness}`]?.[subPart] ||
feedback[`_${correctness}`]?.final ||
feedback._incorrect?.final
) || ''
};
};

const getConfigObject = () => {
const subPart = isFinal ? 'Final' : 'NotFinal';
return (
isCorrect
? feedback._correct
: feedback[`_${correctness}${subPart}`] ||
feedback[`_${correctness}Final`] ||
feedback._incorrectFinal
) || {};
};

const feedbackConfig = {
altTitle: feedback.altTitle ||
Adapt.course.get('_globals')._accessibility.altFeedbackTitle ||
'',
title: feedback.title ||
this.get('displayTitle') ||
this.get('title') ||
'',
_classes: feedback._classes,
...(isLegacyConfig
? getLegacyConfigObject()
: getConfigObject()
)
};

if (feedbackConfig?._graphic?._src && !feedbackConfig?._imageAlignment) {
feedbackConfig._imageAlignment = 'right';
}
return {};

return feedbackConfig;
}

// Used to setup the correct, incorrect and partly correct feedback
Expand Down

0 comments on commit c093556

Please sign in to comment.