Skip to content

Commit 90a356f

Browse files
authored
Merge pull request #4177 from dpalou/MOBILE-4638
MOBILE-4638 question: Update correctness icons to match last LMS changes
2 parents 129e335 + bfa9b05 commit 90a356f

File tree

6 files changed

+101
-46
lines changed

6 files changed

+101
-46
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
{{ row.accessibilityLabel }}
2020
</label>
2121
</div>
22-
<ion-icon *ngIf="row.isCorrect === 1" class="core-correct-icon" name="fas-check" color="success" slot="start"
22+
<ion-icon *ngIf="row.isCorrect === 1" class="core-correct-icon" [name]="correctIcon" color="success" slot="start"
2323
[attr.aria-label]="'core.question.correct' | translate" />
24-
<ion-icon *ngIf="row.isCorrect === 0" class="core-correct-icon" name="fas-xmark" color="danger" slot="start"
24+
<ion-icon *ngIf="row.isCorrect === 0" class="core-correct-icon" [name]="incorrectIcon" color="danger" slot="start"
2525
[attr.aria-label]="'core.question.incorrect' | translate" />
2626
<ion-select-option *ngFor="let option of row.options" [value]="option.value">
2727
{{option.label}}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
[contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="courseId" />
2626
</div>
2727
</div>
28-
<ion-icon *ngIf="option.isCorrect === 1" class="core-correct-icon" name="fas-check" color="success"
28+
<ion-icon *ngIf="option.isCorrect === 1" class="core-correct-icon" [name]="correctIcon" color="success"
2929
[attr.aria-label]="'core.question.correct' | translate" />
30-
<ion-icon *ngIf="option.isCorrect === 0" class="core-correct-icon" name="fas-xmark" color="danger"
30+
<ion-icon *ngIf="option.isCorrect === 0" class="core-correct-icon" [name]="incorrectIcon" color="danger"
3131
[attr.aria-label]="'core.question.incorrect' | translate" />
3232
</ion-checkbox>
3333
<div *ngIf="option.feedback" class="specificfeedback">
@@ -53,9 +53,9 @@
5353
[contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="courseId" />
5454
</div>
5555
</div>
56-
<ion-icon *ngIf="option.isCorrect === 1" class="core-correct-icon" name="fas-check" color="success"
56+
<ion-icon *ngIf="option.isCorrect === 1" class="core-correct-icon" [name]="correctIcon" color="success"
5757
[attr.aria-label]="'core.question.correct' | translate" />
58-
<ion-icon *ngIf="option.isCorrect === 0" class="core-correct-icon" name="fas-xmark" color="danger"
58+
<ion-icon *ngIf="option.isCorrect === 0" class="core-correct-icon" [name]="incorrectIcon" color="danger"
5959
[attr.aria-label]="'core.question.incorrect' | translate" />
6060
</ion-radio>
6161

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@if (item.correctClass === 'correct') {
2222
<ion-icon [name]="correctIcon" slot="start" [ariaLabel]="'core.question.correct' | translate" color="success" />
2323
} @else if (item.correctClass === 'incorrect') {
24-
<ion-icon name="fas-xmark" slot="start" [ariaLabel]="'core.question.incorrect' | translate" color="danger" />
24+
<ion-icon [name]="incorrectIcon" slot="start" [ariaLabel]="'core.question.incorrect' | translate" color="danger" />
2525
} @else if (item.correctClass.startsWith('partial')) {
2626
<ion-icon [name]="partialCorrectIcon" slot="start" [ariaLabel]="'core.question.partiallycorrect' | translate"
2727
color="warning" />

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

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

42-
correctIcon = '';
43-
partialCorrectIcon = '';
44-
4542
constructor(elementRef: ElementRef) {
4643
super('AddonQtypeOrderingComponent', elementRef);
4744
}
@@ -59,9 +56,6 @@ export class AddonQtypeOrderingComponent extends CoreQuestionBaseComponent<Addon
5956
return;
6057
}
6158

62-
this.correctIcon = CoreQuestionHelper.getCorrectIcon();
63-
this.partialCorrectIcon = CoreQuestionHelper.getPartiallyCorrectIcon();
64-
6559
// Replace Moodle's feedback classes with our own.
6660
CoreQuestionHelper.replaceFeedbackClasses(questionElement);
6761

@@ -81,7 +75,8 @@ export class AddonQtypeOrderingComponent extends CoreQuestionBaseComponent<Addon
8175
// Remove correctness icons from the content.
8276
const itemContentEl = element.querySelector<HTMLElement>('[data-itemcontent]');
8377
itemContentEl?.querySelector(
84-
'.icon.fa-check, .icon.fa-remove, .icon.fa-check-square, .icon.fa-check-double, .icon.fa-xmark',
78+
'.icon.fa-check, .icon.fa-remove, .icon.fa-check-square, .icon.fa-circle-check, .icon.fa-xmark, ' +
79+
'.icon.fa-circle-xmark, .icon.fa-square-check, .icon.circle-half-stroke',
8580
)?.remove();
8681

8782
return {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export class CoreQuestionBaseComponent<T extends AddonModQuizQuestion = AddonMod
4848
@Output() buttonClicked = new EventEmitter<CoreQuestionBehaviourButton>(); // Will emit when a behaviour button is clicked.
4949
@Output() onAbort = new EventEmitter<void>(); // Should emit an event if the question should be aborted.
5050

51+
correctIcon = '';
52+
incorrectIcon = '';
53+
partialCorrectIcon = '';
54+
5155
protected logger: CoreLogger;
5256
protected hostElement: HTMLElement;
5357

@@ -60,6 +64,10 @@ export class CoreQuestionBaseComponent<T extends AddonModQuizQuestion = AddonMod
6064
* @inheritdoc
6165
*/
6266
ngOnInit(): void {
67+
this.correctIcon = CoreQuestionHelper.getCorrectIcon().fullName;
68+
this.incorrectIcon = CoreQuestionHelper.getIncorrectIcon().fullName;
69+
this.partialCorrectIcon = CoreQuestionHelper.getPartiallyCorrectIcon().fullName;
70+
6371
if (!this.question) {
6472
this.logger.warn('Aborting because of no question received.');
6573

@@ -492,17 +500,17 @@ export class CoreQuestionBaseComponent<T extends AddonModQuizQuestion = AddonMod
492500
// Check if question is marked as correct.
493501
if (input.classList.contains('incorrect')) {
494502
question.input.correctClass = 'core-question-incorrect';
495-
question.input.correctIcon = 'fas-xmark';
503+
question.input.correctIcon = this.incorrectIcon;
496504
question.input.correctIconColor = CoreIonicColorNames.DANGER;
497505
question.input.correctIconLabel = 'core.question.incorrect';
498506
} else if (input.classList.contains('correct')) {
499507
question.input.correctClass = 'core-question-correct';
500-
question.input.correctIcon = CoreQuestionHelper.getCorrectIcon();
508+
question.input.correctIcon = this.correctIcon;
501509
question.input.correctIconColor = CoreIonicColorNames.SUCCESS;
502510
question.input.correctIconLabel = 'core.question.correct';
503511
} else if (input.classList.contains('partiallycorrect')) {
504512
question.input.correctClass = 'core-question-partiallycorrect';
505-
question.input.correctIcon = CoreQuestionHelper.getPartiallyCorrectIcon();
513+
question.input.correctIcon = this.partialCorrectIcon;
506514
question.input.correctIconColor = CoreIonicColorNames.WARNING;
507515
question.input.correctIconLabel = 'core.question.partiallycorrect';
508516
} else {

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

Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -799,30 +799,71 @@ export class CoreQuestionHelperProvider {
799799
* Returns correct icon based on the LMS version.
800800
* In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
801801
*
802-
* @param withPrefix Whether to include the prefix in the icon name.
803-
* @returns Icon name.
802+
* @returns Icon data.
804803
*/
805-
getCorrectIcon(withPrefix = true): string {
806-
const icon = CoreSites.getRequiredCurrentSite().isVersionGreaterEqualThan('4.5')
807-
? 'check-double'
808-
: 'check';
804+
getCorrectIcon(): IconData {
805+
if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.5')) {
806+
return {
807+
name: 'circle-check',
808+
prefix: 'far',
809+
library: 'regular',
810+
fullName: 'far-circle-check',
811+
};
812+
} else {
813+
return {
814+
name: 'check',
815+
prefix: 'fas',
816+
library: 'solid',
817+
fullName: 'fas-check',
818+
};
819+
}
820+
}
809821

810-
return withPrefix ? `fas-${icon}` : icon;
822+
/**
823+
* Returns incorrect correct icon based on the LMS version.
824+
*
825+
* @returns Icon data.
826+
*/
827+
getIncorrectIcon(): IconData {
828+
if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.5')) {
829+
return {
830+
name: 'circle-xmark',
831+
prefix: 'far',
832+
library: 'regular',
833+
fullName: 'far-circle-xmark',
834+
};
835+
} else {
836+
return {
837+
name: 'xmark',
838+
prefix: 'fas',
839+
library: 'solid',
840+
fullName: 'fas-xmark',
841+
};
842+
}
811843
}
812844

813845
/**
814846
* Returns partially correct icon based on the LMS version.
815847
* In LMS 4.4 and older, fa-check means correct. In 4.5+, fa-check means partially correct.
816848
*
817-
* @param withPrefix Whether to include the prefix in the icon name.
818-
* @returns Icon name.
849+
* @returns Icon data.
819850
*/
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;
851+
getPartiallyCorrectIcon(): IconData {
852+
if (CoreSites.getCurrentSite()?.isVersionGreaterEqualThan('4.5')) {
853+
return {
854+
name: 'circle-half-stroke',
855+
prefix: 'fas',
856+
library: 'solid',
857+
fullName: 'fas-circle-half-stroke',
858+
};
859+
} else {
860+
return {
861+
name: 'square-check',
862+
prefix: 'fas',
863+
library: 'solid',
864+
fullName: 'fas-square-check',
865+
};
866+
}
826867
}
827868

828869
/**
@@ -833,41 +874,42 @@ export class CoreQuestionHelperProvider {
833874
treatCorrectnessIcons(element: HTMLElement): void {
834875
const icons = <HTMLElement[]> Array.from(element.querySelectorAll('img.icon, img.questioncorrectnessicon, i.icon'));
835876
icons.forEach((icon) => {
836-
let iconName: string | undefined;
877+
let iconData: IconData | undefined;
837878
let color: string | undefined;
838879

839-
const correctIcon = this.getCorrectIcon(false);
840-
const partiallyCorrectIcon = this.getCorrectIcon(false);
880+
const correctIcon = this.getCorrectIcon();
881+
const incorrectIcon = this.getIncorrectIcon();
882+
const partiallyCorrectIcon = this.getPartiallyCorrectIcon();
841883
if ('src' in icon) {
842884
if ((icon as HTMLImageElement).src.indexOf('correct') >= 0) {
843-
iconName = correctIcon;
885+
iconData = correctIcon;
844886
color = CoreIonicColorNames.SUCCESS;
845887
} else if ((icon as HTMLImageElement).src.indexOf('incorrect') >= 0 ) {
846-
iconName = 'xmark';
888+
iconData = incorrectIcon;
847889
color = CoreIonicColorNames.DANGER;
848890
}
849891
} else {
850-
if (icon.classList.contains(`fa-${partiallyCorrectIcon}`)) {
851-
iconName = partiallyCorrectIcon;
892+
if (icon.classList.contains(`fa-${partiallyCorrectIcon.name}`)) {
893+
iconData = partiallyCorrectIcon;
852894
color = CoreIonicColorNames.WARNING;
853-
} else if (icon.classList.contains(`fa-${correctIcon}`)) {
854-
iconName = correctIcon;
895+
} else if (icon.classList.contains(`fa-${correctIcon.name}`)) {
896+
iconData = correctIcon;
855897
color = CoreIonicColorNames.SUCCESS;
856-
} else if (icon.classList.contains('fa-xmark') || icon.classList.contains('fa-remove')) {
857-
iconName = 'xmark';
898+
} else if (icon.classList.contains(`fa-${incorrectIcon.name}`) || icon.classList.contains('fa-remove')) {
899+
iconData = incorrectIcon;
858900
color = CoreIonicColorNames.DANGER;
859901
}
860902
}
861903

862-
if (!iconName) {
904+
if (!iconData) {
863905
return;
864906
}
865907

866908
// Replace the icon with the font version.
867909
const newIcon: HTMLIonIconElement = document.createElement('ion-icon');
868910

869-
newIcon.setAttribute('name', `fas-${iconName}`);
870-
newIcon.setAttribute('src', CoreIcons.getIconSrc('font-awesome', 'solid', iconName));
911+
newIcon.setAttribute('name', iconData.fullName);
912+
newIcon.setAttribute('src', CoreIcons.getIconSrc('font-awesome', iconData.library, iconData.name));
871913
newIcon.className = `core-correct-icon ion-color ion-color-${color} questioncorrectnessicon`;
872914
newIcon.title = icon.title;
873915
newIcon.setAttribute('aria-label', icon.title);
@@ -997,3 +1039,13 @@ export type CoreQuestionBehaviourButton = {
9971039
export type CoreQuestionBehaviourCertaintyOption = CoreQuestionBehaviourButton & {
9981040
text: string;
9991041
};
1042+
1043+
/**
1044+
* Data about a font-awesome icon.
1045+
*/
1046+
type IconData = {
1047+
name: string;
1048+
prefix: string;
1049+
library: string;
1050+
fullName: string;
1051+
};

0 commit comments

Comments
 (0)