From c92fbe380fb8d2ca9ce1d63573306d10ae1ae49f Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Thu, 8 Jun 2023 14:39:04 +0200 Subject: [PATCH] MOBILE-4318 reportbuilder: Create report builder link handler --- .../reportbuilder/reportbuilder.module.ts | 3 ++ .../services/handlers/reportbuilder-link.ts | 54 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts diff --git a/src/core/features/reportbuilder/reportbuilder.module.ts b/src/core/features/reportbuilder/reportbuilder.module.ts index a905a6ced..c985b7605 100644 --- a/src/core/features/reportbuilder/reportbuilder.module.ts +++ b/src/core/features/reportbuilder/reportbuilder.module.ts @@ -14,9 +14,11 @@ import { APP_INITIALIZER, NgModule } from '@angular/core'; import { Routes } from '@angular/router'; +import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; import { CoreMainMenuRoutingModule } from '@features/mainmenu/mainmenu-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreUserDelegate } from '@features/user/services/user-delegate'; +import { CoreReportBuilderLinkHandler } from './services/handlers/reportbuilder-link'; import { CoreReportBuilderHandler, CoreReportBuilderHandlerService } from './services/handlers/reportbuilder'; const routes: Routes = [ @@ -37,6 +39,7 @@ const routes: Routes = [ multi: true, useValue: () => { CoreUserDelegate.registerHandler(CoreReportBuilderHandler.instance); + CoreContentLinksDelegate.registerHandler(CoreReportBuilderLinkHandler.instance); }, }, ], diff --git a/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts b/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts new file mode 100644 index 000000000..3d24974ba --- /dev/null +++ b/src/core/features/reportbuilder/services/handlers/reportbuilder-link.ts @@ -0,0 +1,54 @@ +// (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 { Params } from '@angular/router'; +import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler'; +import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreNavigator } from '@services/navigator'; +import { makeSingleton } from '@singletons'; +import { CoreReportBuilder } from '../reportbuilder'; +import { CoreReportBuilderHandlerService } from './reportbuilder'; + +/** + * Content links handler for report builder + * Match reportbuilder/view.php?id=6 with a valid data and report id. + */ +@Injectable({ providedIn: 'root' }) +export class CoreReportBuilderLinkHandlerService extends CoreContentLinksHandlerBase { + + name = 'CoreReportBuilderLinkHandler'; + pattern = /\/reportbuilder\/view\.php.*([?&]id=\d+)/; + + /** + * @inheritdoc + */ + getActions(siteIds: string[], url: string, params: Params): CoreContentLinksAction[] { + return [{ + action: async (siteId): Promise => { + CoreNavigator.navigateToSitePath(`${CoreReportBuilderHandlerService.PAGE_NAME}/${params.id || ''}`, { siteId }); + }, + }]; + } + + /** + * @inheritdoc + */ + async isEnabled(): Promise { + return await CoreReportBuilder.isEnabled(); + } + +} + +export const CoreReportBuilderLinkHandler = makeSingleton(CoreReportBuilderLinkHandlerService);