forked from CIT/Vmeda.Online
		
	MOBILE-2431 courses: Fix course options not available
This commit is contained in:
		
							parent
							
								
									11013c69ab
								
							
						
					
					
						commit
						10da720a4a
					
				| @ -395,7 +395,9 @@ export class CoreCourseOptionsDelegate extends CoreDelegate { | ||||
|      * @return {Promise<void>} Promise resolved when done. | ||||
|      */ | ||||
|     protected loadCourseOptions(course: any, refresh?: boolean): Promise<void> { | ||||
|         if (typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh) { | ||||
|         if (this.coursesProvider.canGetAdminAndNavOptions() && | ||||
|                 (typeof course.navOptions == 'undefined' || typeof course.admOptions == 'undefined' || refresh)) { | ||||
| 
 | ||||
|             return this.coursesProvider.getCoursesAdminAndNavOptions([course.id]).then((options) => { | ||||
|                 course.navOptions = options.navOptions[course.id]; | ||||
|                 course.admOptions = options.admOptions[course.id]; | ||||
|  | ||||
| @ -111,12 +111,14 @@ export class CoreCoursesMyCoursesPage implements OnDestroy { | ||||
|                 })); | ||||
|             } | ||||
| 
 | ||||
|             if (this.coursesProvider.canGetAdminAndNavOptions()) { | ||||
|                 promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => { | ||||
|                     courses.forEach((course) => { | ||||
|                         course.navOptions = options.navOptions[course.id]; | ||||
|                         course.admOptions = options.admOptions[course.id]; | ||||
|                     }); | ||||
|                 })); | ||||
|             } | ||||
| 
 | ||||
|             return Promise.all(promises).then(() => { | ||||
|                 this.courses = courses; | ||||
|  | ||||
| @ -223,6 +223,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy { | ||||
|                 return course.id; | ||||
|             }); | ||||
| 
 | ||||
|             if (this.coursesProvider.canGetAdminAndNavOptions()) { | ||||
|                 // Load course options of the course.
 | ||||
|                 promises.push(this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => { | ||||
|                     courses.forEach((course) => { | ||||
| @ -230,6 +231,7 @@ export class CoreCoursesMyOverviewPage implements OnDestroy { | ||||
|                         course.admOptions = options.admOptions[course.id]; | ||||
|                     }); | ||||
|                 })); | ||||
|             } | ||||
| 
 | ||||
|             this.courseIds = courseIds.join(','); | ||||
| 
 | ||||
|  | ||||
| @ -33,6 +33,16 @@ export class CoreCoursesProvider { | ||||
|         this.logger = logger.getInstance('CoreCoursesProvider'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Whether current site supports getting course options. | ||||
|      * | ||||
|      * @return {boolean} Whether current site supports getting course options. | ||||
|      */ | ||||
|     canGetAdminAndNavOptions(): boolean { | ||||
|         return this.sitesProvider.wsAvailableInCurrentSite('core_course_get_user_navigation_options') && | ||||
|                 this.sitesProvider.wsAvailableInCurrentSite('core_course_get_user_administration_options'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get categories. They can be filtered by id. | ||||
|      * | ||||
|  | ||||
| @ -213,21 +213,33 @@ export class CoreUserDelegate extends CoreDelegate { | ||||
|      * @return {Subject<CoreUserProfileHandlerToDisplay[]>} Resolved with the handlers. | ||||
|      */ | ||||
|     getProfileHandlersFor(user: any, courseId: number): Subject<CoreUserProfileHandlerToDisplay[]> { | ||||
|         const promises = []; | ||||
|         let promise, | ||||
|             navOptions, | ||||
|             admOptions; | ||||
| 
 | ||||
|         this.userHandlers = []; | ||||
| 
 | ||||
|         // Retrieve course options forcing cache.
 | ||||
|         this.coursesProvider.getUserCourses(true).then((courses) => { | ||||
|         if (this.coursesProvider.canGetAdminAndNavOptions()) { | ||||
|             // Get course options.
 | ||||
|             promise = this.coursesProvider.getUserCourses(true).then((courses) => { | ||||
|                 const courseIds = courses.map((course) => { | ||||
|                     return course.id; | ||||
|                 }); | ||||
| 
 | ||||
|                 return this.coursesProvider.getCoursesAdminAndNavOptions(courseIds).then((options) => { | ||||
|                     // For backwards compatibility we don't modify the courseId.
 | ||||
|                 const courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId(), | ||||
|                     navOptions = options.navOptions[courseIdForOptions], | ||||
|                     const courseIdForOptions = courseId || this.sitesProvider.getCurrentSiteHomeId(); | ||||
| 
 | ||||
|                     navOptions = options.navOptions[courseIdForOptions]; | ||||
|                     admOptions = options.admOptions[courseIdForOptions]; | ||||
|                 }); | ||||
|             }); | ||||
|         } else { | ||||
|             promise = Promise.resolve(); | ||||
|         } | ||||
| 
 | ||||
|         this.userHandlers = []; | ||||
| 
 | ||||
|         promise.then(() => { | ||||
|             const promises = []; | ||||
| 
 | ||||
|             for (const name in this.enabledHandlers) { | ||||
|                 // Checks if the handler is enabled for the user.
 | ||||
| @ -258,7 +270,6 @@ export class CoreUserDelegate extends CoreDelegate { | ||||
|                 this.loaded = true; | ||||
|                 this.observableHandlers.next(this.userHandlers); | ||||
|             }); | ||||
|             }); | ||||
|         }).catch(() => { | ||||
|             // Never fails.
 | ||||
|             this.loaded = true; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user