forked from CIT/Vmeda.Online
		
	Merge pull request #2551 from crazyserver/MOBILE-3523
MOBILE-3469 course: Get course data when entering from search
This commit is contained in:
		
						commit
						ad2b5c4529
					
				| @ -28,7 +28,7 @@ import { CoreCourseOfflineProvider } from './course-offline'; | |||||||
| import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins'; | import { CoreSitePluginsProvider } from '@core/siteplugins/providers/siteplugins'; | ||||||
| import { CoreCourseFormatDelegate } from './format-delegate'; | import { CoreCourseFormatDelegate } from './format-delegate'; | ||||||
| import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; | import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications'; | ||||||
| import { CoreCoursesProvider } from '@core/courses/providers/courses'; | import { CoreCoursesProvider, CoreCourses } from '@core/courses/providers/courses'; | ||||||
| import { makeSingleton } from '@singletons/core.singletons'; | import { makeSingleton } from '@singletons/core.singletons'; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -978,19 +978,47 @@ export class CoreCourseProvider { | |||||||
|      * @param params Other params to pass to the course page. |      * @param params Other params to pass to the course page. | ||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     openCourse(navCtrl: NavController, course: any, params?: any): Promise<any> { |     async openCourse(navCtrl: NavController, course: any, params?: any): Promise<void> { | ||||||
|         const loading = this.domUtils.showModalLoading(); |         const loading = this.domUtils.showModalLoading(); | ||||||
| 
 | 
 | ||||||
|         // Wait for site plugins to be fetched.
 |         // Wait for site plugins to be fetched.
 | ||||||
|         return this.sitePluginsProvider.waitFetchPlugins().then(() => { |         await this.sitePluginsProvider.waitFetchPlugins(); | ||||||
|             if (this.sitePluginsProvider.sitePluginPromiseExists('format_' + course.format)) { |  | ||||||
|                 // This course uses a custom format plugin, wait for the format plugin to finish loading.
 |  | ||||||
| 
 | 
 | ||||||
|                 return this.sitePluginsProvider.sitePluginLoaded('format_' + course.format).then(() => { |         if (typeof course.format == 'undefined') { | ||||||
|  |             const coursesProvider = CoreCourses.instance; | ||||||
|  |             try { | ||||||
|  |                 course = await coursesProvider.getUserCourse(course.id, true); | ||||||
|  |             } catch (error) { | ||||||
|  |                 // Not enrolled or an error happened. Try to use another WebService.
 | ||||||
|  |                 const available = coursesProvider.isGetCoursesByFieldAvailableInSite(); | ||||||
|  |                 try { | ||||||
|  |                     if (available) { | ||||||
|  |                         course = await CoreCourses.instance.getCourseByField('id', course.id); | ||||||
|  |                     } else { | ||||||
|  |                         course = await CoreCourses.instance.getCourse(course.id); | ||||||
|  |                     } | ||||||
|  |                 } catch (error) { | ||||||
|  |                     // Ignore errors.
 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (!this.sitePluginsProvider.sitePluginPromiseExists('format_' + course.format)) { | ||||||
|  |             // No custom format plugin. We don't need to wait for anything.
 | ||||||
|  |             await this.courseFormatDelegate.openCourse(navCtrl, course, params); | ||||||
|  |             loading.dismiss(); | ||||||
|  | 
 | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // This course uses a custom format plugin, wait for the format plugin to finish loading.
 | ||||||
|  |         try { | ||||||
|  |             await this.sitePluginsProvider.sitePluginLoaded('format_' + course.format); | ||||||
|             // The format loaded successfully, but the handlers wont be registered until all site plugins have loaded.
 |             // The format loaded successfully, but the handlers wont be registered until all site plugins have loaded.
 | ||||||
|             if (this.sitePluginsProvider.sitePluginsFinishedLoading) { |             if (this.sitePluginsProvider.sitePluginsFinishedLoading) { | ||||||
|                 return this.courseFormatDelegate.openCourse(navCtrl, course, params); |                 return this.courseFormatDelegate.openCourse(navCtrl, course, params); | ||||||
|                     } else { |             } | ||||||
|  | 
 | ||||||
|             // Wait for plugins to be loaded.
 |             // Wait for plugins to be loaded.
 | ||||||
|             const deferred = this.utils.promiseDefer(), |             const deferred = this.utils.promiseDefer(), | ||||||
|                 observer = this.eventsProvider.on(CoreEventsProvider.SITE_PLUGINS_LOADED, () => { |                 observer = this.eventsProvider.on(CoreEventsProvider.SITE_PLUGINS_LOADED, () => { | ||||||
| @ -1004,8 +1032,7 @@ export class CoreCourseProvider { | |||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|             return deferred.promise; |             return deferred.promise; | ||||||
|                     } |         } catch (error) { | ||||||
|                 }).catch(() => { |  | ||||||
|             // The site plugin failed to load. The user needs to restart the app to try loading it again.
 |             // The site plugin failed to load. The user needs to restart the app to try loading it again.
 | ||||||
|             const message = this.translate.instant('core.courses.errorloadplugins'); |             const message = this.translate.instant('core.courses.errorloadplugins'); | ||||||
|             const reload = this.translate.instant('core.courses.reload'); |             const reload = this.translate.instant('core.courses.reload'); | ||||||
| @ -1013,14 +1040,7 @@ export class CoreCourseProvider { | |||||||
|             this.domUtils.showConfirm(message, '', reload, ignore).then(() => { |             this.domUtils.showConfirm(message, '', reload, ignore).then(() => { | ||||||
|                 window.location.reload(); |                 window.location.reload(); | ||||||
|             }); |             }); | ||||||
|                 }); |  | ||||||
|             } else { |  | ||||||
|                 // No custom format plugin. We don't need to wait for anything.
 |  | ||||||
|                 return this.courseFormatDelegate.openCourse(navCtrl, course, params); |  | ||||||
|         } |         } | ||||||
|         }).finally(() => { |  | ||||||
|             loading.dismiss(); |  | ||||||
|         }); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -172,7 +172,7 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { | |||||||
|      * @param params Params to pass to the course page. |      * @param params Params to pass to the course page. | ||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     openCourse(navCtrl: NavController, course: any, params?: any): Promise<any> { |     openCourse(navCtrl: NavController, course: any, params?: any): Promise<void> { | ||||||
|         params = params || {}; |         params = params || {}; | ||||||
|         Object.assign(params, { course: course }); |         Object.assign(params, { course: course }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -102,7 +102,7 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler { | |||||||
|      * @param params Params to pass to the course page. |      * @param params Params to pass to the course page. | ||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     openCourse?(navCtrl: NavController, course: any, params?: any): Promise<any>; |     openCourse?(navCtrl: NavController, course: any, params?: any): Promise<void>; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Return the Component to use to display the course format instead of using the default one. |      * Return the Component to use to display the course format instead of using the default one. | ||||||
| @ -351,14 +351,14 @@ export class CoreCourseFormatDelegate extends CoreDelegate { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Open a course. |      * Open a course. Should not be called directly. Call CoreCourseHelper.openCourse instead. | ||||||
|      * |      * | ||||||
|      * @param navCtrl The NavController instance to use. |      * @param navCtrl The NavController instance to use. | ||||||
|      * @param course The course to open. It should contain a "format" attribute. |      * @param course The course to open. It should contain a "format" attribute. | ||||||
|      * @param params Params to pass to the course page. |      * @param params Params to pass to the course page. | ||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     openCourse(navCtrl: NavController, course: any, params?: any): Promise<any> { |     openCourse(navCtrl: NavController, course: any, params?: any): Promise<void> { | ||||||
|         return this.executeFunctionOnEnabled(course.format, 'openCourse', [navCtrl, course, params]); |         return this.executeFunctionOnEnabled(course.format, 'openCourse', [navCtrl, course, params]); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1601,7 +1601,7 @@ export class CoreCourseHelperProvider { | |||||||
|      * @param siteId Site ID. If not defined, current site. |      * @param siteId Site ID. If not defined, current site. | ||||||
|      * @return Promise resolved when done. |      * @return Promise resolved when done. | ||||||
|      */ |      */ | ||||||
|     openCourse(navCtrl: NavController, course: any, params?: any, siteId?: string): Promise<any> { |     openCourse(navCtrl: NavController, course: any, params?: any, siteId?: string): Promise<void> { | ||||||
|         if (!siteId || siteId == this.sitesProvider.getCurrentSiteId()) { |         if (!siteId || siteId == this.sitesProvider.getCurrentSiteId()) { | ||||||
|             // Current site, we can open the course.
 |             // Current site, we can open the course.
 | ||||||
|             return this.courseProvider.openCourse(navCtrl, course, params); |             return this.courseProvider.openCourse(navCtrl, course, params); | ||||||
|  | |||||||
| @ -259,7 +259,7 @@ export class CoreCoursesCoursePreviewPage implements OnDestroy { | |||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.courseFormatDelegate.openCourse(this.navCtrl, this.course); |         this.courseHelper.openCourse(this.navCtrl, this.course); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user