From 5514e56f00abcee277540127de1bb95cf275f4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 19 Nov 2018 14:22:58 +0100 Subject: [PATCH] MOBILE-2739 site: Add site version to body tag --- src/app/app.component.ts | 39 +++++++++++++++++++ .../course-progress/course-progress.scss | 4 ++ src/providers/sites.ts | 34 ++++++++++------ 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 417cd86ec..0ec80a762 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -62,6 +62,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. @@ -142,6 +145,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 || '')); } }); @@ -169,4 +176,36 @@ export class MoodleMobileApp implements OnInit { pauseVideos(window); }); } + + /** + * 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 51c020133..0c0597bc5 100644 --- a/src/core/courses/components/course-progress/course-progress.scss +++ b/src/core/courses/components/course-progress/course-progress.scss @@ -84,3 +84,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); }); }); });