forked from EVOgeek/Vmeda.Online
		
	Merge pull request #3034 from NoelDeMartin/MOBILE-3833
MOBILE-3833: Fix navigation & prefetch handlers
This commit is contained in:
		
						commit
						5af14b7f2e
					
				| @ -24,29 +24,8 @@ export class AddonModForumDiscussionsSwipeManager | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async navigateToNextItem(): Promise<void> { | ||||
|         let delta = -1; | ||||
|         const item = await this.getItemBy(-1); | ||||
| 
 | ||||
|         if (item && this.getSource().isNewDiscussionForm(item)) { | ||||
|             delta--; | ||||
|         } | ||||
| 
 | ||||
|         await this.navigateToItemBy(delta, 'back'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async navigateToPreviousItem(): Promise<void> { | ||||
|         let delta = 1; | ||||
|         const item = await this.getItemBy(1); | ||||
| 
 | ||||
|         if (item && this.getSource().isNewDiscussionForm(item)) { | ||||
|             delta++; | ||||
|         } | ||||
| 
 | ||||
|         await this.navigateToItemBy(delta, 'forward'); | ||||
|     protected skipItemInSwipe(item: AddonModForumDiscussionItem): boolean { | ||||
|         return this.getSource().isNewDiscussionForm(item); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -131,6 +131,7 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource< | ||||
|      */ | ||||
|     startSearch(): void { | ||||
|         this.isSearch = true; | ||||
|         this.setDirty(true); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -148,6 +149,7 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource< | ||||
|         this.hasSearched = false; | ||||
|         this.onlineEntries = cachedOnlineEntries; | ||||
|         this.hasMoreItems = hasMoreOnlineEntries; | ||||
|         this.setDirty(true); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -177,6 +179,7 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource< | ||||
|             'ASC', | ||||
|         ); | ||||
|         this.hasSearched = true; | ||||
|         this.setDirty(true); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
| @ -209,6 +212,7 @@ export class AddonModGlossaryEntriesSource extends CoreRoutedItemsManagerSource< | ||||
| 
 | ||||
|         this.fetchMode = mode; | ||||
|         this.isSearch = false; | ||||
|         this.setDirty(true); | ||||
| 
 | ||||
|         switch (mode) { | ||||
|             case 'author_all': | ||||
|  | ||||
| @ -24,29 +24,8 @@ export abstract class AddonModGlossaryEntriesSwipeManager | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async navigateToNextItem(): Promise<void> { | ||||
|         let delta = -1; | ||||
|         const item = await this.getItemBy(-1); | ||||
| 
 | ||||
|         if (item && this.getSource().isNewEntryForm(item)) { | ||||
|             delta--; | ||||
|         } | ||||
| 
 | ||||
|         await this.navigateToItemBy(delta, 'back'); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async navigateToPreviousItem(): Promise<void> { | ||||
|         let delta = 1; | ||||
|         const item = await this.getItemBy(1); | ||||
| 
 | ||||
|         if (item && this.getSource().isNewEntryForm(item)) { | ||||
|             delta++; | ||||
|         } | ||||
| 
 | ||||
|         await this.navigateToItemBy(delta, 'forward'); | ||||
|     protected skipItemInSwipe(item: AddonModGlossaryEntryItem): boolean { | ||||
|         return this.getSource().isNewEntryForm(item); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -82,7 +82,13 @@ export class CoreSwipeNavigationItemsManager< | ||||
|      * @param animationDirection Animation direction. | ||||
|      */ | ||||
|     protected async navigateToItemBy(delta: number, animationDirection: 'forward' | 'back'): Promise<void> { | ||||
|         const item = await this.getItemBy(delta); | ||||
|         let item: Item | null; | ||||
| 
 | ||||
|         do { | ||||
|             item = await this.getItemBy(delta); | ||||
| 
 | ||||
|             delta += delta > 0 ? 1 : -1; | ||||
|         } while (item && this.skipItemInSwipe(item)); | ||||
| 
 | ||||
|         if (!item) { | ||||
|             return; | ||||
| @ -100,14 +106,15 @@ export class CoreSwipeNavigationItemsManager< | ||||
|         const items = this.getSource().getItems(); | ||||
| 
 | ||||
|         // Get selected item.
 | ||||
|         const index = (this.selectedItem && items?.indexOf(this.selectedItem)) ?? -1; | ||||
|         const selectedIndex = (this.selectedItem && items?.indexOf(this.selectedItem)) ?? -1; | ||||
|         const nextIndex = selectedIndex + delta; | ||||
| 
 | ||||
|         if (index === -1) { | ||||
|         if (selectedIndex === -1 || nextIndex < 0) { | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // Get item by delta.
 | ||||
|         const item = items?.[index + delta] ?? null; | ||||
|         const item = items?.[nextIndex] ?? null; | ||||
| 
 | ||||
|         if (!item && !this.getSource().isCompleted()) { | ||||
|             await this.getSource().load(); | ||||
| @ -118,4 +125,15 @@ export class CoreSwipeNavigationItemsManager< | ||||
|         return item; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Check if an item should be skipped during swipe navigation. | ||||
|      * | ||||
|      * @param item Item. | ||||
|      * @returns Whether to skip this item during swipe navigation. | ||||
|      */ | ||||
|     // eslint-disable-next-line @typescript-eslint/no-unused-vars
 | ||||
|     protected skipItemInSwipe(item: Item): boolean { | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -106,7 +106,7 @@ export class CoreCourseModuleComponent implements OnInit, OnDestroy { | ||||
| 
 | ||||
|         if (this.module.handlerData.showDownloadButton) { | ||||
|             // Listen for changes on this module status, even if download isn't enabled.
 | ||||
|             this.prefetchHandler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(this.module.name); | ||||
|             this.prefetchHandler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(this.module.modname); | ||||
| 
 | ||||
|             this.statusObserver = CoreEvents.on(CoreEvents.PACKAGE_STATUS_CHANGED, (data) => { | ||||
|                 if (!this.module || data.componentId != this.module.id || !this.prefetchHandler || | ||||
|  | ||||
| @ -1013,7 +1013,7 @@ export class CoreCourseHelperProvider { | ||||
|     ): Promise<void> { | ||||
|         siteId = siteId || CoreSites.getCurrentSiteId(); | ||||
| 
 | ||||
|         const prefetchHandler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(module.name); | ||||
|         const prefetchHandler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(module.modname); | ||||
| 
 | ||||
|         if (prefetchHandler) { | ||||
|             // Use the prefetch handler to download the module.
 | ||||
| @ -2048,7 +2048,7 @@ export class CoreCourseHelperProvider { | ||||
| 
 | ||||
|         promises.push(CoreCourseModulePrefetchDelegate.removeModuleFiles(module, courseId)); | ||||
| 
 | ||||
|         const handler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(module.name); | ||||
|         const handler = CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(module.modname); | ||||
|         const site = CoreSites.getCurrentSite(); | ||||
|         if (handler && site) { | ||||
|             promises.push(site.deleteComponentFromCache(handler.component, module.id)); | ||||
|  | ||||
| @ -95,7 +95,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved with boolean: whether the module can use check updates WS. | ||||
|      */ | ||||
|     async canModuleUseCheckUpdates(module: CoreCourseAnyModuleData, courseId: number): Promise<boolean> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
| 
 | ||||
|         if (!handler) { | ||||
|             // Module not supported, cannot use check updates.
 | ||||
| @ -171,7 +171,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Module status. | ||||
|      */ | ||||
|     determineModuleStatus(module: CoreCourseAnyModuleData, status: string): string { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         const siteId = CoreSites.getCurrentSiteId(); | ||||
| 
 | ||||
|         if (!handler) { | ||||
| @ -203,7 +203,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      */ | ||||
|     async downloadModule(module: CoreCourseAnyModuleData, courseId: number, dirPath?: string): Promise<void> { | ||||
|         // Check if the module has a prefetch handler.
 | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
| 
 | ||||
|         if (!handler) { | ||||
|             return; | ||||
| @ -381,7 +381,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved with the size. | ||||
|      */ | ||||
|     async getModuleDownloadSize(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<CoreFileSizeSum> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
| 
 | ||||
|         if (!handler) { | ||||
|             return { size: 0, total: false }; | ||||
| @ -419,7 +419,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved with the size. | ||||
|      */ | ||||
|     async getModuleDownloadedSize(module: CoreCourseAnyModuleData, courseId: number): Promise<number> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         if (!handler) { | ||||
|             return 0; | ||||
|         } | ||||
| @ -492,7 +492,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|         } | ||||
| 
 | ||||
|         const site = CoreSites.getCurrentSite(); | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         if (!handler || !site) { | ||||
|             // If there is no handler then we can't find out the component name.
 | ||||
|             // We can't work out the cached size, so just return downloaded size.
 | ||||
| @ -515,7 +515,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|         module: CoreCourseAnyModuleData, | ||||
|         courseId: number, | ||||
|     ): Promise<(CoreWSFile | CoreCourseModuleContentFile)[]> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
| 
 | ||||
|         if (handler?.getFiles) { | ||||
|             // The handler defines a function to get files, use it.
 | ||||
| @ -548,7 +548,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|         refresh?: boolean, | ||||
|         sectionId?: number, | ||||
|     ): Promise<string> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
| 
 | ||||
|         if (!handler) { | ||||
|             // No handler found, module not downloadable.
 | ||||
| @ -712,7 +712,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|         } | ||||
| 
 | ||||
|         await Promise.all(modules.map(async (module) => { | ||||
|             const handler = this.getPrefetchHandlerFor(module.name); | ||||
|             const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|             if (!handler || (onlyToDisplay && handler.skipListStatus)) { | ||||
|                 return; | ||||
|             } | ||||
| @ -758,7 +758,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|         module: CoreCourseAnyModuleData, | ||||
|         courseId: number, | ||||
|     ): Promise<{ status: string; downloadTime?: number }> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         const siteId = CoreSites.getCurrentSiteId(); | ||||
| 
 | ||||
|         if (!handler) { | ||||
| @ -895,7 +895,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|     async invalidateModules(modules: CoreCourseModuleData[], courseId: number): Promise<void> { | ||||
| 
 | ||||
|         const promises = modules.map(async (module) => { | ||||
|             const handler = this.getPrefetchHandlerFor(module.name); | ||||
|             const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|             if (!handler) { | ||||
|                 return; | ||||
|             } | ||||
| @ -919,7 +919,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @param module Module to be invalidated. | ||||
|      */ | ||||
|     invalidateModuleStatusCache(module: CoreCourseAnyModuleData): void { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         if (handler) { | ||||
|             this.statusCache.invalidate(CoreFilepool.getPackageId(handler.component, module.id)); | ||||
|         } | ||||
| @ -964,7 +964,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         if (!handler) { | ||||
|             return false; | ||||
|         } | ||||
| @ -1000,7 +1000,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved with boolean: whether the module has updates. | ||||
|      */ | ||||
|     async moduleHasUpdates(module: CoreCourseAnyModuleData, courseId: number, updates: CourseUpdates): Promise<boolean> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         const moduleUpdates = updates[module.id]; | ||||
| 
 | ||||
|         if (handler?.hasUpdates) { | ||||
| @ -1033,7 +1033,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved when finished. | ||||
|      */ | ||||
|     async prefetchModule(module: CoreCourseAnyModuleData, courseId: number, single?: boolean): Promise<void> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         if (!handler) { | ||||
|             return; | ||||
|         } | ||||
| @ -1067,7 +1067,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved when finished. | ||||
|      */ | ||||
|     async syncModule<T = unknown>(module: CoreCourseAnyModuleData, courseId: number): Promise<T | undefined> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         if (!handler?.sync) { | ||||
|             return; | ||||
|         } | ||||
| @ -1124,7 +1124,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
| 
 | ||||
|         const promises = modules.map(async (module) => { | ||||
|             // Check if the module has a prefetch handler.
 | ||||
|             const handler = this.getPrefetchHandlerFor(module.name); | ||||
|             const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|             if (!handler) { | ||||
|                 return; | ||||
|             } | ||||
| @ -1170,7 +1170,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo | ||||
|      * @return Promise resolved when done. | ||||
|      */ | ||||
|     async removeModuleFiles(module: CoreCourseAnyModuleData, courseId: number): Promise<void> { | ||||
|         const handler = this.getPrefetchHandlerFor(module.name); | ||||
|         const handler = this.getPrefetchHandlerFor(module.modname); | ||||
|         const siteId = CoreSites.getCurrentSiteId(); | ||||
| 
 | ||||
|         if (handler?.removeFiles) { | ||||
|  | ||||
| @ -145,7 +145,7 @@ export class CoreSitePluginsModuleIndexComponent implements OnInit, OnDestroy, C | ||||
|         this.refreshIcon = CoreConstants.ICON_REFRESH; | ||||
| 
 | ||||
|         // Check if there is a prefetch handler for this type of module.
 | ||||
|         if (CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(this.module.name)) { | ||||
|         if (CoreCourseModulePrefetchDelegate.getPrefetchHandlerFor(this.module.modname)) { | ||||
|             CoreCourseHelper.fillContextMenu(this, this.module, this.courseId, refresh, this.component); | ||||
|         } | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user