diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fb53313e6..0e425823a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -64,6 +64,9 @@ export class MoodleMobileApp implements OnInit { // Unload lang custom strings. this.langProvider.clearCustomStrings(); + + // Remove version classes from body. + this.removeVersionClass(); }); // Listen for session expired events. @@ -144,6 +147,10 @@ export class MoodleMobileApp implements OnInit { this.eventsProvider.on(CoreEventsProvider.SITE_UPDATED, (data) => { if (data.siteId == this.sitesProvider.getCurrentSiteId()) { loadCustomStrings(); + + // Add version classes to body. + this.removeVersionClass(); + this.addVersionClass(this.sitesProvider.getReleaseNumber(data.release || '')); } }); @@ -190,4 +197,36 @@ export class MoodleMobileApp implements OnInit { } ); } + + /** + * Convenience function to add version to body classes. + * + * @param {string} release Current release number of the site. + */ + protected addVersionClass(release: string): void { + const parts = release.split('.'); + + parts[1] = parts[1] || '0'; + parts[2] = parts[2] || '0'; + + document.body.classList.add('version-' + parts[0], 'version-' + parts[0] + '-' + parts[1], + 'version-' + parts[0] + '-' + parts[1] + '-' + parts[2]); + + } + + /** + * Convenience function to remove all version classes form body. + */ + protected removeVersionClass(): void { + const remove = []; + Array.from(document.body.classList).forEach((tempClass) => { + if (tempClass.substring(0, 8) == 'version-') { + remove.push(tempClass); + } + }); + + remove.forEach((tempClass) => { + document.body.classList.remove(tempClass); + }); + } } diff --git a/src/core/courses/components/course-progress/course-progress.scss b/src/core/courses/components/course-progress/course-progress.scss index ae2f1a1bd..4f2c29f5d 100644 --- a/src/core/courses/components/course-progress/course-progress.scss +++ b/src/core/courses/components/course-progress/course-progress.scss @@ -83,3 +83,7 @@ ion-app.app-root core-courses-course-progress { z-index: 1; } } + +body.version-3-1 .core-course-thumb{ + display: none; +} diff --git a/src/providers/sites.ts b/src/providers/sites.ts index 2a2fd1f99..27e088ef8 100644 --- a/src/providers/sites.ts +++ b/src/providers/sites.ts @@ -586,16 +586,13 @@ export class CoreSitesProvider { } // We couldn't validate by version number. Let's try to validate by release number. - if (info.release) { - const matches = info.release.match(/^([\d|\.]*)/); - if (matches && matches.length > 1) { - if (matches[1] >= release31) { - return this.VALID_VERSION; - } else if (matches[1] >= release24) { - return this.LEGACY_APP_VERSION; - } else { - return this.INVALID_VERSION; - } + const release = this.getReleaseNumber(info.release || ''); + if (release) { + if (release >= release31) { + return this.VALID_VERSION; + } + if (release >= release24) { + return this.LEGACY_APP_VERSION; } } @@ -603,6 +600,21 @@ export class CoreSitesProvider { return this.INVALID_VERSION; } + /** + * Returns the release number from site release info. + * + * @param {string} rawRelease Raw release info text. + * @return {string} Release number or empty. + */ + getReleaseNumber(rawRelease: string): string { + const matches = rawRelease.match(/^\d(\.\d(\.\d+)?)?/); + if (matches) { + return matches[0]; + } + + return ''; + } + /** * Check if site info is valid. If it's not, return error message. * @@ -1088,7 +1100,7 @@ export class CoreSitesProvider { } return this.appDB.updateRecords(this.SITES_TABLE, newValues, { id: siteId }).finally(() => { - this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, {}, siteId); + this.eventsProvider.trigger(CoreEventsProvider.SITE_UPDATED, info, siteId); }); }); });