MOBILE-2824 course: Allow passing params when navigate to module

main
Dani Palou 2019-01-22 12:20:04 +01:00
parent fe25e65039
commit dde19b17a6
24 changed files with 137 additions and 48 deletions

View File

@ -68,8 +68,12 @@ export class AddonModAssignModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_assign-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModAssignIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModAssignIndexPage', pageParams, options);
}
};
}

View File

@ -65,8 +65,12 @@ export class AddonModBookModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_book-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModBookIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModBookIndexPage', pageParams, options);
}
};
}

View File

@ -62,8 +62,12 @@ export class AddonModChatModuleHandler implements CoreCourseModuleHandler {
icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon),
title: module.name,
class: 'addon-mod_chat-handler',
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModChatIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModChatIndexPage', pageParams, options);
}
};
}

View File

@ -64,8 +64,12 @@ export class AddonModChoiceModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_choice-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModChoiceIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModChoiceIndexPage', pageParams, options);
}
};
}

View File

@ -67,8 +67,12 @@ export class AddonModDataModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_data-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModDataIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModDataIndexPage', pageParams, options);
}
};
}

View File

@ -65,8 +65,12 @@ export class AddonModFeedbackModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_feedback-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModFeedbackIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModFeedbackIndexPage', pageParams, options);
}
};
}

View File

@ -64,8 +64,12 @@ export class AddonModFolderModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_folder-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModFolderIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModFolderIndexPage', pageParams, options);
}
};
}

View File

@ -72,8 +72,12 @@ export class AddonModForumModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_forum-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModForumIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModForumIndexPage', pageParams, options);
}
};

View File

@ -66,8 +66,12 @@ export class AddonModGlossaryModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_glossary-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModGlossaryIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModGlossaryIndexPage', pageParams, options);
}
};
}

View File

@ -65,8 +65,12 @@ export class AddonModImscpModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_imscp-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModImscpIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModImscpIndexPage', pageParams, options);
}
};
}

View File

@ -65,8 +65,12 @@ export class AddonModLessonModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_lesson-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModLessonIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModLessonIndexPage', pageParams, options);
}
};
}

View File

@ -74,8 +74,12 @@ export class AddonModLtiModuleHandler implements CoreCourseModuleHandler {
icon: this.courseProvider.getModuleIconSrc(this.modName, module.modicon),
title: module.name,
class: 'addon-mod_lti-handler',
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModLtiIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModLtiIndexPage', pageParams, options);
},
buttons: [{
icon: 'link',

View File

@ -65,8 +65,12 @@ export class AddonModPageModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_page-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModPageIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModPageIndexPage', pageParams, options);
}
};
}

View File

@ -66,8 +66,12 @@ export class AddonModQuizModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_quiz-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModQuizIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModQuizIndexPage', pageParams, options);
}
};
}

View File

@ -82,8 +82,12 @@ export class AddonModResourceModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_resource-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModResourceIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModResourceIndexPage', pageParams, options);
},
updateStatus: updateStatus.bind(this),
buttons: [ {

View File

@ -64,8 +64,12 @@ export class AddonModScormModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_scorm-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModScormIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModScormIndexPage', pageParams, options);
}
};
}

View File

@ -64,8 +64,12 @@ export class AddonModSurveyModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_survey-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModSurveyIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModSurveyIndexPage', pageParams, options);
}
};
}

View File

@ -72,7 +72,7 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_url-handler',
showDownloadButton: false,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const modal = handler.domUtils.showModalLoading();
// First of all, check if the URL can be handled by the app. If so, always open it directly.
@ -100,7 +100,11 @@ export class AddonModUrlModuleHandler implements CoreCourseModuleHandler {
if (shouldOpen) {
handler.openUrl(module, courseId);
} else {
navCtrl.push('AddonModUrlIndexPage', {module: module, courseId: courseId}, options);
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModUrlIndexPage', pageParams, options);
}
}).finally(() => {
modal.dismiss();

View File

@ -65,8 +65,12 @@ export class AddonModWikiModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_wiki-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModWikiIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModWikiIndexPage', pageParams, options);
}
};
}

View File

@ -64,8 +64,12 @@ export class AddonModWorkshopModuleHandler implements CoreCourseModuleHandler {
title: module.name,
class: 'addon-mod_workshop-handler',
showDownloadButton: true,
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions): void {
navCtrl.push('AddonModWorkshopIndexPage', {module: module, courseId: courseId}, options);
action(event: Event, navCtrl: NavController, module: any, courseId: number, options: NavOptions, params?: any): void {
const pageParams = {module: module, courseId: courseId};
if (params) {
Object.assign(pageParams, params);
}
navCtrl.push('AddonModWorkshopIndexPage', pageParams, options);
}
};
}

View File

@ -62,6 +62,7 @@ export class CoreCourseSectionPage implements OnDestroy {
displayRefresher: boolean;
protected module: any;
protected modParams: any;
protected completionObserver;
protected courseStatusObserver;
protected syncObserver;
@ -80,6 +81,7 @@ export class CoreCourseSectionPage implements OnDestroy {
this.sectionNumber = navParams.get('sectionNumber');
this.module = navParams.get('module');
this.firstTabName = navParams.get('selectedTab');
this.modParams = navParams.get('modParams');
// Get the title to display. We dont't have sections yet.
this.title = courseFormatDelegate.getCourseTitle(this.course);
@ -124,7 +126,7 @@ export class CoreCourseSectionPage implements OnDestroy {
if (this.module) {
this.moduleId = this.module.id;
this.courseHelper.openModule(this.navCtrl, this.module, this.course.id, this.sectionId);
this.courseHelper.openModule(this.navCtrl, this.module, this.course.id, this.sectionId, this.modParams);
}
this.loadData(false, true).finally(() => {

View File

@ -1007,9 +1007,11 @@ export class CoreCourseHelperProvider {
* @param {number} [sectionId] Section the module belongs to. If not defined we'll try to retrieve it from the site.
* @param {string} [modName] If set, 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 {any} [modParams] Params to pass to the module
* @return {Promise<void>} Promise resolved when done.
*/
navigateToModule(moduleId: number, siteId?: string, courseId?: number, sectionId?: number, modName?: string): Promise<void> {
navigateToModule(moduleId: number, siteId?: string, courseId?: number, sectionId?: number, modName?: string, modParams?: any)
: Promise<void> {
siteId = siteId || this.sitesProvider.getCurrentSiteId();
const modal = this.domUtils.showModalLoading();
@ -1048,7 +1050,8 @@ export class CoreCourseHelperProvider {
const params = {
course: { id: courseId },
module: module,
sectionId: sectionId
sectionId: sectionId,
modParams: modParams
};
module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId);
@ -1075,15 +1078,16 @@ export class CoreCourseHelperProvider {
* @param {any} module The module to open.
* @param {number} courseId The course ID of the module.
* @param {number} [sectionId] The section ID of the module.
* @param {any} [modParams] Params to pass to the module
* @param {boolean} True if module can be opened, false otherwise.
*/
openModule(navCtrl: NavController, module: any, courseId: number, sectionId?: number): boolean {
openModule(navCtrl: NavController, module: any, courseId: number, sectionId?: number, modParams?: any): boolean {
if (!module.handlerData) {
module.handlerData = this.moduleDelegate.getModuleDataFor(module.modname, module, courseId, sectionId);
}
if (module.handlerData && module.handlerData.action) {
module.handlerData.action(new Event('click'), navCtrl, module, courseId, { animate: false });
module.handlerData.action(new Event('click'), navCtrl, module, courseId, { animate: false }, modParams);
return true;
}

View File

@ -156,8 +156,9 @@ export interface CoreCourseModuleHandlerData {
* @param {any} module The module object.
* @param {number} courseId The course ID.
* @param {NavOptions} [options] Options for the navigation.
* @param {any} [params] Params for the new page.
*/
action?(event: Event, navCtrl: NavController, module: any, courseId: number, options?: NavOptions): void;
action?(event: Event, navCtrl: NavController, module: any, courseId: number, options?: NavOptions, params?: any): void;
/**
* Updates the status of the module.

View File

@ -31,9 +31,11 @@ export class CoreSiteHomeIndexPage {
constructor(navParams: NavParams, navCtrl: NavController, courseHelper: CoreCourseHelperProvider,
sitesProvider: CoreSitesProvider) {
const module = navParams.get('module');
const module = navParams.get('module'),
modParams = navParams.get('modParams');
if (module) {
courseHelper.openModule(navCtrl, module, sitesProvider.getCurrentSite().getSiteHomeId());
courseHelper.openModule(navCtrl, module, sitesProvider.getCurrentSite().getSiteHomeId(), undefined, modParams);
}
}
}