forked from EVOgeek/Vmeda.Online
		
	MOBILE-4526 filter: Convert block and user contexts to parent
This commit is contained in:
		
							parent
							
								
									44b9f499bf
								
							
						
					
					
						commit
						8afeac3a94
					
				| @ -30,7 +30,7 @@ | ||||
|                         <div class="flex-row ion-justify-content-between ion-align-items-center"> | ||||
|                             <h2> | ||||
|                                 <core-format-text [text]="entry.subject" [contextLevel]="contextLevel" | ||||
|                                     [contextInstanceId]="contextInstanceId" /> | ||||
|                                     [contextInstanceId]="contextInstanceId" [courseId]="entry.courseid" /> | ||||
|                             </h2> | ||||
|                             <ion-note class="ion-text-end"> | ||||
|                                 {{ 'addon.blog.' + entry.publishTranslated! | translate}} | ||||
| @ -47,8 +47,8 @@ | ||||
|                 <ion-card-content> | ||||
|                     <ion-item class="ion-text-wrap"> | ||||
|                         <ion-label> | ||||
|                             <core-format-text [text]="entry.summary" [component]="this.component" [componentId]="entry.id" | ||||
|                                 [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" /> | ||||
|                             <core-format-text [text]="entry.summary" [component]="component" [componentId]="entry.id" | ||||
|                                 [contextLevel]="contextLevel" [contextInstanceId]="contextInstanceId" [courseId]="entry.courseid" /> | ||||
|                         </ion-label> | ||||
|                     </ion-item> | ||||
|                     <ion-item class="ion-text-wrap" *ngIf="tagsEnabled && entry.tags && entry.tags!.length > 0"> | ||||
| @ -57,10 +57,9 @@ | ||||
|                             <core-tag-list [tags]="entry.tags" /> | ||||
|                         </ion-label> | ||||
|                     </ion-item> | ||||
|                     <core-comments *ngIf="commentsEnabled" [component]="this.component" [itemId]="entry.id" area="format_blog" | ||||
|                         [instanceId]="entry.userid" contextLevel="user" [showItem]="true" /> | ||||
|                     <core-file *ngFor="let file of entry.attachmentfiles" [file]="file" [component]="this.component" | ||||
|                         [componentId]="entry.id" /> | ||||
|                     <core-comments *ngIf="commentsEnabled" [component]="component" [itemId]="entry.id" area="format_blog" | ||||
|                         [instanceId]="entry.userid" contextLevel="user" [showItem]="true" [courseId]="entry.courseid" /> | ||||
|                     <core-file *ngFor="let file of entry.attachmentfiles" [file]="file" [component]="component" [componentId]="entry.id" /> | ||||
|                     <ion-item *ngIf="entry.uniquehash" [href]="entry.uniquehash" core-link [detail]="true"> | ||||
|                         <ion-label>{{ 'addon.blog.linktooriginalentry' | translate }}</ion-label> | ||||
|                     </ion-item> | ||||
|  | ||||
| @ -36,13 +36,11 @@ export class CoreBlockPreRenderedComponent extends CoreBlockBaseComponent implem | ||||
|      * @inheritdoc | ||||
|      */ | ||||
|     async ngOnInit(): Promise<void> { | ||||
|         await super.ngOnInit(); | ||||
| 
 | ||||
|         this.courseId = this.contextLevel == 'course' ? this.instanceId : undefined; | ||||
| 
 | ||||
|         this.fetchContentDefaultError = 'Error getting ' + this.block.contents?.title + ' data.'; | ||||
| 
 | ||||
|         this.id = `block-${this.block.instanceid}`; | ||||
| 
 | ||||
|         await super.ngOnInit(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | ||||
| @ -69,32 +69,6 @@ export class CoreFilterHelperProvider { | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get the contexts of all blocks in a course. | ||||
|      * | ||||
|      * @param courseId Course ID. | ||||
|      * @param siteId Site ID. If not defined, current site. | ||||
|      * @returns Promise resolved with the contexts. | ||||
|      */ | ||||
|     async getBlocksContexts(courseId: number, siteId?: string): Promise<CoreFiltersGetAvailableInContextWSParamContext[]> { | ||||
|         // Use stale while revalidate, but always use the first value. If data is updated it will be stored in DB.
 | ||||
|         const blocks = await firstValueFrom(CoreCourse.getCourseBlocksObservable(courseId, { | ||||
|             readingStrategy: CoreSitesReadingStrategy.STALE_WHILE_REVALIDATE, | ||||
|             siteId, | ||||
|         })); | ||||
| 
 | ||||
|         const contexts: CoreFiltersGetAvailableInContextWSParamContext[] = []; | ||||
| 
 | ||||
|         blocks.forEach((block) => { | ||||
|             contexts.push({ | ||||
|                 contextlevel: 'block', | ||||
|                 instanceid: block.instanceid, | ||||
|             }); | ||||
|         }); | ||||
| 
 | ||||
|         return contexts; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Get some filters from memory cache. If not in cache, get them and store them in cache. | ||||
|      * | ||||
| @ -199,10 +173,14 @@ export class CoreFilterHelperProvider { | ||||
|     async getFilters( | ||||
|         contextLevel: string, | ||||
|         instanceId: number, | ||||
|         options?: CoreFilterFormatTextOptions, | ||||
|         options: CoreFilterFormatTextOptions = {}, | ||||
|         siteId?: string, | ||||
|     ): Promise<CoreFilterFilter[]> { | ||||
|         options = options || {}; | ||||
|         // Check the right context to use.
 | ||||
|         const newContext = CoreFilter.convertContext(contextLevel, instanceId, { courseId: options.courseId }); | ||||
|         contextLevel = newContext.contextLevel; | ||||
|         instanceId = newContext.instanceId; | ||||
| 
 | ||||
|         options.contextLevel = contextLevel; | ||||
|         options.instanceId = instanceId; | ||||
|         options.filter = false; | ||||
| @ -246,11 +224,6 @@ export class CoreFilterHelperProvider { | ||||
|                 // If enrolled, get all enrolled courses filters with a single call to decrease number of WS calls.
 | ||||
|                 const getFilters = () => this.getCourseContexts(instanceId, siteId); | ||||
| 
 | ||||
|                 return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); | ||||
|             } else if (contextLevel == 'block' && courseId && CoreBlockHelper.canGetCourseBlocks(site)) { | ||||
|                 // Get all the course blocks filters with a single call to decrease number of WS calls.
 | ||||
|                 const getFilters = () => this.getBlocksContexts(courseId, siteId); | ||||
| 
 | ||||
|                 return await this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); | ||||
|             } | ||||
| 
 | ||||
|  | ||||
| @ -24,6 +24,7 @@ import { makeSingleton } from '@singletons'; | ||||
| import { CoreEvents, CoreEventSiteData } from '@singletons/events'; | ||||
| import { CoreLogger } from '@singletons/logger'; | ||||
| import { CoreSiteWSPreSets } from '@classes/sites/authenticated-site'; | ||||
| import { ContextLevel } from '@/core/constants'; | ||||
| 
 | ||||
| /** | ||||
|  * Service to provide filter functionalities. | ||||
| @ -162,6 +163,29 @@ export class CoreFilterProvider { | ||||
|         return classified; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Given a context level and instance ID, return the proper context to use. | ||||
|      * | ||||
|      * @param contextLevel The context level. | ||||
|      * @param instanceId Instance ID related to the context. | ||||
|      * @param options Options. | ||||
|      * @returns Context to use. | ||||
|      */ | ||||
|     convertContext( | ||||
|         contextLevel: string, | ||||
|         instanceId: number, | ||||
|         options: {courseId?: number} = {}, | ||||
|     ): {contextLevel: string; instanceId: number} { | ||||
|         if (contextLevel === ContextLevel.BLOCK || contextLevel === ContextLevel.USER) { | ||||
|             // Blocks and users cannot have specific filters, use the parent context instead.
 | ||||
|             return options.courseId ? | ||||
|                 { contextLevel: ContextLevel.COURSE, instanceId: options.courseId } : | ||||
|                 { contextLevel: ContextLevel.SYSTEM, instanceId: 0 }; | ||||
|         } | ||||
| 
 | ||||
|         return { contextLevel, instanceId }; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Given some HTML code, this function returns the text as safe HTML. | ||||
|      * | ||||
|  | ||||
| @ -29,7 +29,8 @@ | ||||
|             <ion-item class="ion-text-wrap" *ngIf="user.description" lines="full"> | ||||
|                 <ion-label> | ||||
|                     <p> | ||||
|                         <core-format-text [text]="user.description" contextLevel="user" [contextInstanceId]="user.id" /> | ||||
|                         <core-format-text [text]="user.description" contextLevel="user" [contextInstanceId]="user.id" | ||||
|                             [courseId]="courseId" /> | ||||
|                     </p> | ||||
|                 </ion-label> | ||||
|             </ion-item> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user