Skip to content

Commit 70bc0db

Browse files
committed
MOBILE-4860 users: Handle participants link
1 parent b443bda commit 70bc0db

File tree

5 files changed

+99
-37
lines changed

5 files changed

+99
-37
lines changed

src/core/features/user/pages/participants/participants.html

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,49 @@
1515
[attr.role]="searchQuery ? 'alert' : null" />
1616
} @else if (!participants.empty) {
1717
<ion-list>
18-
<ion-item *ngFor="let participant of participants.items" class="ion-text-wrap"
19-
[attr.aria-current]="participants.getItemAriaCurrent(participant)" [attr.aria-label]="participant.fullname"
20-
(click)="participants.select(participant)" button [detail]="true">
18+
@for (participant of participants.items; track participant.id) {
19+
<ion-item class="ion-text-wrap"
20+
[attr.aria-current]="participants.getItemAriaCurrent(participant)" [attr.aria-label]="participant.fullname"
21+
(click)="participants.select(participant)" button [detail]="true">
2122

22-
<core-user-avatar [user]="participant" [linkProfile]="false" [checkOnline]="true" slot="start" />
23+
<core-user-avatar [user]="participant" [linkProfile]="false" [checkOnline]="true" slot="start" />
2324

24-
<ion-label>
25-
@if (!searchQuery) {
25+
<ion-label>
26+
@if (!searchQuery) {
2627

27-
<p class="item-heading">{{ participant.fullname }}</p>
28-
@if (participant.lastcourseaccess !== undefined) {
29-
<p>
30-
<strong>{{ 'core.user.lastcourseaccess' | translate }}: </strong>
31-
@if (participant.lastcourseaccess) {
32-
{{ participant.lastcourseaccess | coreTimeAgo }}
28+
<p class="item-heading">{{ participant.fullname }}</p>
29+
@if ('lastcourseaccess' in participant && participant.lastcourseaccess !== undefined) {
30+
<p>
31+
<strong>{{ 'core.user.lastcourseaccess' | translate }}: </strong>
32+
@if (participant.lastcourseaccess) {
33+
{{ participant.lastcourseaccess | coreTimeAgo }}
3334

34-
}
35-
@if (!participant.lastcourseaccess) {
36-
{{ 'core.never' | translate }}
37-
}
38-
</p>
39-
} @else if (participant.lastaccess !== undefined) {
40-
<p>
41-
<strong>{{ 'core.lastaccess' | translate }}: </strong>
42-
@if (participant.lastaccess) {
43-
{{ participant.lastaccess | coreTimeAgo }}
44-
}
45-
@if (!participant.lastaccess) {
46-
{{ 'core.never' | translate }}
47-
}
35+
}
36+
@if (!participant.lastcourseaccess) {
37+
{{ 'core.never' | translate }}
38+
}
39+
</p>
40+
} @else if (participant.lastaccess !== undefined) {
41+
<p>
42+
<strong>{{ 'core.lastaccess' | translate }}: </strong>
43+
@if (participant.lastaccess) {
44+
{{ participant.lastaccess | coreTimeAgo }}
45+
}
46+
@if (!participant.lastaccess) {
47+
{{ 'core.never' | translate }}
48+
}
49+
</p>
50+
}
51+
52+
} @else {
53+
<p class="item-heading">
54+
<core-format-text [text]="participant.fullname" [highlight]="searchQuery" [filter]="false" />
4855
</p>
4956
}
57+
</ion-label>
5058

51-
} @else {
52-
<p class="item-heading">
53-
<core-format-text [text]="participant.fullname" [highlight]="searchQuery" [filter]="false" />
54-
</p>
55-
}
56-
</ion-label>
57-
58-
</ion-item>
59+
</ion-item>
60+
}
5961
</ion-list>
6062
}
6163
<core-infinite-loading [enabled]="participants.loaded && !participants.completed" (action)="fetchMoreParticipants($event)"

src/core/features/user/pages/participants/participants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default class CoreUserParticipantsPage implements OnInit, AfterViewInit,
6969
* @inheritdoc
7070
*/
7171
async ngOnInit(): Promise<void> {
72-
this.searchEnabled = await CoreUser.canSearchParticipantsInSite();
72+
this.searchEnabled = CoreUser.canSearchParticipantsInSite();
7373
}
7474

7575
/**

src/core/features/user/services/handlers/course-option.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export class CoreUserCourseOptionHandlerService implements CoreCourseOptionsHand
4848
/**
4949
* @inheritdoc
5050
*/
51-
isEnabled(): Promise<boolean> {
52-
return Promise.resolve(true);
51+
async isEnabled(): Promise<boolean> {
52+
return true;
5353
}
5454

5555
/**
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 { Injectable } from '@angular/core';
16+
17+
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
18+
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
19+
import { CoreCourseHelper } from '@features/course/services/course-helper';
20+
import { makeSingleton } from '@singletons';
21+
22+
/**
23+
* Handler to treat links to course participants.
24+
*/
25+
@Injectable({ providedIn: 'root' })
26+
export class CoreUserParticipantsLinkHandlerService extends CoreContentLinksHandlerBase {
27+
28+
name = 'CoreUserParticipantsLinkHandler';
29+
pattern = /\/user\/index\.php.*([?&]id=)/;
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
getActions(
35+
siteIds: string[],
36+
url: string,
37+
params: Record<string, string>,
38+
courseId?: number,
39+
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
40+
const courseIdentifier = courseId || Number(params.id);
41+
42+
return [{
43+
action: async (siteId): Promise<void> => {
44+
await CoreCourseHelper.getAndOpenCourse(courseIdentifier, { selectedTab: 'CoreUserParticipants' }, siteId);
45+
},
46+
}];
47+
}
48+
49+
/**
50+
* @inheritdoc
51+
*/
52+
async isEnabled(): Promise<boolean> {
53+
return true;
54+
}
55+
56+
}
57+
58+
export const CoreUserParticipantsLinkHandler = makeSingleton(CoreUserParticipantsLinkHandlerService);

src/core/features/user/user.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { CoreScreen } from '@services/screen';
3535
import { CoreEvents } from '@singletons/events';
3636
import { CORE_COURSE_PAGE_NAME, CORE_COURSE_INDEX_PATH } from '@features/course/constants';
3737
import { PARTICIPANTS_PAGE_NAME } from './constants';
38+
import { CoreUserParticipantsLinkHandler } from './services/handlers/participants-link';
3839

3940
/**
4041
* Get user services.
@@ -141,6 +142,7 @@ const courseIndexRoutes: Routes = [
141142
provideAppInitializer(() => {
142143
CoreUserDelegate.registerHandler(CoreUserProfileMailHandler.instance);
143144
CoreContentLinksDelegate.registerHandler(CoreUserProfileLinkHandler.instance);
145+
CoreContentLinksDelegate.registerHandler(CoreUserParticipantsLinkHandler.instance);
144146
CoreCronDelegate.register(CoreUserSyncCronHandler.instance);
145147
CoreTagAreaDelegate.registerHandler(CoreUserTagAreaHandler.instance);
146148
CoreCourseOptionsDelegate.registerHandler(CoreUserCourseOptionHandler.instance);

0 commit comments

Comments
 (0)