Merge pull request #3023 from crazyserver/MOBILE-3833

MOBILE-3833 dashboard: Fix WS exceptions on get_recent_courses and grace
main
Dani Palou 2021-12-13 12:41:43 +01:00 committed by GitHub
commit 09a8d8fead
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -264,8 +264,13 @@ export class AddonBlockMyOverviewComponent extends CoreBlockBaseComponent implem
this.hasCourses = this.allCourses.length > 0; this.hasCourses = this.allCourses.length > 0;
this.gradePeriodAfter = parseInt(await this.currentSite.getConfig('coursegraceperiodafter', refresh), 10) || 0; try {
this.gradePeriodBefore = parseInt(await this.currentSite.getConfig('coursegraceperiodbefore', refresh), 10) || 0; this.gradePeriodAfter = parseInt(await this.currentSite.getConfig('coursegraceperiodafter', refresh), 10);
this.gradePeriodBefore = parseInt(await this.currentSite.getConfig('coursegraceperiodbefore', refresh), 10);
} catch {
this.gradePeriodAfter = 0;
this.gradePeriodBefore = 0;
}
this.loadSort(); this.loadSort();
this.loadLayouts(config?.layouts?.value.split(',')); this.loadLayouts(config?.layouts?.value.split(','));

View File

@ -135,14 +135,16 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories && const showCategories = this.block.configsRecord && this.block.configsRecord.displaycategories &&
this.block.configsRecord.displaycategories.value == '1'; this.block.configsRecord.displaycategories.value == '1';
// WS is failing on 3.7 and 3.6, use a fallback. let recentCourses: CoreCourseSummaryData[] = [];
if (!this.site.isVersionGreaterEqualThan('3.8')) { try {
recentCourses = await CoreCourses.getRecentCourses();
} catch {
// WS is failing on 3.7 and bellow, use a fallback.
this.courses = await CoreCoursesHelper.getUserCoursesWithOptions('lastaccess', 10, undefined, showCategories); this.courses = await CoreCoursesHelper.getUserCoursesWithOptions('lastaccess', 10, undefined, showCategories);
return; return;
} }
const recentCourses = await CoreCourses.getRecentCourses();
const courseIds = recentCourses.map((course) => course.id); const courseIds = recentCourses.map((course) => course.id);
// Get the courses using getCoursesByField to get more info about each course. // Get the courses using getCoursesByField to get more info about each course.