diff --git a/src/core/features/courses/courses.module.ts b/src/core/features/courses/courses.module.ts index 51503f2db..425f959ef 100644 --- a/src/core/features/courses/courses.module.ts +++ b/src/core/features/courses/courses.module.ts @@ -40,6 +40,7 @@ import { CoreCoursesMyCoursesMainMenuHandlerService, } from './services/handlers/my-courses-mainmenu'; import { CoreCoursesRequestPushClickHandler } from './services/handlers/request-push-click'; +import { CoreCoursesMyCoursesLinkHandler } from './services/handlers/my-courses-link'; export const CORE_COURSES_SERVICES: Type[] = [ CoreCoursesProvider, @@ -79,6 +80,7 @@ const routes: Routes = [ CoreMainMenuDelegate.registerHandler(CoreCoursesMyCoursesHomeHandler.instance); CoreContentLinksDelegate.registerHandler(CoreCoursesCourseLinkHandler.instance); CoreContentLinksDelegate.registerHandler(CoreCoursesIndexLinkHandler.instance); + CoreContentLinksDelegate.registerHandler(CoreCoursesMyCoursesLinkHandler.instance); CoreContentLinksDelegate.registerHandler(CoreCoursesDashboardLinkHandler.instance); CorePushNotificationsDelegate.registerClickHandler(CoreCoursesEnrolPushClickHandler.instance); CorePushNotificationsDelegate.registerClickHandler(CoreCoursesRequestPushClickHandler.instance); diff --git a/src/core/features/courses/services/handlers/my-courses-link.ts b/src/core/features/courses/services/handlers/my-courses-link.ts new file mode 100644 index 000000000..23b26f353 --- /dev/null +++ b/src/core/features/courses/services/handlers/my-courses-link.ts @@ -0,0 +1,61 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Injectable } from '@angular/core'; +import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; +import { makeSingleton } from '@singletons'; +import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; +import { Params } from '@angular/router'; +import { CoreNavigator } from '@services/navigator'; +/** + * Handler to treat links to my courses page. + */ +@Injectable({ providedIn: 'root' }) +export class CoreCoursesMyCoursesLinkHandlerService extends CoreContentLinksHandlerBase { + + name = 'CoreCoursesMyCoursesLinkHandler'; + pattern = /\/my\/courses\.php/; + + /** + * @inheritdoc + */ + getActions( + siteIds: string[], + url: string, + params: Record, + ): CoreContentLinksAction[] | Promise { + return [{ + action: (): void => { + this.actionOpen({ + sort: params.sort || undefined, + filter: params.filter || undefined, + search: params.search || undefined, + layout: params.layout || undefined, + }); + }, + }]; + } + + /** + * Open my courses. + * + * @param params Params to send to the new page. + */ + protected actionOpen(params: Params): void { + CoreNavigator.navigate('/main/courses/my', { params }); + } + +} + +export const CoreCoursesMyCoursesLinkHandler = makeSingleton(CoreCoursesMyCoursesLinkHandlerService);