Merge pull request #2177 from crazyserver/MOBILE-3218

Mobile 3218
main
Juan Leyva 2019-12-03 14:30:17 +01:00 committed by GitHub
commit 2ceb3a155d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 239 additions and 129 deletions

View File

@ -15,7 +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 { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { AddonModBookProvider } from './book';
/** /**
* Handler to treat links to book. * Handler to treat links to book.
@ -24,30 +24,33 @@ 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,
super(courseHelper, 'AddonModBook', 'book'); protected bookProvider: AddonModBookProvider) {
super(courseHelper, 'AddonModBook', 'book', 'b');
} }
/** /**
* 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 url The URL to treat.
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1} * @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. * @param courseId Course ID related to the URL. Optional but recommended.
* @return List of (or promise resolved with list of) actions. * @return List of params to pass to navigateToModule / navigateToModuleByInstance.
*/ */
getActions(siteIds: string[], url: string, params: any, courseId?: number): getPageParams(url: string, params: any, courseId?: number): any {
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { return params.chapterid ? {chapterId: parseInt(params.chapterid, 10)} : undefined;
}
const modParams = params.chapterid ? {chapterId: params.chapterid} : undefined; /**
courseId = courseId || params.courseid || params.cid; * Check if the handler is enabled for a certain site (site + user) and a URL.
*
return [{ * @param siteId The site ID.
action: (siteId, navCtrl?): void => { * @param url The URL to treat.
this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined, * @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
this.useModNameToGetModule ? this.modName : undefined, modParams, navCtrl); * @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

@ -24,6 +24,6 @@ export class AddonModChatLinkHandler extends CoreContentLinksModuleIndexHandler
name = 'AddonModChatLinkHandler'; name = 'AddonModChatLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModChat', 'chat'); super(courseHelper, 'AddonModChat', 'chat', 'c');
} }
} }

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,
super(courseHelper, 'AddonModData', 'data'); protected dataProvider: AddonModDataProvider) {
super(courseHelper, 'AddonModData', 'data', 'd');
}
/**
* 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

@ -24,6 +24,6 @@ export class AddonModFolderLinkHandler extends CoreContentLinksModuleIndexHandle
name = 'AddonModFolderLinkHandler'; name = 'AddonModFolderLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModFolder', 'folder'); super(courseHelper, 'AddonModFolder', 'folder', 'f');
} }
} }

View File

@ -191,8 +191,8 @@ export class AddonModForumDiscussionPage implements OnDestroy {
}); });
this.changeDiscObserver = this.eventsProvider.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, (data) => { this.changeDiscObserver = this.eventsProvider.on(AddonModForumProvider.CHANGE_DISCUSSION_EVENT, (data) => {
if ((this.forum && this.forum.id === data.forumId) || data.cmId === this.cmId) { if ((this.forumId && this.forumId === data.forumId) || data.cmId === this.cmId) {
this.forumProvider.invalidateDiscussionsList(this.forum.id).finally(() => { this.forumProvider.invalidateDiscussionsList(this.forumId).finally(() => {
if (typeof data.locked != 'undefined') { if (typeof data.locked != 'undefined') {
this.discussion.locked = data.locked; this.discussion.locked = data.locked;
} }
@ -350,7 +350,7 @@ export class AddonModForumDiscussionPage implements OnDestroy {
const promises = []; const promises = [];
promises.push(this.forumProvider.getAccessInformation(this.forum.id).then((accessInfo) => { promises.push(this.forumProvider.getAccessInformation(this.forumId).then((accessInfo) => {
this.accessInfo = accessInfo; this.accessInfo = accessInfo;
// Disallow replying if cut-off date is reached and the user has not the capability to override it. // 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. // Fetch the discussion if not passed as parameter.
if (!this.discussion) { if (!this.discussion) {
promises.push(this.forumHelper.getDiscussionById(forum.id, this.discussionId).then((discussion) => { promises.push(this.loadDiscussion(this.forumId, this.discussionId));
this.discussion = discussion;
}).catch(() => {
// Ignore errors.
}));
} }
return Promise.all(promises); 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<void> {
// 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. * Tries to synchronize the posts discussion.
* *

View File

@ -45,6 +45,12 @@ export class AddonModForumDiscussionLinkHandler extends CoreContentLinksHandlerB
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
data = data || {}; data = data || {};
if (!data.instance) {
// Without the forumId discussions cannot be loaded (from link).
return [];
}
return [{ return [{
action: (siteId, navCtrl?): void => { action: (siteId, navCtrl?): void => {
const pageParams: any = { const pageParams: any = {

View File

@ -15,10 +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 { CoreCourseProvider } from '@core/course/providers/course';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
/** /**
* Handler to treat links to forum index. * Handler to treat links to forum index.
@ -27,57 +23,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) { super(courseHelper, 'AddonModForum', 'forum', 'f');
super(courseHelper, 'AddonModForum', 'forum');
// Match the view.php URL with an id param.
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).
*
* @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<CoreContentLinksAction[]> {
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);
} }
} }

View File

@ -25,6 +25,6 @@ export class AddonModGlossaryIndexLinkHandler extends CoreContentLinksModuleInde
name = 'AddonModGlossaryIndexLinkHandler'; name = 'AddonModGlossaryIndexLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider, protected glossaryProvider: AddonModGlossaryProvider) { constructor(courseHelper: CoreCourseHelperProvider, protected glossaryProvider: AddonModGlossaryProvider) {
super(courseHelper, 'AddonModGlossary', 'glossary'); super(courseHelper, 'AddonModGlossary', 'glossary', 'g');
} }
} }

View File

@ -304,7 +304,7 @@ export class AddonModImscpProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise. * @return Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise.
*/ */
isPluginEnabled(siteId?: string): Promise<any> { isPluginEnabled(siteId?: string): Promise<boolean> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
return site.canDownloadFiles(); return site.canDownloadFiles();
}); });

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,
super(courseHelper, 'AddonModImscp', 'imscp'); protected imscpProvider: AddonModImscpProvider) {
super(courseHelper, 'AddonModImscp', 'imscp', 'i');
}
/**
* 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

@ -24,6 +24,6 @@ export class AddonModLabelLinkHandler extends CoreContentLinksModuleIndexHandler
name = 'AddonModLabelLinkHandler'; name = 'AddonModLabelLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModLabel', 'label'); super(courseHelper, 'AddonModLabel', 'label', 'l');
} }
} }

View File

@ -2775,7 +2775,7 @@ export class AddonModLessonProvider {
* @param siteId Site ID. If not defined, current site. * @param siteId Site ID. If not defined, current site.
* @return Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise. * @return Promise resolved with true if plugin is enabled, rejected or resolved with false otherwise.
*/ */
isPluginEnabled(siteId?: string): Promise<any> { isPluginEnabled(siteId?: string): Promise<boolean> {
return this.sitesProvider.getSite(siteId).then((site) => { return this.sitesProvider.getSite(siteId).then((site) => {
// All WS were introduced at the same time so checking one is enough. // All WS were introduced at the same time so checking one is enough.
return site.wsAvailable('mod_lesson_get_lesson_access_information'); return site.wsAvailable('mod_lesson_get_lesson_access_information');

View File

@ -24,6 +24,6 @@ export class AddonModLtiLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModLtiLinkHandler'; name = 'AddonModLtiLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModLti', 'lti'); super(courseHelper, 'AddonModLti', 'lti', 'l');
} }
} }

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,
super(courseHelper, 'AddonModPage', 'page'); protected pageProvider: AddonModPageProvider) {
super(courseHelper, 'AddonModPage', 'page', 'p');
}
/**
* 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

@ -25,20 +25,6 @@ export class AddonModQuizIndexLinkHandler extends CoreContentLinksModuleIndexHan
name = 'AddonModQuizIndexLinkHandler'; name = 'AddonModQuizIndexLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider, protected quizProvider: AddonModQuizProvider) { constructor(courseHelper: CoreCourseHelperProvider, protected quizProvider: AddonModQuizProvider) {
super(courseHelper, 'AddonModQuiz', 'quiz'); super(courseHelper, 'AddonModQuiz', 'quiz', 'q');
}
/**
* 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,
super(courseHelper, 'AddonModResource', 'resource'); protected resourceProvider: AddonModResourceProvider) {
super(courseHelper, 'AddonModResource', 'resource', 'r');
}
/**
* 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,6 +24,6 @@ export class AddonModScormIndexLinkHandler extends CoreContentLinksModuleIndexHa
name = 'AddonModScormIndexLinkHandler'; name = 'AddonModScormIndexLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModScorm', 'scorm'); super(courseHelper, 'AddonModScorm', 'scorm', 'a');
} }
} }

View File

@ -25,6 +25,6 @@ export class AddonModUrlLinkHandler extends CoreContentLinksModuleIndexHandler {
useModNameToGetModule = true; useModNameToGetModule = true;
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModUrl', 'url'); super(courseHelper, 'AddonModUrl', 'url', 'u');
} }
} }

View File

@ -24,6 +24,6 @@ export class AddonModWikiIndexLinkHandler extends CoreContentLinksModuleIndexHan
name = 'AddonModWikiIndexLinkHandler'; name = 'AddonModWikiIndexLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) { constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModWiki', 'wiki'); super(courseHelper, 'AddonModWiki', 'wiki', 'wid');
} }
} }

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,
super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop'); protected workshopProvider: AddonModWorkshopProvider) {
super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop', 'w');
}
/**
* 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);
} }
} }

View File

@ -15,6 +15,8 @@
import { CoreContentLinksAction } from '../providers/delegate'; import { CoreContentLinksAction } from '../providers/delegate';
import { CoreContentLinksHandlerBase } from './base-handler'; import { CoreContentLinksHandlerBase } from './base-handler';
import { CoreCourseHelperProvider } from '@core/course/providers/helper'; 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. * 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 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 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 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(); 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. // 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; 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.
*/
getPageParams(url: string, params: any, courseId?: number): any {
return undefined;
}
/** /**
* Get the list of actions for a link (url). * Get the list of actions for a link (url).
* *
@ -55,11 +75,23 @@ export class CoreContentLinksModuleIndexHandler extends CoreContentLinksHandlerB
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
courseId = courseId || params.courseid || params.cid; courseId = courseId || params.courseid || params.cid;
const pageParams = this.getPageParams(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, pageParams, navCtrl);
}
}];
}
return [{ return [{
action: (siteId, navCtrl?): void => { action: (siteId, navCtrl?): void => {
this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined, this.courseHelper.navigateToModule(parseInt(params.id, 10), siteId, courseId, undefined,
this.useModNameToGetModule ? this.modName : undefined, undefined, navCtrl); this.useModNameToGetModule ? this.modName : undefined, pageParams, navCtrl);
} }
}]; }];
} }

View File

@ -1114,6 +1114,37 @@ export class CoreCourseHelperProvider {
return 'Section-' + section.id; 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<void> {
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. * Navigate to a module.
* *
@ -1166,13 +1197,6 @@ export class CoreCourseHelperProvider {
// Get the module. // Get the module.
return this.courseProvider.getModule(moduleId, courseId, sectionId, false, false, siteId, modName); return this.courseProvider.getModule(moduleId, courseId, sectionId, false, false, siteId, modName);
}).then((module) => { }).then((module) => {
const params = {
course: { id: courseId },
module: module,
sectionId: sectionId,
modParams: modParams
};
module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId); module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId);
if (navCtrl && module.handlerData && module.handlerData.action) { if (navCtrl && module.handlerData && module.handlerData.action) {
@ -1180,11 +1204,18 @@ export class CoreCourseHelperProvider {
// Otherwise, we will redirect below. // Otherwise, we will redirect below.
modal.dismiss(); 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); 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()) { if (courseId == site.getSiteHomeId()) {
// Check if site home is available. // Check if site home is available.
return this.siteHomeProvider.isAvailable().then(() => { return this.siteHomeProvider.isAvailable().then(() => {