Skip to content

Commit 1ef4aa6

Browse files
authored
Merge pull request #4181 from albertgasset/MOBILE-4639
MOBILE-4639 badges: Support links to badges/badgeclass.php?id=X
2 parents 404cbf7 + 5c6744a commit 1ef4aa6

File tree

9 files changed

+404
-32
lines changed

9 files changed

+404
-32
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { NgModule } from '@angular/core';
16+
import { RouterModule, Routes } from '@angular/router';
17+
import { AddonBadgesBadgeClassPage } from './pages/badge-class/badge-class';
18+
import { CoreSharedModule } from '@/core/shared.module';
19+
20+
const routes: Routes = [
21+
{
22+
path: ':badgeId',
23+
component: AddonBadgesBadgeClassPage,
24+
},
25+
];
26+
27+
@NgModule({
28+
imports: [
29+
RouterModule.forChild(routes),
30+
CoreSharedModule,
31+
],
32+
declarations: [
33+
AddonBadgesBadgeClassPage,
34+
],
35+
})
36+
export class AddonBadgeClassLazyModule {}

src/addons/badges/badges.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Routes } from '@angular/router';
1717

1818
import { AddonBadgesMyBadgesLinkHandler } from './services/handlers/mybadges-link';
1919
import { AddonBadgesBadgeLinkHandler } from './services/handlers/badge-link';
20+
import { AddonBadgesBadgeClassLinkHandler } from './services/handlers/badgeclass-link';
2021
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
2122
import { CoreUserDelegate } from '@features/user/services/user-delegate';
2223
import { AddonBadgesUserHandler } from './services/handlers/user';
@@ -48,6 +49,10 @@ const mainMenuRoutes: Routes = [
4849
path: 'badges',
4950
loadChildren: () => import('./badges-lazy.module').then(m => m.AddonBadgesLazyModule),
5051
},
52+
{
53+
path: 'badgeclass',
54+
loadChildren: () => import('./badgeclass-lazy.module').then(m => m.AddonBadgeClassLazyModule),
55+
},
5156
];
5257

5358
@NgModule({
@@ -61,6 +66,7 @@ const mainMenuRoutes: Routes = [
6166
useValue: () => {
6267
CoreContentLinksDelegate.registerHandler(AddonBadgesMyBadgesLinkHandler.instance);
6368
CoreContentLinksDelegate.registerHandler(AddonBadgesBadgeLinkHandler.instance);
69+
CoreContentLinksDelegate.registerHandler(AddonBadgesBadgeClassLinkHandler.instance);
6470
CoreUserDelegate.registerHandler(AddonBadgesUserHandler.instance);
6571
CorePushNotificationsDelegate.registerClickHandler(AddonBadgesPushClickHandler.instance);
6672
CoreTagAreaDelegate.registerHandler(AddonBadgesTagAreaHandler.instance);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<ion-header>
2+
<ion-toolbar>
3+
<ion-buttons slot="start">
4+
<ion-back-button [text]="'core.back' | translate" />
5+
</ion-buttons>
6+
<ion-title>
7+
<h1 *ngIf="badge">{{ badge.name }}</h1>
8+
<h1 *ngIf="!badge">{{ 'addon.badges.badgedetails' | translate }}</h1>
9+
</ion-title>
10+
</ion-toolbar>
11+
</ion-header>
12+
<ion-content class="limited-width">
13+
<ion-refresher slot="fixed" [disabled]="!badgeLoaded" (ionRefresh)="refreshBadgeClass($event.target)">
14+
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}" />
15+
</ion-refresher>
16+
<core-loading [hideUntil]="badgeLoaded">
17+
<ng-container *ngIf="badge">
18+
<ion-item-group>
19+
<ion-item class="ion-text-wrap ion-text-center">
20+
<ion-label>
21+
<img *ngIf="badge.image" class="large-avatar" [url]="badge.image" core-external-content [alt]="badge.name" />
22+
</ion-label>
23+
</ion-item>
24+
<ion-item class="ion-text-wrap" *ngIf="badge.name">
25+
<ion-label>
26+
<p class="item-heading">{{ 'core.name' | translate}}</p>
27+
<p>{{ badge.name }}</p>
28+
</ion-label>
29+
</ion-item>
30+
<ion-item class="ion-text-wrap" *ngIf="badge.issuer">
31+
<ion-label>
32+
<p class="item-heading">{{ 'addon.badges.issuername' | translate}}</p>
33+
<p>{{ badge.issuer }}</p>
34+
</ion-label>
35+
</ion-item>
36+
<ion-item class="ion-text-wrap" *ngIf="badge.coursefullname">
37+
<ion-label>
38+
<p class="item-heading">{{ 'core.course' | translate}}</p>
39+
<p>
40+
<core-format-text [text]="badge.coursefullname" contextLevel="course" [contextInstanceId]="badge.courseid" />
41+
</p>
42+
</ion-label>
43+
</ion-item>
44+
<ion-item class="ion-text-wrap" *ngIf="badge.description">
45+
<ion-label>
46+
<p class="item-heading">{{ 'core.description' | translate}}</p>
47+
<p>{{ badge.description }}</p>
48+
</ion-label>
49+
</ion-item>
50+
</ion-item-group>
51+
52+
<!-- Competencies alignment -->
53+
<ion-item-group *ngIf="badge.alignment?.length">
54+
<ion-item-divider>
55+
<ion-label>
56+
<h2>{{ 'addon.badges.alignment' | translate}}</h2>
57+
</ion-label>
58+
</ion-item-divider>
59+
<ion-item class="ion-text-wrap" *ngFor="let alignment of badge.alignment" [href]="alignment.targetUrl" core-link
60+
[autoLogin]="false">
61+
<ion-label>
62+
<p class="item-heading">{{ alignment.targetName }}</p>
63+
</ion-label>
64+
</ion-item>
65+
</ion-item-group>
66+
</ng-container>
67+
</core-loading>
68+
</ion-content>
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// (C) Copyright 2015 Moodle Pty Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import { Component, OnInit } from '@angular/core';
16+
import { CoreDomUtils } from '@services/utils/dom';
17+
import { CoreUtils } from '@services/utils/utils';
18+
import { CoreNavigator } from '@services/navigator';
19+
import { ActivatedRoute } from '@angular/router';
20+
import { CoreAnalytics, CoreAnalyticsEventType } from '@services/analytics';
21+
import { CoreTime } from '@singletons/time';
22+
import { AddonBadges, AddonBadgesBadgeClass } from '../../services/badges';
23+
24+
/**
25+
* Page that displays a badge class.
26+
*/
27+
@Component({
28+
selector: 'page-addon-badges-badge-class',
29+
templateUrl: 'badge-class.html',
30+
})
31+
export class AddonBadgesBadgeClassPage implements OnInit {
32+
33+
protected badgeId = 0;
34+
protected logView: (badge: AddonBadgesBadgeClass) => void;
35+
36+
badge?: AddonBadgesBadgeClass;
37+
badgeLoaded = false;
38+
currentTime = 0;
39+
40+
constructor(protected route: ActivatedRoute) {
41+
this.badgeId = CoreNavigator.getRequiredRouteNumberParam('badgeId');
42+
43+
this.logView = CoreTime.once((badge) => {
44+
CoreAnalytics.logEvent({
45+
type: CoreAnalyticsEventType.VIEW_ITEM,
46+
ws: 'core_badges_get_badge',
47+
name: badge.name,
48+
data: { id: this.badgeId, category: 'badges' },
49+
url: `/badges/badgeclass.php?id=${this.badgeId}`,
50+
});
51+
});
52+
}
53+
54+
/**
55+
* View loaded.
56+
*/
57+
ngOnInit(): void {
58+
this.fetchBadgeClass().finally(() => {
59+
this.badgeLoaded = true;
60+
});
61+
}
62+
63+
/**
64+
* Fetch the badge class required for the view.
65+
*
66+
* @returns Promise resolved when done.
67+
*/
68+
async fetchBadgeClass(): Promise<void> {
69+
try {
70+
this.badge = await AddonBadges.getBadgeClass(this.badgeId);
71+
72+
this.logView(this.badge);
73+
} catch (message) {
74+
CoreDomUtils.showErrorModalDefault(message, 'Error getting badge data.');
75+
}
76+
}
77+
78+
/**
79+
* Refresh the badge class.
80+
*
81+
* @param refresher Refresher.
82+
*/
83+
async refreshBadgeClass(refresher?: HTMLIonRefresherElement): Promise<void> {
84+
await CoreUtils.ignoreErrors(AddonBadges.invalidateBadgeClass(this.badgeId));
85+
86+
await this.fetchBadgeClass();
87+
88+
refresher?.complete();
89+
}
90+
91+
}

src/addons/badges/pages/issued-badge/issued-badge.html

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ <h2>{{ 'addon.badges.badgedetails' | translate}}</h2>
111111
<p>{{ badge.imagecaption }}</p>
112112
</ion-label>
113113
</ion-item>
114-
<ion-item class="ion-text-wrap" *ngIf="course">
114+
<ion-item class="ion-text-wrap" *ngIf="badge.coursefullname">
115115
<ion-label>
116116
<p class="item-heading">{{ 'core.course' | translate}}</p>
117117
<p>
118-
<core-format-text [text]="course.fullname" contextLevel="course" [contextInstanceId]="courseId" />
118+
<core-format-text [text]="badge.coursefullname" contextLevel="course" [contextInstanceId]="badge.courseid" />
119119
</p>
120120
</ion-label>
121121
</ion-item>
@@ -217,21 +217,16 @@ <h2>{{ 'addon.badges.relatedbages' | translate}}</h2>
217217
</ion-item-group>
218218

219219
<!-- Competencies alignment -->
220-
<ion-item-group *ngIf="badge.alignment">
220+
<ion-item-group *ngIf="badge.alignment?.length">
221221
<ion-item-divider>
222222
<ion-label>
223223
<h2>{{ 'addon.badges.alignment' | translate}}</h2>
224224
</ion-label>
225225
</ion-item-divider>
226-
<ion-item class="ion-text-wrap" *ngFor="let alignment of badge.alignment" [href]="alignment.targeturl" core-link
226+
<ion-item class="ion-text-wrap" *ngFor="let alignment of badge.alignment" [href]="alignment.targetUrl" core-link
227227
[autoLogin]="false">
228228
<ion-label>
229-
<p class="item-heading">{{ alignment.targetname }}</p>
230-
</ion-label>
231-
</ion-item>
232-
<ion-item class="ion-text-wrap" *ngIf="badge.alignment.length === 0">
233-
<ion-label>
234-
<p class="item-heading">{{ 'addon.badges.noalignment' | translate}}</p>
229+
<p class="item-heading">{{ alignment.targetName }}</p>
235230
</ion-label>
236231
</ion-item>
237232
</ion-item-group>

src/addons/badges/pages/issued-badge/issued-badge.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CoreSites } from '@services/sites';
1919
import { CoreUser } from '@features/user/services/user';
2020
import { AddonBadges, AddonBadgesUserBadge } from '../../services/badges';
2121
import { CoreUtils } from '@services/utils/utils';
22-
import { CoreCourses, CoreEnrolledCourseData } from '@features/courses/services/courses';
22+
import { CoreCourses } from '@features/courses/services/courses';
2323
import { CoreNavigator } from '@services/navigator';
2424
import { ActivatedRoute } from '@angular/router';
2525
import { CoreSwipeNavigationItemsManager } from '@classes/items-management/swipe-navigation-items-manager';
@@ -30,7 +30,7 @@ import { CoreTime } from '@singletons/time';
3030
import { CoreSharedModule } from '@/core/shared.module';
3131

3232
/**
33-
* Page that displays the list of calendar events.
33+
* Page that displays an issued badge.
3434
*/
3535
@Component({
3636
selector: 'page-addon-badges-issued-badge',
@@ -47,7 +47,6 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy {
4747
protected logView: (badge: AddonBadgesUserBadge) => void;
4848

4949
courseId = 0;
50-
course?: CoreEnrolledCourseData;
5150
badge?: AddonBadgesUserBadge;
5251
badges?: CoreSwipeNavigationItemsManager;
5352
badgeLoaded = false;
@@ -128,16 +127,18 @@ export class AddonBadgesIssuedBadgePage implements OnInit, OnDestroy {
128127
}
129128
}
130129

131-
this.badge = badge;
132-
if (badge.courseid) {
130+
// Try to get course full name if not returned by the WS.
131+
if (badge.courseid && !badge.coursefullname) {
133132
try {
134-
this.course = await CoreCourses.getUserCourse(badge.courseid, true);
133+
const course = await CoreCourses.getUserCourse(badge.courseid, true);
134+
badge.coursefullname = course.fullname;
135135
} catch {
136-
// Maybe an old deleted course.
137-
this.course = undefined;
136+
// User is not enrolled in the course.
138137
}
139138
}
140139

140+
this.badge = badge;
141+
141142
this.logView(badge);
142143
} catch (message) {
143144
CoreDomUtils.showErrorModalDefault(message, 'Error getting badge data.');

0 commit comments

Comments
 (0)