diff --git a/src/core/block/components/pre-rendered-block/core-block-pre-rendered.html b/src/core/block/components/pre-rendered-block/core-block-pre-rendered.html index 4b3f46315..ab4dcb92e 100644 --- a/src/core/block/components/pre-rendered-block/core-block-pre-rendered.html +++ b/src/core/block/components/pre-rendered-block/core-block-pre-rendered.html @@ -1,11 +1,11 @@ -

+

- + - + diff --git a/src/core/block/components/pre-rendered-block/pre-rendered-block.ts b/src/core/block/components/pre-rendered-block/pre-rendered-block.ts index a88659e36..0f9cd1087 100644 --- a/src/core/block/components/pre-rendered-block/pre-rendered-block.ts +++ b/src/core/block/components/pre-rendered-block/pre-rendered-block.ts @@ -24,6 +24,8 @@ import { CoreBlockBaseComponent } from '../../classes/base-block-component'; }) export class CoreBlockPreRenderedComponent extends CoreBlockBaseComponent implements OnInit { + courseId: number; + constructor(injector: Injector) { super(injector, 'CoreBlockPreRenderedComponent'); } @@ -34,6 +36,8 @@ export class CoreBlockPreRenderedComponent extends CoreBlockBaseComponent imple ngOnInit(): void { super.ngOnInit(); + this.courseId = this.contextLevel == 'course' ? this.instanceId : undefined; + this.fetchContentDefaultError = 'Error getting ' + this.block.contents.title + ' data.'; } diff --git a/src/core/course/providers/course.ts b/src/core/course/providers/course.ts index 832eeda4c..c6f99929b 100644 --- a/src/core/course/providers/course.ts +++ b/src/core/course/providers/course.ts @@ -113,12 +113,14 @@ export class CoreCourseProvider { /** * Check if the get course blocks WS is available in current site. * + * @param site Site to check. If not defined, current site. * @return Whether it's available. * @since 3.7 */ - canGetCourseBlocks(): boolean { - return this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7') && - this.sitesProvider.wsAvailableInCurrentSite('core_block_get_course_blocks'); + canGetCourseBlocks(site?: CoreSite): boolean { + site = site || this.sitesProvider.getCurrentSite(); + + return site.isVersionGreaterEqualThan('3.7') && site.wsAvailable('core_block_get_course_blocks'); } /** diff --git a/src/core/filter/providers/helper.ts b/src/core/filter/providers/helper.ts index fd8cba551..82c89e8ac 100644 --- a/src/core/filter/providers/helper.ts +++ b/src/core/filter/providers/helper.ts @@ -64,6 +64,29 @@ 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. + * @return Promise resolved with the contexts. + */ + getBlocksContexts(courseId: number, siteId?: string): Promise<{contextlevel: string, instanceid: number}[]> { + + return this.courseProvider.getCourseBlocks(courseId, siteId).then((blocks) => { + const contexts: {contextlevel: string, instanceid: number}[] = []; + + 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. * @@ -200,6 +223,11 @@ export class CoreFilterHelperProvider { // If enrolled, get all enrolled courses filters with a single call to decrease number of WS calls. const getFilters = this.getCourseContexts.bind(this, instanceId, siteId); + return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); + } else if (contextLevel == 'block' && options.courseId && this.courseProvider.canGetCourseBlocks(site)) { + // Get all the course blocks filters with a single call to decrease number of WS calls. + const getFilters = this.getBlocksContexts.bind(this, options.courseId, siteId); + return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site); }