From ce602321ff2be8c1062a4328b6def688e465e51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 29 Nov 2019 11:39:36 +0100 Subject: [PATCH] MOBILE-3218 links: Adapt links to new handler functions --- src/addon/mod/book/providers/link-handler.ts | 26 +++-------- .../mod/forum/providers/index-link-handler.ts | 43 +------------------ .../classes/module-index-handler.ts | 8 ++-- src/core/course/providers/helper.ts | 16 +++---- 4 files changed, 21 insertions(+), 72 deletions(-) diff --git a/src/addon/mod/book/providers/link-handler.ts b/src/addon/mod/book/providers/link-handler.ts index 427060748..ecc033eeb 100644 --- a/src/addon/mod/book/providers/link-handler.ts +++ b/src/addon/mod/book/providers/link-handler.ts @@ -15,7 +15,6 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; -import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { AddonModBookProvider } from './book'; /** @@ -31,26 +30,15 @@ export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler } /** - * Get the list of actions for a link (url). + * Get the mod params necessary to open an activity. * - * @param siteIds List of sites the URL belongs to. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return List of (or promise resolved with list of) actions. + * @param url The URL to treat. + * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} + * @param courseId Course ID related to the URL. Optional but recommended. + * @return List of params to pass to navigateToModule / navigateToModuleByInstance. */ - getActions(siteIds: string[], url: string, params: any, courseId?: number): - CoreContentLinksAction[] | Promise { - - const modParams = params.chapterid ? {chapterId: params.chapterid} : undefined; - courseId = courseId || params.courseid || params.cid; - - return [{ - action: (siteId, navCtrl?): void => { - this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined, - this.useModNameToGetModule ? this.modName : undefined, modParams, navCtrl); - } - }]; + getPageParams(url: string, params: any, courseId?: number): any { + return params.chapterid ? {chapterId: parseInt(params.chapterid, 10)} : undefined; } /** diff --git a/src/addon/mod/forum/providers/index-link-handler.ts b/src/addon/mod/forum/providers/index-link-handler.ts index e131ffb6d..9e059e491 100644 --- a/src/addon/mod/forum/providers/index-link-handler.ts +++ b/src/addon/mod/forum/providers/index-link-handler.ts @@ -15,9 +15,6 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; -import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; -import { CoreCourseProvider } from '@core/course/providers/course'; -import { CoreDomUtilsProvider } from '@providers/utils/dom'; /** * Handler to treat links to forum index. @@ -26,43 +23,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModForumIndexLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider, - private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) { - super(courseHelper, 'AddonModForum', 'forum'); - - // Match the view.php URL with an id param. - this.pattern = new RegExp('\/mod\/forum\/view\.php.*([\&\?](f|id)=\\d+)'); - } - - /** - * Get the list of actions for a link (url). - * - * @param siteIds List of sites the URL belongs to. - * @param url The URL to treat. - * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} - * @param courseId Course ID related to the URL. Optional but recommended. - * @return List of (or promise resolved with list of) actions. - */ - getActions(siteIds: string[], url: string, params: any, courseId?: number): - CoreContentLinksAction[] | Promise { - - if (typeof params.f != 'undefined') { - return [{ - action: (siteId, navCtrl?): void => { - const modal = this.domUtils.showModalLoading(), - forumId = parseInt(params.f, 10); - - this.courseProvider.getModuleBasicInfoByInstance(forumId, 'forum', siteId).then((module) => { - this.courseHelper.navigateToModule(parseInt(module.id, 10), siteId, module.course, undefined, - undefined, undefined, navCtrl); - }).finally(() => { - // Just in case. In fact we need to dismiss the modal before showing a toast or error message. - modal.dismiss(); - }); - } - }]; - } - - return super.getActions(siteIds, url, params, courseId); + constructor(courseHelper: CoreCourseHelperProvider) { + super(courseHelper, 'AddonModForum', 'forum', 'f'); } } diff --git a/src/core/contentlinks/classes/module-index-handler.ts b/src/core/contentlinks/classes/module-index-handler.ts index 32037482d..1af14a851 100644 --- a/src/core/contentlinks/classes/module-index-handler.ts +++ b/src/core/contentlinks/classes/module-index-handler.ts @@ -58,7 +58,7 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB * @param courseId Course ID related to the URL. Optional but recommended. * @return List of params to pass to navigateToModule / navigateToModuleByInstance. */ - getModParams(url: string, params: any, courseId?: number): any { + getPageParams(url: string, params: any, courseId?: number): any { return undefined; } @@ -75,7 +75,7 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB CoreContentLinksAction[] | Promise { courseId = courseId || params.courseid || params.cid; - const modParams = this.getModParams(url, params, courseId); + const pageParams = this.getPageParams(url, params, courseId); if (this.instanceIdParam && typeof params[this.instanceIdParam] != 'undefined') { const instanceId = parseInt(params[this.instanceIdParam], 10); @@ -83,7 +83,7 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB return [{ action: (siteId, navCtrl?): void => { this.courseHelper.navigateToModuleByInstance(instanceId, this.modName, siteId, courseId, undefined, - this.useModNameToGetModule, modParams, navCtrl); + this.useModNameToGetModule, pageParams, navCtrl); } }]; } @@ -91,7 +91,7 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB return [{ action: (siteId, navCtrl?): void => { this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined, - this.useModNameToGetModule ? this.modName : undefined, modParams, navCtrl); + this.useModNameToGetModule ? this.modName : undefined, pageParams, navCtrl); } }]; } diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index 86db51423..324c4a29a 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -1197,13 +1197,6 @@ export class CoreCourseHelperProvider { // Get the module. return this.courseProvider.getModule(moduleId, courseId, sectionId, false, false, siteId, modName); }).then((module) => { - const params = { - course: { id: courseId }, - module: module, - sectionId: sectionId, - modParams: modParams - }; - module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId); if (navCtrl && module.handlerData && module.handlerData.action) { @@ -1211,11 +1204,18 @@ export class CoreCourseHelperProvider { // Otherwise, we will redirect below. modal.dismiss(); - return module.handlerData.action(new Event('click'), navCtrl, module, courseId); + return module.handlerData.action(new Event('click'), navCtrl, module, courseId, undefined, modParams); } this.logger.warn('navCtrl was not passed to navigateToModule by the link handler for ' + module.modname); + const params = { + course: { id: courseId }, + module: module, + sectionId: sectionId, + modParams: modParams + }; + if (courseId == site.getSiteHomeId()) { // Check if site home is available. return this.siteHomeProvider.isAvailable().then(() => {