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] 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); + } }