From a6432ad7b7d8c05f03088164d5355479c912a045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 29 Nov 2019 11:21:19 +0100 Subject: [PATCH 1/6] MOBILE-3218 mod: Fix isPluginEnabled return type on activities --- src/addon/mod/imscp/providers/imscp.ts | 2 +- src/addon/mod/lesson/providers/lesson.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/addon/mod/imscp/providers/imscp.ts b/src/addon/mod/imscp/providers/imscp.ts index 58667b135..bd7eb8cf4 100644 --- a/src/addon/mod/imscp/providers/imscp.ts +++ b/src/addon/mod/imscp/providers/imscp.ts @@ -304,7 +304,7 @@ export class AddonModImscpProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise. */ - isPluginEnabled(siteId?: string): Promise { + isPluginEnabled(siteId?: string): Promise { return this.sitesProvider.getSite(siteId).then((site) => { return site.canDownloadFiles(); }); diff --git a/src/addon/mod/lesson/providers/lesson.ts b/src/addon/mod/lesson/providers/lesson.ts index 4c7a52711..b7fabe1f1 100644 --- a/src/addon/mod/lesson/providers/lesson.ts +++ b/src/addon/mod/lesson/providers/lesson.ts @@ -2775,7 +2775,7 @@ export class AddonModLessonProvider { * @param siteId Site ID. If not defined, current site. * @return Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise. */ - isPluginEnabled(siteId?: string): Promise { + isPluginEnabled(siteId?: string): Promise { return this.sitesProvider.getSite(siteId).then((site) => { // All WS were introduced at the same time so checking one is enough. return site.wsAvailable('mod_lesson_get_lesson_access_information'); From ed1fc4c09d905f497649f51b75b3da889e047b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 29 Nov 2019 13:49:58 +0100 Subject: [PATCH 2/6] MOBILE-3218 course: Add general navigation to module by instance --- .../classes/module-index-handler.ts | 38 +++++++++++++++++-- src/core/course/providers/helper.ts | 31 +++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/core/contentlinks/classes/module-index-handler.ts b/src/core/contentlinks/classes/module-index-handler.ts index 859d72c1d..32037482d 100644 --- a/src/core/contentlinks/classes/module-index-handler.ts +++ b/src/core/contentlinks/classes/module-index-handler.ts @@ -15,6 +15,8 @@ import { CoreContentLinksAction } from '../providers/delegate'; import { CoreContentLinksHandlerBase } from './base-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; /** * Handler to handle URLs pointing to the index of a module. @@ -33,15 +35,33 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB * @param courseHelper The CoreCourseHelperProvider instance. * @param addon Name of the addon as it's registered in course delegate. It'll be used to check if it's disabled. * @param modName Name of the module (assign, book, ...). + * @param instanceIdParam Param name for instance ID gathering. Only if set. */ - constructor(protected courseHelper: CoreCourseHelperProvider, public addon: string, public modName: string) { + constructor(protected courseHelper: CoreCourseHelperProvider, public addon: string, public modName: string, + protected instanceIdParam?: string) { super(); + const pattern = instanceIdParam ? + '\/mod\/' + modName + '\/view\.php.*([\&\?](' + instanceIdParam + '|id)=\\d+)' : + '\/mod\/' + modName + '\/view\.php.*([\&\?]id=\\d+)'; + // Match the view.php URL with an id param. - this.pattern = new RegExp('\/mod\/' + modName + '\/view\.php.*([\&\?]id=\\d+)'); + this.pattern = new RegExp(pattern); this.featureName = 'CoreCourseModuleDelegate_' + addon; } + /** + * Get the mod params necessary to open an activity. + * + * @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. + */ + getModParams(url: string, params: any, courseId?: number): any { + return undefined; + } + /** * Get the list of actions for a link (url). * @@ -55,11 +75,23 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB CoreContentLinksAction[] | Promise { courseId = courseId || params.courseid || params.cid; + const modParams = this.getModParams(url, params, courseId); + + if (this.instanceIdParam && typeof params[this.instanceIdParam] != 'undefined') { + const instanceId = parseInt(params[this.instanceIdParam], 10); + + return [{ + action: (siteId, navCtrl?): void => { + this.courseHelper.navigateToModuleByInstance(instanceId, this.modName, siteId, courseId, undefined, + this.useModNameToGetModule, modParams, navCtrl); + } + }]; + } return [{ action: (siteId, navCtrl?): void => { this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined, - this.useModNameToGetModule ? this.modName : undefined, undefined, navCtrl); + this.useModNameToGetModule ? this.modName : undefined, modParams, navCtrl); } }]; } diff --git a/src/core/course/providers/helper.ts b/src/core/course/providers/helper.ts index 1ecf7a124..86db51423 100644 --- a/src/core/course/providers/helper.ts +++ b/src/core/course/providers/helper.ts @@ -1114,6 +1114,37 @@ export class CoreCourseHelperProvider { return 'Section-' + section.id; } + /** + * Navigate to a module using instance ID and module name. + * + * @param instanceId Activity instance ID. + * @param modName Module name of the activity. + * @param siteId Site ID. If not defined, current site. + * @param courseId Course ID. If not defined we'll try to retrieve it from the site. + * @param sectionId Section the module belongs to. If not defined we'll try to retrieve it from the site. + * @param useModNameToGetModule If true, the app will retrieve all modules of this type with a single WS call. This reduces the + * number of WS calls, but it isn't recommended for modules that can return a lot of contents. + * @param modParams Params to pass to the module + * @param navCtrl NavController for adding new pages to the current history. Optional for legacy support, but + * generates a warning if omitted. + * @return Promise resolved when done. + */ + navigateToModuleByInstance(instanceId: number, modName: string, siteId?: string, courseId?: number, sectionId?: number, + useModNameToGetModule: boolean = false, modParams?: any, navCtrl?: NavController): Promise { + + const modal = this.domUtils.showModalLoading(); + + return this.courseProvider.getModuleBasicInfoByInstance(instanceId, modName, siteId).then((module) => { + this.navigateToModule(parseInt(module.id, 10), siteId, module.course, sectionId, + useModNameToGetModule ? modName : undefined, modParams, navCtrl); + }).catch((error) => { + this.domUtils.showErrorModalDefault(error, 'core.course.errorgetmodule', true); + }).finally(() => { + // Just in case. In fact we need to dismiss the modal before showing a toast or error message. + modal.dismiss(); + }); + } + /** * Navigate to a module. * From 30e6feab240bd762d75384694e8cb7deb2ba141d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 29 Nov 2019 11:37:20 +0100 Subject: [PATCH 3/6] MOBILE-3218 links: Implement all index handlers enabled on activity --- src/addon/mod/book/providers/link-handler.ts | 17 ++++++++++++++++- src/addon/mod/data/providers/link-handler.ts | 17 ++++++++++++++++- .../mod/feedback/providers/link-handler.ts | 17 ++++++++++++++++- .../mod/forum/providers/index-link-handler.ts | 17 +---------------- src/addon/mod/imscp/providers/link-handler.ts | 17 ++++++++++++++++- src/addon/mod/page/providers/link-handler.ts | 17 ++++++++++++++++- .../mod/quiz/providers/index-link-handler.ts | 14 -------------- .../mod/resource/providers/link-handler.ts | 17 ++++++++++++++++- .../mod/workshop/providers/link-handler.ts | 16 +++++++++++++++- 9 files changed, 112 insertions(+), 37 deletions(-) diff --git a/src/addon/mod/book/providers/link-handler.ts b/src/addon/mod/book/providers/link-handler.ts index cde3d391f..427060748 100644 --- a/src/addon/mod/book/providers/link-handler.ts +++ b/src/addon/mod/book/providers/link-handler.ts @@ -16,6 +16,7 @@ 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'; /** * Handler to treat links to book. @@ -24,7 +25,8 @@ import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModBookLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected bookProvider: AddonModBookProvider) { super(courseHelper, 'AddonModBook', 'book'); } @@ -50,4 +52,17 @@ export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler } }]; } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.bookProvider.isPluginEnabled(); + } } diff --git a/src/addon/mod/data/providers/link-handler.ts b/src/addon/mod/data/providers/link-handler.ts index 622e18d6a..00e5903aa 100644 --- a/src/addon/mod/data/providers/link-handler.ts +++ b/src/addon/mod/data/providers/link-handler.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { AddonModDataProvider } from './data'; /** * Handler to treat links to data. @@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper'; export class AddonModDataLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModDataLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected dataProvider: AddonModDataProvider) { super(courseHelper, 'AddonModData', 'data'); } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.dataProvider.isPluginEnabled(); + } } diff --git a/src/addon/mod/feedback/providers/link-handler.ts b/src/addon/mod/feedback/providers/link-handler.ts index 420db096d..a6021911e 100644 --- a/src/addon/mod/feedback/providers/link-handler.ts +++ b/src/addon/mod/feedback/providers/link-handler.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { AddonModFeedbackProvider } from './feedback'; /** * Handler to treat links to feedback. @@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper'; export class AddonModFeedbackLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModFeedbackLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected feedbackProvider: AddonModFeedbackProvider) { super(courseHelper, 'AddonModFeedback', 'feedback'); } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.feedbackProvider.isPluginEnabled(); + } } diff --git a/src/addon/mod/forum/providers/index-link-handler.ts b/src/addon/mod/forum/providers/index-link-handler.ts index ac0468cb9..e131ffb6d 100644 --- a/src/addon/mod/forum/providers/index-link-handler.ts +++ b/src/addon/mod/forum/providers/index-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 { AddonModForumProvider } from './forum'; import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -27,7 +26,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom'; export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModForumIndexLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider, protected forumProvider: AddonModForumProvider, + constructor(courseHelper: CoreCourseHelperProvider, private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) { super(courseHelper, 'AddonModForum', 'forum'); @@ -35,20 +34,6 @@ export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHa this.pattern = new RegExp('\/mod\/forum\/view\.php.*([\&\?](f|id)=\\d+)'); } - /** - * Check if the handler is enabled for a certain site (site + user) and a URL. - * If not defined, defaults to true. - * - * @param siteId The site ID. - * @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 Whether the handler is enabled for the URL and site. - */ - isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { - return true; - } - /** * Get the list of actions for a link (url). * diff --git a/src/addon/mod/imscp/providers/link-handler.ts b/src/addon/mod/imscp/providers/link-handler.ts index 870f1ad0c..4795a50d3 100644 --- a/src/addon/mod/imscp/providers/link-handler.ts +++ b/src/addon/mod/imscp/providers/link-handler.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { AddonModImscpProvider } from './imscp'; /** * Handler to treat links to IMSCP. @@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper'; export class AddonModImscpLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModImscpLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected imscpProvider: AddonModImscpProvider) { super(courseHelper, 'AddonModImscp', 'imscp'); } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.imscpProvider.isPluginEnabled(); + } } diff --git a/src/addon/mod/page/providers/link-handler.ts b/src/addon/mod/page/providers/link-handler.ts index c49947c63..d4d779c5e 100644 --- a/src/addon/mod/page/providers/link-handler.ts +++ b/src/addon/mod/page/providers/link-handler.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { AddonModPageProvider } from './page'; /** * Handler to treat links to resource. @@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper'; export class AddonModPageLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModPageLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected pageProvider: AddonModPageProvider) { super(courseHelper, 'AddonModPage', 'page'); } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.pageProvider.isPluginEnabled(); + } } diff --git a/src/addon/mod/quiz/providers/index-link-handler.ts b/src/addon/mod/quiz/providers/index-link-handler.ts index 11f99de3b..eeb82ab38 100644 --- a/src/addon/mod/quiz/providers/index-link-handler.ts +++ b/src/addon/mod/quiz/providers/index-link-handler.ts @@ -27,18 +27,4 @@ export class AddonModQuizIndexLinkHandler extends CoreContentLinksModuleIndexHan constructor(courseHelper: CoreCourseHelperProvider, protected quizProvider: AddonModQuizProvider) { super(courseHelper, 'AddonModQuiz', 'quiz'); } - - /** - * Check if the handler is enabled for a certain site (site + user) and a URL. - * If not defined, defaults to true. - * - * @param siteId The site ID. - * @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 Whether the handler is enabled for the URL and site. - */ - isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { - return this.quizProvider.isPluginEnabled(); - } } diff --git a/src/addon/mod/resource/providers/link-handler.ts b/src/addon/mod/resource/providers/link-handler.ts index 39a1795de..e17ec1721 100644 --- a/src/addon/mod/resource/providers/link-handler.ts +++ b/src/addon/mod/resource/providers/link-handler.ts @@ -15,6 +15,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { AddonModResourceProvider } from './resource'; /** * Handler to treat links to resource. @@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper'; export class AddonModResourceLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModResourceLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected resourceProvider: AddonModResourceProvider) { super(courseHelper, 'AddonModResource', 'resource'); } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.resourceProvider.isPluginEnabled(); + } } diff --git a/src/addon/mod/workshop/providers/link-handler.ts b/src/addon/mod/workshop/providers/link-handler.ts index 94637f4b2..0e62d1cbf 100644 --- a/src/addon/mod/workshop/providers/link-handler.ts +++ b/src/addon/mod/workshop/providers/link-handler.ts @@ -24,7 +24,21 @@ import { AddonModWorkshopProvider } from './workshop'; export class AddonModWorkshopLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModWorkshopLinkHandler'; - constructor(courseHelper: CoreCourseHelperProvider) { + constructor(courseHelper: CoreCourseHelperProvider, + protected workshopProvider: AddonModWorkshopProvider) { super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop'); } + + /** + * Check if the handler is enabled for a certain site (site + user) and a URL. + * + * @param siteId The site ID. + * @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 Whether the handler is enabled for the URL and site. + */ + isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise { + return this.workshopProvider.isPluginEnabled(siteId); + } } 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 4/6] 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(() => { From 22ab48800e6c9a818c55bce8f4a9fe4d4253f474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 29 Nov 2019 13:48:12 +0100 Subject: [PATCH 5/6] MOBILE-3218 forum: Discussions link only works from notifications --- .../mod/forum/pages/discussion/discussion.ts | 33 ++++++++++++++----- .../providers/discussion-link-handler.ts | 6 ++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/addon/mod/forum/pages/discussion/discussion.ts b/src/addon/mod/forum/pages/discussion/discussion.ts index 6d47d6db9..bbeca74e6 100644 --- a/src/addon/mod/forum/pages/discussion/discussion.ts +++ b/src/addon/mod/forum/pages/discussion/discussion.ts @@ -191,8 +191,8 @@ export class AddonModForumDiscussionPage implements OnDestroy { }); this.changeDiscObserver = this.eventsProvider.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, (data) => { - if ((this.forum && this.forum.id === data.forumId) || data.cmId === this.cmId) { - this.forumProvider.invalidateDiscussionsList(this.forum.id).finally(() => { + if ((this.forumId && this.forumId === data.forumId) || data.cmId === this.cmId) { + this.forumProvider.invalidateDiscussionsList(this.forumId).finally(() => { if (typeof data.locked != 'undefined') { this.discussion.locked = data.locked; } @@ -350,7 +350,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { const promises = []; - promises.push(this.forumProvider.getAccessInformation(this.forum.id).then((accessInfo) => { + promises.push(this.forumProvider.getAccessInformation(this.forumId).then((accessInfo) => { this.accessInfo = accessInfo; // Disallow replying if cut-off date is reached and the user has not the capability to override it. @@ -364,11 +364,7 @@ export class AddonModForumDiscussionPage implements OnDestroy { // Fetch the discussion if not passed as parameter. if (!this.discussion) { - promises.push(this.forumHelper.getDiscussionById(forum.id, this.discussionId).then((discussion) => { - this.discussion = discussion; - }).catch(() => { - // Ignore errors. - })); + promises.push(this.loadDiscussion(this.forumId, this.discussionId)); } return Promise.all(promises); @@ -434,6 +430,27 @@ export class AddonModForumDiscussionPage implements OnDestroy { }); } + /** + * Convenience function to load discussion. + * + * @param forumId Forum ID. + * @param discussionId Discussion ID. + * @return Promise resolved when done. + */ + protected loadDiscussion(forumId: number, discussionId: number): Promise { + // Fetch the discussion if not passed as parameter. + if (!this.discussion && forumId) { + return this.forumHelper.getDiscussionById(forumId, discussionId).then((discussion) => { + this.discussion = discussion; + this.discussionId = this.discussion.discussion; + }).catch(() => { + // Ignore errors. + }); + } + + return Promise.resolve(); + } + /** * Tries to synchronize the posts discussion. * diff --git a/src/addon/mod/forum/providers/discussion-link-handler.ts b/src/addon/mod/forum/providers/discussion-link-handler.ts index 243a1d09d..67e87c4cd 100644 --- a/src/addon/mod/forum/providers/discussion-link-handler.ts +++ b/src/addon/mod/forum/providers/discussion-link-handler.ts @@ -45,6 +45,12 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB CoreContentLinksAction[] | Promise { data = data || {}; + if (!data.instance) { + // Without the forumId discussions cannot be loaded (from link). + + return []; + } + return [{ action: (siteId, navCtrl?): void => { const pageParams: any = { From a03162f70b9ea7b6e121ab21b0c4ba9f380ff22b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Fri, 29 Nov 2019 13:51:06 +0100 Subject: [PATCH 6/6] MOBILE-3218 links: Use instanceId on module index links --- src/addon/mod/book/providers/link-handler.ts | 2 +- src/addon/mod/chat/providers/link-handler.ts | 2 +- src/addon/mod/data/providers/link-handler.ts | 2 +- src/addon/mod/folder/providers/link-handler.ts | 2 +- src/addon/mod/glossary/providers/index-link-handler.ts | 2 +- src/addon/mod/imscp/providers/link-handler.ts | 2 +- src/addon/mod/label/providers/link-handler.ts | 2 +- src/addon/mod/lti/providers/link-handler.ts | 2 +- src/addon/mod/page/providers/link-handler.ts | 2 +- src/addon/mod/quiz/providers/index-link-handler.ts | 2 +- src/addon/mod/resource/providers/link-handler.ts | 2 +- src/addon/mod/scorm/providers/index-link-handler.ts | 2 +- src/addon/mod/url/providers/link-handler.ts | 2 +- src/addon/mod/wiki/providers/index-link-handler.ts | 2 +- src/addon/mod/workshop/providers/link-handler.ts | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/addon/mod/book/providers/link-handler.ts b/src/addon/mod/book/providers/link-handler.ts index ecc033eeb..051d08429 100644 --- a/src/addon/mod/book/providers/link-handler.ts +++ b/src/addon/mod/book/providers/link-handler.ts @@ -26,7 +26,7 @@ export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler constructor(courseHelper: CoreCourseHelperProvider, protected bookProvider: AddonModBookProvider) { - super(courseHelper, 'AddonModBook', 'book'); + super(courseHelper, 'AddonModBook', 'book', 'b'); } /** diff --git a/src/addon/mod/chat/providers/link-handler.ts b/src/addon/mod/chat/providers/link-handler.ts index 73b77063d..a2fb3035f 100644 --- a/src/addon/mod/chat/providers/link-handler.ts +++ b/src/addon/mod/chat/providers/link-handler.ts @@ -24,6 +24,6 @@ export class AddonModChatLinkHandler extends CoreContentLinksModuleIndexHandler name = 'AddonModChatLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModChat', 'chat'); + super(courseHelper, 'AddonModChat', 'chat', 'c'); } } diff --git a/src/addon/mod/data/providers/link-handler.ts b/src/addon/mod/data/providers/link-handler.ts index 00e5903aa..30879d5ec 100644 --- a/src/addon/mod/data/providers/link-handler.ts +++ b/src/addon/mod/data/providers/link-handler.ts @@ -26,7 +26,7 @@ export class AddonModDataLinkHandler extends CoreContentLinksModuleIndexHandler constructor(courseHelper: CoreCourseHelperProvider, protected dataProvider: AddonModDataProvider) { - super(courseHelper, 'AddonModData', 'data'); + super(courseHelper, 'AddonModData', 'data', 'd'); } /** diff --git a/src/addon/mod/folder/providers/link-handler.ts b/src/addon/mod/folder/providers/link-handler.ts index c71004b19..cba59acfb 100644 --- a/src/addon/mod/folder/providers/link-handler.ts +++ b/src/addon/mod/folder/providers/link-handler.ts @@ -24,6 +24,6 @@ export class AddonModFolderLinkHandler extends CoreContentLinksModuleIndexHandle name = 'AddonModFolderLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModFolder', 'folder'); + super(courseHelper, 'AddonModFolder', 'folder', 'f'); } } diff --git a/src/addon/mod/glossary/providers/index-link-handler.ts b/src/addon/mod/glossary/providers/index-link-handler.ts index 5162325d8..a4e78aa5e 100644 --- a/src/addon/mod/glossary/providers/index-link-handler.ts +++ b/src/addon/mod/glossary/providers/index-link-handler.ts @@ -25,6 +25,6 @@ export class AddonModGlossaryIndexLinkHandler extends CoreContentLinksModuleInde name = 'AddonModGlossaryIndexLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider, protected glossaryProvider: AddonModGlossaryProvider) { - super(courseHelper, 'AddonModGlossary', 'glossary'); + super(courseHelper, 'AddonModGlossary', 'glossary', 'g'); } } diff --git a/src/addon/mod/imscp/providers/link-handler.ts b/src/addon/mod/imscp/providers/link-handler.ts index 4795a50d3..f7e4c14bd 100644 --- a/src/addon/mod/imscp/providers/link-handler.ts +++ b/src/addon/mod/imscp/providers/link-handler.ts @@ -26,7 +26,7 @@ export class AddonModImscpLinkHandler extends CoreContentLinksModuleIndexHandler constructor(courseHelper: CoreCourseHelperProvider, protected imscpProvider: AddonModImscpProvider) { - super(courseHelper, 'AddonModImscp', 'imscp'); + super(courseHelper, 'AddonModImscp', 'imscp', 'i'); } /** diff --git a/src/addon/mod/label/providers/link-handler.ts b/src/addon/mod/label/providers/link-handler.ts index be593f328..75bb57f31 100644 --- a/src/addon/mod/label/providers/link-handler.ts +++ b/src/addon/mod/label/providers/link-handler.ts @@ -24,6 +24,6 @@ export class AddonModLabelLinkHandler extends CoreContentLinksModuleIndexHandler name = 'AddonModLabelLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModLabel', 'label'); + super(courseHelper, 'AddonModLabel', 'label', 'l'); } } diff --git a/src/addon/mod/lti/providers/link-handler.ts b/src/addon/mod/lti/providers/link-handler.ts index bc0c0a6b2..2a174688c 100644 --- a/src/addon/mod/lti/providers/link-handler.ts +++ b/src/addon/mod/lti/providers/link-handler.ts @@ -24,6 +24,6 @@ export class AddonModLtiLinkHandler extends CoreContentLinksModuleIndexHandler { name = 'AddonModLtiLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModLti', 'lti'); + super(courseHelper, 'AddonModLti', 'lti', 'l'); } } diff --git a/src/addon/mod/page/providers/link-handler.ts b/src/addon/mod/page/providers/link-handler.ts index d4d779c5e..6374fb2d1 100644 --- a/src/addon/mod/page/providers/link-handler.ts +++ b/src/addon/mod/page/providers/link-handler.ts @@ -26,7 +26,7 @@ export class AddonModPageLinkHandler extends CoreContentLinksModuleIndexHandler constructor(courseHelper: CoreCourseHelperProvider, protected pageProvider: AddonModPageProvider) { - super(courseHelper, 'AddonModPage', 'page'); + super(courseHelper, 'AddonModPage', 'page', 'p'); } /** diff --git a/src/addon/mod/quiz/providers/index-link-handler.ts b/src/addon/mod/quiz/providers/index-link-handler.ts index eeb82ab38..dbb36cc8e 100644 --- a/src/addon/mod/quiz/providers/index-link-handler.ts +++ b/src/addon/mod/quiz/providers/index-link-handler.ts @@ -25,6 +25,6 @@ export class AddonModQuizIndexLinkHandler extends CoreContentLinksModuleIndexHan name = 'AddonModQuizIndexLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider, protected quizProvider: AddonModQuizProvider) { - super(courseHelper, 'AddonModQuiz', 'quiz'); + super(courseHelper, 'AddonModQuiz', 'quiz', 'q'); } } diff --git a/src/addon/mod/resource/providers/link-handler.ts b/src/addon/mod/resource/providers/link-handler.ts index e17ec1721..a9cc54f1a 100644 --- a/src/addon/mod/resource/providers/link-handler.ts +++ b/src/addon/mod/resource/providers/link-handler.ts @@ -26,7 +26,7 @@ export class AddonModResourceLinkHandler extends CoreContentLinksModuleIndexHand constructor(courseHelper: CoreCourseHelperProvider, protected resourceProvider: AddonModResourceProvider) { - super(courseHelper, 'AddonModResource', 'resource'); + super(courseHelper, 'AddonModResource', 'resource', 'r'); } /** diff --git a/src/addon/mod/scorm/providers/index-link-handler.ts b/src/addon/mod/scorm/providers/index-link-handler.ts index 999c01595..a8182a2ed 100644 --- a/src/addon/mod/scorm/providers/index-link-handler.ts +++ b/src/addon/mod/scorm/providers/index-link-handler.ts @@ -24,6 +24,6 @@ export class AddonModScormIndexLinkHandler extends CoreContentLinksModuleIndexHa name = 'AddonModScormIndexLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModScorm', 'scorm'); + super(courseHelper, 'AddonModScorm', 'scorm', 'a'); } } diff --git a/src/addon/mod/url/providers/link-handler.ts b/src/addon/mod/url/providers/link-handler.ts index 26d02f5f3..9d43f2975 100644 --- a/src/addon/mod/url/providers/link-handler.ts +++ b/src/addon/mod/url/providers/link-handler.ts @@ -25,6 +25,6 @@ export class AddonModUrlLinkHandler extends CoreContentLinksModuleIndexHandler { useModNameToGetModule = true; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModUrl', 'url'); + super(courseHelper, 'AddonModUrl', 'url', 'u'); } } diff --git a/src/addon/mod/wiki/providers/index-link-handler.ts b/src/addon/mod/wiki/providers/index-link-handler.ts index 26286449e..8b734e980 100644 --- a/src/addon/mod/wiki/providers/index-link-handler.ts +++ b/src/addon/mod/wiki/providers/index-link-handler.ts @@ -24,6 +24,6 @@ export class AddonModWikiIndexLinkHandler extends CoreContentLinksModuleIndexHan name = 'AddonModWikiIndexLinkHandler'; constructor(courseHelper: CoreCourseHelperProvider) { - super(courseHelper, 'AddonModWiki', 'wiki'); + super(courseHelper, 'AddonModWiki', 'wiki', 'wid'); } } diff --git a/src/addon/mod/workshop/providers/link-handler.ts b/src/addon/mod/workshop/providers/link-handler.ts index 0e62d1cbf..a934b63bc 100644 --- a/src/addon/mod/workshop/providers/link-handler.ts +++ b/src/addon/mod/workshop/providers/link-handler.ts @@ -26,7 +26,7 @@ export class AddonModWorkshopLinkHandler extends CoreContentLinksModuleIndexHand constructor(courseHelper: CoreCourseHelperProvider, protected workshopProvider: AddonModWorkshopProvider) { - super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop'); + super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop', 'w'); } /**