Skip to content

Commit

Permalink
New: Added _canShowCorrectness and .can-show-correctness for questions (
Browse files Browse the repository at this point in the history
fixes #582)

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

* Ensure only one style is applied at a time
  • Loading branch information
oliverfoster authored Oct 4, 2024
1 parent 11434ab commit c5668ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit c5668ac

Please sign in to comment.