Merge pull request #1622 from crazyserver/MOBILE-2739
MOBILE-2739 site: Add site version to body tagmain
commit
c3b6144c70
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,3 +83,7 @@ ion-app.app-root core-courses-course-progress {
|
|||
z-index: 1;
|
||||
}
|
||||
}
|
||||
|
||||
body.version-3-1 .core-course-thumb{
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue