MOBILE-4639 badges: Use ccourse full name returned by WS

main
Albert Gasset 2024-09-17 16:23:15 +02:00
parent 24fddd8f7e
commit 38ae12fe35
3 changed files with 12 additions and 10 deletions

View File

@ -111,11 +111,11 @@
<p>{{ badge.imagecaption }}</p>
</ion-label>
</ion-item>
<ion-item class="ion-text-wrap" *ngIf="course">
<ion-item class="ion-text-wrap" *ngIf="badge.coursefullname">
<ion-label>
<p class="item-heading">{{ 'core.course' | translate}}</p>
<p>
<core-format-text [text]="course.fullname" contextLevel="course" [contextInstanceId]="courseId" />
<core-format-text [text]="badge.coursefullname" contextLevel="course" [contextInstanceId]="badge.courseid" />
</p>
</ion-label>
</ion-item>

View File

@ -19,7 +19,7 @@ import { CoreSites } from '@services/sites';
import { CoreUser } from '@features/user/services/user';
import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
import { CoreUtils } from '@services/utils/utils';
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
import { CoreCourses } from '@features/courses/services/courses';
import { CoreNavigator } from '@services/navigator';
import { ActivatedRoute } from '@angular/router';
import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager';
@ -30,7 +30,7 @@ import { CoreTime } from '@singletons/time';
import { CoreSharedModule } from '@/core/shared.module';
/**
* Page that displays the list of calendar events.
* Page that displays an issued badge.
*/
@Component({
selector: 'page-addon-badges-issued-badge',
@ -47,7 +47,6 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy {
protected logView: (badge: AddonBadgesUserBadge) => void;
courseId = 0;
course?: CoreEnrolledCourseData;
badge?: AddonBadgesUserBadge;
badges?: CoreSwipeNavigationItemsManager;
badgeLoaded = false;
@ -128,16 +127,18 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy {
}
}
this.badge = badge;
if (badge.courseid) {
// Try to get course full name if not returned by the WS.
if (badge.courseid && !badge.coursefullname) {
try {
this.course = await CoreCourses.getUserCourse(badge.courseid, true);
const course = await CoreCourses.getUserCourse(badge.courseid, true);
badge.coursefullname = course.fullname;
} catch {
// Maybe an old deleted course.
this.course = undefined;
// User is not enrolled in the course.
}
}
this.badge = badge;
this.logView(badge);
} catch (message) {
CoreDomUtils.showErrorModalDefault(message, 'Error getting badge data.');

View File

@ -215,6 +215,7 @@ export type AddonBadgesUserBadge = {
expireperiod?: number; // Expire period.
type?: number; // Type.
courseid?: number; // Course id.
coursefullname?: string; // Full name of the course.
message?: string; // Message.
messagesubject?: string; // Message subject.
attachment?: number; // Attachment.