MOBILE-3227 filter: Get all course blocks filters at once
parent
466da5c7af
commit
dca93cb6e4
|
@ -1,11 +1,11 @@
|
||||||
<ion-item-divider text-wrap *ngIf="title">
|
<ion-item-divider text-wrap *ngIf="title">
|
||||||
<h2><core-format-text [text]="title | translate" contextLevel="block" [contextInstanceId]="block.instanceid"></core-format-text></h2>
|
<h2><core-format-text [text]="title | translate" contextLevel="block" [contextInstanceId]="block.instanceid" [courseId]="courseId"></core-format-text></h2>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
<core-loading [hideUntil]="loaded" class="core-loading-center">
|
||||||
<ion-item *ngIf="block.contents.content" text-wrap class="core-block-content">
|
<ion-item *ngIf="block.contents.content" text-wrap class="core-block-content">
|
||||||
<core-format-text [text]="block.contents.content" contextLevel="block" [contextInstanceId]="block.instanceid"></core-format-text>
|
<core-format-text [text]="block.contents.content" contextLevel="block" [contextInstanceId]="block.instanceid" [courseId]="courseId"></core-format-text>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
<ion-item *ngIf="block.contents.footer" text-wrap class="core-block-footer">
|
<ion-item *ngIf="block.contents.footer" text-wrap class="core-block-footer">
|
||||||
<core-format-text [text]="block.contents.footer" contextLevel="block" [contextInstanceId]="block.instanceid"></core-format-text>
|
<core-format-text [text]="block.contents.footer" contextLevel="block" [contextInstanceId]="block.instanceid" [courseId]="courseId"></core-format-text>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
|
@ -24,6 +24,8 @@ import { CoreBlockBaseComponent } from '../../classes/base-block-component';
|
||||||
})
|
})
|
||||||
export class CoreBlockPreRenderedComponent extends CoreBlockBaseComponent implements OnInit {
|
export class CoreBlockPreRenderedComponent extends CoreBlockBaseComponent implements OnInit {
|
||||||
|
|
||||||
|
courseId: number;
|
||||||
|
|
||||||
constructor(injector: Injector) {
|
constructor(injector: Injector) {
|
||||||
super(injector, 'CoreBlockPreRenderedComponent');
|
super(injector, 'CoreBlockPreRenderedComponent');
|
||||||
}
|
}
|
||||||
|
@ -34,6 +36,8 @@ export class CoreBlockPreRenderedComponent extends CoreBlockBaseComponent imple
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
super.ngOnInit();
|
super.ngOnInit();
|
||||||
|
|
||||||
|
this.courseId = this.contextLevel == 'course' ? this.instanceId : undefined;
|
||||||
|
|
||||||
this.fetchContentDefaultError = 'Error getting ' + this.block.contents.title + ' data.';
|
this.fetchContentDefaultError = 'Error getting ' + this.block.contents.title + ' data.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,12 +113,14 @@ export class CoreCourseProvider {
|
||||||
/**
|
/**
|
||||||
* Check if the get course blocks WS is available in current site.
|
* 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.
|
* @return Whether it's available.
|
||||||
* @since 3.7
|
* @since 3.7
|
||||||
*/
|
*/
|
||||||
canGetCourseBlocks(): boolean {
|
canGetCourseBlocks(site?: CoreSite): boolean {
|
||||||
return this.sitesProvider.getCurrentSite().isVersionGreaterEqualThan('3.7') &&
|
site = site || this.sitesProvider.getCurrentSite();
|
||||||
this.sitesProvider.wsAvailableInCurrentSite('core_block_get_course_blocks');
|
|
||||||
|
return site.isVersionGreaterEqualThan('3.7') && site.wsAvailable('core_block_get_course_blocks');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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.
|
* 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.
|
// 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);
|
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);
|
return this.getCacheableFilters(contextLevel, instanceId, getFilters, options, site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue