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

New: Added _canShowCorrectness and .can-show-correctness for questions #582

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions js/models/questionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QuestionModel extends ComponentModel {
_isQuestionType: true,
_shouldDisplayAttempts: false,
_shouldShowMarking: false,
_canShowCorrectness: false,
_canShowModelAnswer: true,
_canShowFeedback: true,
_canShowMarking: true,
Expand Down Expand Up @@ -213,10 +214,11 @@ class QuestionModel extends ComponentModel {
const isEnabled = this.get('_isEnabled');
const buttonState = this.get('_buttonState');
const canShowModelAnswer = this.get('_canShowModelAnswer');
const canShowCorrectness = this.get('_canShowCorrectness');

if (isInteractionComplete) {

if (isCorrect || !canShowModelAnswer) {
if (isCorrect || (!canShowModelAnswer || canShowCorrectness)) {
// Use correct instead of complete to signify button state
this.set('_buttonState', BUTTON_STATE.CORRECT);

Expand Down Expand Up @@ -381,7 +383,11 @@ class QuestionModel extends ComponentModel {
}

if (this.get('_attemptsLeft') === 0) {
return this.get('_canShowModelAnswer') ? BUTTON_STATE.SHOW_CORRECT_ANSWER : BUTTON_STATE.INCORRECT;
const canShowModelAnswer = this.get('_canShowModelAnswer');
const canShowCorrectness = this.get('_canShowCorrectness');
return canShowModelAnswer && !canShowCorrectness
? BUTTON_STATE.SHOW_CORRECT_ANSWER
: BUTTON_STATE.INCORRECT;
}

return this.get('_isSubmitted') ? BUTTON_STATE.RESET : BUTTON_STATE.SUBMIT;
Expand Down
5 changes: 4 additions & 1 deletion js/views/questionView.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'core/js/models/questionModel';
class QuestionView extends ComponentView {

className() {
const canShowCorrectness = this.model.get('_canShowCorrectness');
const canShowModelAnswer = this.model.get('_canShowModelAnswer');
return [
'component',
'is-question',
Expand All @@ -21,7 +23,8 @@ class QuestionView extends ComponentView {
'is-' + this.model.get('_layout'),
(this.model.get('_isComplete') ? 'is-complete' : ''),
(this.model.get('_isOptional') ? 'is-optional' : ''),
(this.model.get('_canShowModelAnswer') ? 'can-show-model-answer' : ''),
(canShowCorrectness ? 'can-show-correctness' : ''),
(canShowModelAnswer && !canShowCorrectness ? 'can-show-model-answer' : ''),
(this.model.get('_canShowFeedback') ? 'can-show-feedback' : ''),
(this.model.get('_canShowMarking') ? 'can-show-marking' : '')
].join(' ');
Expand Down