Skip to content

Commit

Permalink
MOBILE-4362 my-courses-link: Create my courses link handler
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonso-salces committed Nov 8, 2023
1 parent 5287ada commit d8baa1d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/features/courses/courses.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>[] = [
CoreCoursesProvider,
Expand Down Expand Up @@ -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);
Expand Down
61 changes: 61 additions & 0 deletions src/core/features/courses/services/handlers/my-courses-link.ts
Original file line number Diff line number Diff line change
@@ -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<string, string>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
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);

0 comments on commit d8baa1d

Please sign in to comment.