Skip to content

Commit e198411

Browse files
committed
MOBILE-4638 quiz: Apply new correctness icons depending on LMS version
1 parent fdf7ac7 commit e198411

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

src/addons/qtype/ordering/component/addon-qtype-ordering.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
@if (dragDisabled) {
2121
@if (item.correctClass === 'correct') {
22-
<ion-icon name="fas-check-double" slot="start" [ariaLabel]="'core.question.correct' | translate" color="success" />
22+
<ion-icon [name]="correctIcon" slot="start" [ariaLabel]="'core.question.correct' | translate" color="success" />
2323
} @else if (item.correctClass === 'incorrect') {
2424
<ion-icon name="fas-xmark" slot="start" [ariaLabel]="'core.question.incorrect' | translate" color="danger" />
2525
} @else if (item.correctClass.startsWith('partial')) {
26-
<ion-icon name="fas-check" slot="start" [ariaLabel]="'core.question.partiallycorrect' | translate" color="warning" />
26+
<ion-icon [name]="partialCorrectIcon" slot="start" [ariaLabel]="'core.question.partiallycorrect' | translate"
27+
color="warning" />
2728
}
2829
}
2930

src/addons/qtype/ordering/component/ordering.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export class AddonQtypeOrderingComponent extends CoreQuestionBaseComponent<Addon
3939
value: '',
4040
};
4141

42+
correctIcon = '';
43+
partialCorrectIcon = '';
44+
4245
constructor(elementRef: ElementRef) {
4346
super('AddonQtypeOrderingComponent', elementRef);
4447
}
@@ -56,6 +59,9 @@ export class AddonQtypeOrderingComponent extends CoreQuestionBaseComponent<Addon
5659
return;
5760
}
5861

62+
this.correctIcon = CoreQuestionHelper.getCorrectIcon();
63+
this.partialCorrectIcon = CoreQuestionHelper.getPartiallyCorrectIcon();
64+
5965
// Replace Moodle's feedback classes with our own.
6066
CoreQuestionHelper.replaceFeedbackClasses(questionElement);
6167

src/core/features/question/classes/base-question-component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,12 @@ export class CoreQuestionBaseComponent<T extends AddonModQuizQuestion = AddonMod
497497
question.input.correctIconLabel = 'core.question.incorrect';
498498
} else if (input.classList.contains('correct')) {
499499
question.input.correctClass = 'core-question-correct';
500-
question.input.correctIcon = 'fas-check-double';
500+
question.input.correctIcon = CoreQuestionHelper.getCorrectIcon();
501501
question.input.correctIconColor = CoreIonicColorNames.SUCCESS;
502502
question.input.correctIconLabel = 'core.question.correct';
503503
} else if (input.classList.contains('partiallycorrect')) {
504504
question.input.correctClass = 'core-question-partiallycorrect';
505-
question.input.correctIcon = 'fas-check';
505+
question.input.correctIcon = CoreQuestionHelper.getPartiallyCorrectIcon();
506506
question.input.correctIconColor = CoreIonicColorNames.WARNING;
507507
question.input.correctIconLabel = 'core.question.partiallycorrect';
508508
} else {

src/core/features/question/services/question-helper.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,36 @@ export class CoreQuestionHelperProvider {
795795
onAbort?.emit();
796796
}
797797

798+
/**
799+
* Returns correct icon based on the LMS version.
800+
* In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
801+
*
802+
* @param withPrefix Whether to include the prefix in the icon name.
803+
* @returns Icon name.
804+
*/
805+
getCorrectIcon(withPrefix = true): string {
806+
const icon = CoreSites.getRequiredCurrentSite().isVersionGreaterEqualThan('4.5')
807+
? 'check-double'
808+
: 'check';
809+
810+
return withPrefix ? `fas-${icon}` : icon;
811+
}
812+
813+
/**
814+
* Returns partially correct icon based on the LMS version.
815+
* In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
816+
*
817+
* @param withPrefix Whether to include the prefix in the icon name.
818+
* @returns Icon name.
819+
*/
820+
getPartiallyCorrectIcon(withPrefix = true): string {
821+
const icon = CoreSites.getRequiredCurrentSite().isVersionGreaterEqualThan('4.5')
822+
? 'check'
823+
: 'square-check';
824+
825+
return withPrefix ? `fas-${icon}` : icon;
826+
}
827+
798828
/**
799829
* Treat correctness icons, replacing them with local icons and setting click events to show the feedback if needed.
800830
*
@@ -806,24 +836,22 @@ export class CoreQuestionHelperProvider {
806836
let iconName: string | undefined;
807837
let color: string | undefined;
808838

839+
const correctIcon = this.getCorrectIcon(false);
840+
const partiallyCorrectIcon = this.getCorrectIcon(false);
809841
if ('src' in icon) {
810842
if ((icon as HTMLImageElement).src.indexOf('correct') >= 0) {
811-
iconName = 'check';
843+
iconName = correctIcon;
812844
color = CoreIonicColorNames.SUCCESS;
813845
} else if ((icon as HTMLImageElement).src.indexOf('incorrect') >= 0 ) {
814846
iconName = 'xmark';
815847
color = CoreIonicColorNames.DANGER;
816848
}
817849
} else {
818-
// In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
819-
if (
820-
icon.classList.contains('fa-check-square') ||
821-
(icon.classList.contains('fa-check') && icon.classList.contains('text-warning'))
822-
) {
823-
iconName = 'check';
850+
if (icon.classList.contains(`fa-${partiallyCorrectIcon}`)) {
851+
iconName = partiallyCorrectIcon;
824852
color = CoreIonicColorNames.WARNING;
825-
} else if (icon.classList.contains('fa-check-double') || icon.classList.contains('fa-check')) {
826-
iconName = 'check-double';
853+
} else if (icon.classList.contains(`fa-${correctIcon}`)) {
854+
iconName = correctIcon;
827855
color = CoreIonicColorNames.SUCCESS;
828856
} else if (icon.classList.contains('fa-xmark') || icon.classList.contains('fa-remove')) {
829857
iconName = 'xmark';

0 commit comments

Comments
 (0)