Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: PartlyCorrect feedback fallback values #416

Merged
merged 6 commits into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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