Skip to content

Commit d8baa1d

Browse files
MOBILE-4362 my-courses-link: Create my courses link handler
1 parent 5287ada commit d8baa1d

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/core/features/courses/courses.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
CoreCoursesMyCoursesMainMenuHandlerService,
4141
} from './services/handlers/my-courses-mainmenu';
4242
import { CoreCoursesRequestPushClickHandler } from './services/handlers/request-push-click';
43+
import { CoreCoursesMyCoursesLinkHandler } from './services/handlers/my-courses-link';
4344

4445
export const CORE_COURSES_SERVICES: Type<unknown>[] = [
4546
CoreCoursesProvider,
@@ -79,6 +80,7 @@ const routes: Routes = [
7980
CoreMainMenuDelegate.registerHandler(CoreCoursesMyCoursesHomeHandler.instance);
8081
CoreContentLinksDelegate.registerHandler(CoreCoursesCourseLinkHandler.instance);
8182
CoreContentLinksDelegate.registerHandler(CoreCoursesIndexLinkHandler.instance);
83+
CoreContentLinksDelegate.registerHandler(CoreCoursesMyCoursesLinkHandler.instance);
8284
CoreContentLinksDelegate.registerHandler(CoreCoursesDashboardLinkHandler.instance);
8385
CorePushNotificationsDelegate.registerClickHandler(CoreCoursesEnrolPushClickHandler.instance);
8486
CorePushNotificationsDelegate.registerClickHandler(CoreCoursesRequestPushClickHandler.instance);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
17+
import { makeSingleton } from '@singletons';
18+
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
19+
import { Params } from '@angular/router';
20+
import { CoreNavigator } from '@services/navigator';
21+
/**
22+
* Handler to treat links to my courses page.
23+
*/
24+
@Injectable({ providedIn: 'root' })
25+
export class CoreCoursesMyCoursesLinkHandlerService extends CoreContentLinksHandlerBase {
26+
27+
name = 'CoreCoursesMyCoursesLinkHandler';
28+
pattern = /\/my\/courses\.php/;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
getActions(
34+
siteIds: string[],
35+
url: string,
36+
params: Record<string, string>,
37+
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
38+
return [{
39+
action: (): void => {
40+
this.actionOpen({
41+
sort: params.sort || undefined,
42+
filter: params.filter || undefined,
43+
search: params.search || undefined,
44+
layout: params.layout || undefined,
45+
});
46+
},
47+
}];
48+
}
49+
50+
/**
51+
* Open my courses.
52+
*
53+
* @param params Params to send to the new page.
54+
*/
55+
protected actionOpen(params: Params): void {
56+
CoreNavigator.navigate('/main/courses/my', { params });
57+
}
58+
59+
}
60+
61+
export const CoreCoursesMyCoursesLinkHandler = makeSingleton(CoreCoursesMyCoursesLinkHandlerService);

0 commit comments

Comments
 (0)