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 { 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,30 +24,33 @@ import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
export class AddonModBookLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModBookLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModBook', 'book');
constructor(courseHelper: CoreCourseHelperProvider,
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 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.
* @return List of params to pass to navigateToModule / navigateToModuleByInstance.
*/
getActions(siteIds: string[], url: string, params: any, courseId?: number):
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
getPageParams(url: string, params: any, courseId?: number): any {
return params.chapterid ? {chapterId: parseInt(params.chapterid, 10)} : undefined;
}
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);
}
}];
/**
* 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

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

View File

@ -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) {
super(courseHelper, 'AddonModData', 'data');
constructor(courseHelper: CoreCourseHelperProvider,
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 { 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<boolean> {
return this.feedbackProvider.isPluginEnabled();
}
}

View File

@ -24,6 +24,6 @@ export class AddonModFolderLinkHandler extends CoreContentLinksModuleIndexHandle
name = 'AddonModFolderLinkHandler';
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) => {
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<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.
*

View File

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

View File

@ -15,10 +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';
/**
* Handler to treat links to forum index.
@ -27,57 +23,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
export class AddonModForumIndexLinkHandler extends CoreContentLinksModuleIndexHandler {
name = 'AddonModForumIndexLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider, protected forumProvider: AddonModForumProvider,
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+)');
}
/**
* 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);
constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, 'AddonModForum', 'forum', 'f');
}
}

View File

@ -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');
}
}

View File

@ -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<any> {
isPluginEnabled(siteId?: string): Promise<boolean> {
return this.sitesProvider.getSite(siteId).then((site) => {
return site.canDownloadFiles();
});

View File

@ -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) {
super(courseHelper, 'AddonModImscp', 'imscp');
constructor(courseHelper: CoreCourseHelperProvider,
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';
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.
* @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) => {
// All WS were introduced at the same time so checking one is enough.
return site.wsAvailable('mod_lesson_get_lesson_access_information');

View File

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

View File

@ -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) {
super(courseHelper, 'AddonModPage', 'page');
constructor(courseHelper: CoreCourseHelperProvider,
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';
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<boolean> {
return this.quizProvider.isPluginEnabled();
super(courseHelper, 'AddonModQuiz', 'quiz', 'q');
}
}

View File

@ -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) {
super(courseHelper, 'AddonModResource', 'resource');
constructor(courseHelper: CoreCourseHelperProvider,
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';
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;
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';
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 {
name = 'AddonModWorkshopLinkHandler';
constructor(courseHelper: CoreCourseHelperProvider) {
super(courseHelper, AddonModWorkshopProvider.COMPONENT, 'workshop');
constructor(courseHelper: CoreCourseHelperProvider,
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 { 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.
*/
getPageParams(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<CoreContentLinksAction[]> {
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 [{
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, pageParams, navCtrl);
}
}];
}

View File

@ -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<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.
*
@ -1166,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) {
@ -1180,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(() => {