MOBILE-3218 links: Implement all index handlers enabled on activity

main
Pau Ferrer Ocaña 2019-11-29 11:37:20 +01:00
parent ed1fc4c09d
commit 30e6feab24
9 changed files with 112 additions and 37 deletions

View File

@ -16,6 +16,7 @@ import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { AddonModBookProvider } from './book';
/** /**
* Handler to treat links to book. * Handler to treat links to book.
@ -24,7 +25,8 @@ import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModBookLinkHandler'; name = 'AddonModBookLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected bookProvider: AddonModBookProvider) {
super(courseHelper, 'AddonModBook', 'book'); 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<boolean> {
return this.bookProvider.isPluginEnabled();
}
} }

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { AddonModDataProvider } from './data';
/** /**
* Handler to treat links to data. * Handler to treat links to data.
@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper';
export class AddonModDataLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModDataLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModDataLinkHandler'; name = 'AddonModDataLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected dataProvider: AddonModDataProvider) {
super(courseHelper, 'AddonModData', 'data'); 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<boolean> {
return this.dataProvider.isPluginEnabled();
}
} }

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { AddonModFeedbackProvider } from './feedback';
/** /**
* Handler to treat links to feedback. * Handler to treat links to feedback.
@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper';
export class AddonModFeedbackLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModFeedbackLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModFeedbackLinkHandler'; name = 'AddonModFeedbackLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected feedbackProvider: AddonModFeedbackProvider) {
super(courseHelper, 'AddonModFeedback', 'feedback'); 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<boolean> {
return this.feedbackProvider.isPluginEnabled();
}
} }

View File

@ -15,7 +15,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { AddonModForumProvider } from './forum';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreCourseProvider } from '@core/course/providers/course'; import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreDomUtilsProvider } from '@providers/utils/dom';
@ -27,7 +26,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModForumIndexLinkHandler'; name = 'AddonModForumIndexLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider, protected forumProvider: AddonModForumProvider, constructor(courseHelper: CoreCourseHelperProvider,
private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) { private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) {
super(courseHelper, 'AddonModForum', 'forum'); super(courseHelper, 'AddonModForum', 'forum');
@ -35,20 +34,6 @@ export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHa
this.pattern = new RegExp('\/mod\/forum\/view\.php.*([\&\?](f|id)=\\d+)'); 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<boolean> {
return true;
}
/** /**
* Get the list of actions for a link (url). * Get the list of actions for a link (url).
* *

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { AddonModImscpProvider } from './imscp';
/** /**
* Handler to treat links to IMSCP. * Handler to treat links to IMSCP.
@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper';
export class AddonModImscpLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModImscpLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModImscpLinkHandler'; name = 'AddonModImscpLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected imscpProvider: AddonModImscpProvider) {
super(courseHelper, 'AddonModImscp', 'imscp'); 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<boolean> {
return this.imscpProvider.isPluginEnabled();
}
} }

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { AddonModPageProvider } from './page';
/** /**
* Handler to treat links to resource. * Handler to treat links to resource.
@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper';
export class AddonModPageLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModPageLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModPageLinkHandler'; name = 'AddonModPageLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected pageProvider: AddonModPageProvider) {
super(courseHelper, 'AddonModPage', 'page'); 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<boolean> {
return this.pageProvider.isPluginEnabled();
}
} }

View File

@ -27,18 +27,4 @@ export class AddonModQuizIndexLinkHandler extends CoreContentLinksModuleIndexHan
constructor(courseHelper: CoreCourseHelperProvider, protected quizProvider: AddonModQuizProvider) { constructor(courseHelper: CoreCourseHelperProvider, protected quizProvider: AddonModQuizProvider) {
super(courseHelper, 'AddonModQuiz', 'quiz'); 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<boolean> {
return this.quizProvider.isPluginEnabled();
}
} }

View File

@ -15,6 +15,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler'; import { CoreContentLinksModuleIndexHandler } from '@core/contentlinks/classes/module-index-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; import { CoreCourseHelperProvider } from '@core/course/providers/helper';
import { AddonModResourceProvider } from './resource';
/** /**
* Handler to treat links to resource. * Handler to treat links to resource.
@ -23,7 +24,21 @@ import { CoreCourseHelperProvider } from '@core/course/providers/helper';
export class AddonModResourceLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModResourceLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModResourceLinkHandler'; name = 'AddonModResourceLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected resourceProvider: AddonModResourceProvider) {
super(courseHelper, 'AddonModResource', 'resource'); 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<boolean> {
return this.resourceProvider.isPluginEnabled();
}
} }

View File

@ -24,7 +24,21 @@ import { AddonModWorkshopProvider } from './workshop';
export class AddonModWorkshopLinkHandler extends CoreContentLinksModuleIndexHandler { export class AddonModWorkshopLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModWorkshopLinkHandler'; name = 'AddonModWorkshopLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider,
protected workshopProvider: AddonModWorkshopProvider) {
super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop'); 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<boolean> {
return this.workshopProvider.isPluginEnabled(siteId);
}
} }