MOBILE-3218 course: Add general navigation to module by instance
parent
a6432ad7b7
commit
ed1fc4c09d
|
@ -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.
|
||||||
|
*/
|
||||||
|
getModParams(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 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 [{
|
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, modParams, navCtrl);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue