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> <p>{{ badge.imagecaption }}</p>
</ion-label> </ion-label>
</ion-item> </ion-item>
<ion-item class="ion-text-wrap" *ngIf="course"> <ion-item class="ion-text-wrap" *ngIf="badge.coursefullname">
<ion-label> <ion-label>
<p class="item-heading">{{ 'core.course' | translate}}</p> <p class="item-heading">{{ 'core.course' | translate}}</p>
<p> <p>
<core-format-text [text]="course.fullname" contextLevel="course" [contextInstanceId]="courseId" /> <core-format-text [text]="badge.coursefullname" contextLevel="course" [contextInstanceId]="badge.courseid" />
</p> </p>
</ion-label> </ion-label>
</ion-item> </ion-item>

View File

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

View File

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