MOBILE-4627 page: Don't download all files when opening
This commit is contained in:
		
							parent
							
								
									330b702cad
								
							
						
					
					
						commit
						8c566af484
					
				| @ -12,13 +12,6 @@ | |||||||
|     <core-course-module-info [module]="module" [description]="displayDescription && description" [component]="component" |     <core-course-module-info [module]="module" [description]="displayDescription && description" [component]="component" | ||||||
|         [componentId]="componentId" [courseId]="courseId" (completionChanged)="onCompletionChange()" /> |         [componentId]="componentId" [courseId]="courseId" (completionChanged)="onCompletionChange()" /> | ||||||
| 
 | 
 | ||||||
|     <ion-card class="core-warning-card" *ngIf="warning"> |  | ||||||
|         <ion-item> |  | ||||||
|             <ion-icon name="fas-triangle-exclamation" slot="start" aria-hidden="true" /> |  | ||||||
|             <ion-label><span [innerHTML]="warning"></span></ion-label> |  | ||||||
|         </ion-item> |  | ||||||
|     </ion-card> |  | ||||||
| 
 |  | ||||||
|     <div class="ion-padding"> |     <div class="ion-padding"> | ||||||
|         <core-format-text [component]="component" [componentId]="componentId" [text]="contents" contextLevel="module" |         <core-format-text [component]="component" [componentId]="componentId" [text]="contents" contextLevel="module" | ||||||
|             [contextInstanceId]="module.id" [courseId]="courseId" /> |             [contextInstanceId]="module.id" [courseId]="courseId" /> | ||||||
|  | |||||||
| @ -15,7 +15,6 @@ | |||||||
| import { Component, OnInit, Optional } from '@angular/core'; | import { Component, OnInit, Optional } from '@angular/core'; | ||||||
| import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component'; | import { CoreCourseModuleMainResourceComponent } from '@features/course/classes/main-resource-component'; | ||||||
| import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; | import { CoreCourseContentsPage } from '@features/course/pages/contents/contents'; | ||||||
| import { CoreCourse } from '@features/course/services/course'; |  | ||||||
| import { CoreTextUtils } from '@services/utils/text'; | import { CoreTextUtils } from '@services/utils/text'; | ||||||
| import { CoreUtils } from '@services/utils/utils'; | import { CoreUtils } from '@services/utils/utils'; | ||||||
| import { AddonModPagePage, AddonModPage } from '../../services/page'; | import { AddonModPagePage, AddonModPage } from '../../services/page'; | ||||||
| @ -38,7 +37,6 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp | |||||||
|     displayTimemodified = true; |     displayTimemodified = true; | ||||||
|     timemodified?: number; |     timemodified?: number; | ||||||
|     page?: AddonModPagePage; |     page?: AddonModPagePage; | ||||||
|     warning?: string; |  | ||||||
| 
 | 
 | ||||||
|     protected fetchContentDefaultError = 'addon.mod_page.errorwhileloadingthepage'; |     protected fetchContentDefaultError = 'addon.mod_page.errorwhileloadingthepage'; | ||||||
| 
 | 
 | ||||||
| @ -68,19 +66,12 @@ export class AddonModPageIndexComponent extends CoreCourseModuleMainResourceComp | |||||||
|      * @inheritdoc |      * @inheritdoc | ||||||
|      */ |      */ | ||||||
|     protected async fetchContent(refresh?: boolean): Promise<void> { |     protected async fetchContent(refresh?: boolean): Promise<void> { | ||||||
|         // Download the resource if it needs to be downloaded.
 |         const [contents] = await Promise.all([ | ||||||
|         const downloadResult = await this.downloadResourceIfNeeded(refresh); |             this.getModuleContents(refresh), | ||||||
| 
 |  | ||||||
|         // Get contents. No need to refresh, it has been done in downloadResourceIfNeeded.
 |  | ||||||
|         const contents = await CoreCourse.getModuleContents(this.module); |  | ||||||
| 
 |  | ||||||
|         const results = await Promise.all([ |  | ||||||
|             this.loadPageData(), |             this.loadPageData(), | ||||||
|             AddonModPageHelper.getPageHtml(contents, this.module.id), |  | ||||||
|         ]); |         ]); | ||||||
| 
 | 
 | ||||||
|         this.contents = results[1]; |         this.contents = await AddonModPageHelper.getPageHtml(contents, this.module.id); | ||||||
|         this.warning = downloadResult?.failed ? this.getErrorDownloadingSomeFilesMessage(downloadResult.error!) : ''; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
| @ -26,7 +26,7 @@ import { CoreEventObserver, CoreEvents } from '@singletons/events'; | |||||||
| import { CoreLogger } from '@singletons/logger'; | import { CoreLogger } from '@singletons/logger'; | ||||||
| import { CoreCourseModuleSummaryResult } from '../components/module-summary/module-summary'; | import { CoreCourseModuleSummaryResult } from '../components/module-summary/module-summary'; | ||||||
| import { CoreCourseContentsPage } from '../pages/contents/contents'; | import { CoreCourseContentsPage } from '../pages/contents/contents'; | ||||||
| import { CoreCourse } from '../services/course'; | import { CoreCourse, CoreCourseModuleContentFile } from '../services/course'; | ||||||
| import { CoreCourseHelper, CoreCourseModuleData } from '../services/course-helper'; | import { CoreCourseHelper, CoreCourseModuleData } from '../services/course-helper'; | ||||||
| import { CoreCourseModuleDelegate, CoreCourseModuleMainComponent } from '../services/module-delegate'; | import { CoreCourseModuleDelegate, CoreCourseModuleMainComponent } from '../services/module-delegate'; | ||||||
| import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-delegate'; | import { CoreCourseModulePrefetchDelegate } from '../services/module-prefetch-delegate'; | ||||||
| @ -364,24 +364,36 @@ export class CoreCourseModuleMainResourceComponent implements OnInit, OnDestroy, | |||||||
| 
 | 
 | ||||||
|         if (!this.module.contents?.length || (refresh && !contentsAlreadyLoaded)) { |         if (!this.module.contents?.length || (refresh && !contentsAlreadyLoaded)) { | ||||||
|             // Try to load the contents.
 |             // Try to load the contents.
 | ||||||
|             const ignoreCache = refresh && CoreNetwork.isOnline(); |             await this.getModuleContents(refresh); | ||||||
| 
 |  | ||||||
|             try { |  | ||||||
|                 await CoreCourse.loadModuleContents(this.module, undefined, undefined, false, ignoreCache); |  | ||||||
|             } catch (error) { |  | ||||||
|                 // Error loading contents. If we ignored cache, try to get the cached value.
 |  | ||||||
|                 if (ignoreCache && !this.module.contents) { |  | ||||||
|                     await CoreCourse.loadModuleContents(this.module); |  | ||||||
|                 } else if (!this.module.contents) { |  | ||||||
|                     // Not able to load contents, throw the error.
 |  | ||||||
|                     throw error; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * Get module contents. | ||||||
|  |      * | ||||||
|  |      * @param refresh Whether we're refreshing data. | ||||||
|  |      * @returns Module contents. | ||||||
|  |      */ | ||||||
|  |     protected async getModuleContents(refresh?: boolean): Promise<CoreCourseModuleContentFile[]> { | ||||||
|  |         const ignoreCache = refresh && CoreNetwork.isOnline(); | ||||||
|  | 
 | ||||||
|  |         try { | ||||||
|  |             return await CoreCourse.getModuleContents(this.module, undefined, undefined, false, ignoreCache); | ||||||
|  |         } catch (error) { | ||||||
|  |             // Error loading contents. If we ignored cache, try to get the cached value.
 | ||||||
|  |             if (ignoreCache && !this.module.contents) { | ||||||
|  |                 return await CoreCourse.getModuleContents(this.module); | ||||||
|  |             } else if (!this.module.contents) { | ||||||
|  |                 // Not able to load contents, throw the error.
 | ||||||
|  |                 throw error; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             return this.module.contents; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * The completion of the modules has changed. |      * The completion of the modules has changed. | ||||||
|      * |      * | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user