|
| 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