diff --git a/scripts/langindex.json b/scripts/langindex.json index 0a13d4d3c..373656b89 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1953,9 +1953,9 @@ "core.settings.sites": "moodle", "core.settings.spaceusage": "local_moodlemobileapp", "core.settings.spaceusagehelp": "local_moodlemobileapp", - "core.settings.synchelp": "local_moodlemobileapp", "core.settings.synchronization": "local_moodlemobileapp", "core.settings.synchronizenow": "local_moodlemobileapp", + "core.settings.synchronizenowhelp": "local_moodlemobileapp", "core.settings.syncsettings": "local_moodlemobileapp", "core.settings.total": "moodle", "core.settings.wificonnection": "local_moodlemobileapp", diff --git a/src/addon/messages/providers/settings-handler.ts b/src/addon/messages/providers/settings-handler.ts index 0375ec36b..b3a4b62df 100644 --- a/src/addon/messages/providers/settings-handler.ts +++ b/src/addon/messages/providers/settings-handler.ts @@ -46,7 +46,7 @@ export class AddonMessagesSettingsHandler implements CoreSettingsHandler { icon: 'chatbubbles', title: 'addon.messages.messages', page: 'AddonMessagesSettingsPage', - class: 'addon-messages-settings-handler' + class: 'addon-messages-settings-handler', }; } diff --git a/src/addon/notifications/providers/settings-handler.ts b/src/addon/notifications/providers/settings-handler.ts index b34f5f15f..08339302a 100644 --- a/src/addon/notifications/providers/settings-handler.ts +++ b/src/addon/notifications/providers/settings-handler.ts @@ -51,7 +51,7 @@ export class AddonNotificationsSettingsHandler implements CoreSettingsHandler { icon: 'notifications', title: 'addon.notifications.notifications', page: 'AddonNotificationsSettingsPage', - class: 'addon-notifications-settings-handler' + class: 'addon-notifications-settings-handler', }; } } diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index daa597d0d..769a0c480 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1953,9 +1953,9 @@ "core.settings.sites": "Sites", "core.settings.spaceusage": "Space usage", "core.settings.spaceusagehelp": "Deleting the stored information of the site will remove all the site offline data. This information allows you to use the app when offline. ", - "core.settings.synchelp": "Synchronising a site will send pending changes and all offline activity stored in the device and will synchronise some data like messages and notifications.", "core.settings.synchronization": "Synchronisation", "core.settings.synchronizenow": "Synchronise now", + "core.settings.synchronizenowhelp": "Synchronising a site will send pending changes and all offline activity stored in the device and will synchronise some data like messages and notifications.", "core.settings.syncsettings": "Synchronisation settings", "core.settings.total": "Total", "core.settings.wificonnection": "Wi-Fi connection", diff --git a/src/core/mainmenu/pages/more/more.html b/src/core/mainmenu/pages/more/more.html index 608eb4915..d2d3908d1 100644 --- a/src/core/mainmenu/pages/more/more.html +++ b/src/core/mainmenu/pages/more/more.html @@ -47,8 +47,7 @@

{{ logoutLabel | translate }}

- - +

{{ 'core.settings.appsettings' | translate }}

diff --git a/src/core/settings/lang/en.json b/src/core/settings/lang/en.json index 1713ce651..a91251cb9 100644 --- a/src/core/settings/lang/en.json +++ b/src/core/settings/lang/en.json @@ -63,9 +63,9 @@ "sites": "Sites", "spaceusage": "Space usage", "spaceusagehelp": "Deleting the stored information of the site will remove all the site offline data. This information allows you to use the app when offline. ", - "synchelp": "Synchronising a site will send pending changes and all offline activity stored in the device and will synchronise some data like messages and notifications.", "synchronization": "Synchronisation", "synchronizenow": "Synchronise now", + "synchronizenowhelp": "Synchronising a site will send pending changes and all offline activity stored in the device and will synchronise some data like messages and notifications.", "syncsettings": "Synchronisation settings", "total": "Total", "wificonnection": "Wi-Fi connection" diff --git a/src/core/settings/pages/site/site.module.ts b/src/core/settings/pages/site/site.module.ts index 2ce44ef26..d7e2a43c3 100644 --- a/src/core/settings/pages/site/site.module.ts +++ b/src/core/settings/pages/site/site.module.ts @@ -22,14 +22,14 @@ import { CorePipesModule } from '@pipes/pipes.module'; @NgModule({ declarations: [ - CoreSitePreferencesPage + CoreSitePreferencesPage, ], imports: [ CoreComponentsModule, CoreDirectivesModule, CorePipesModule, IonicPageModule.forChild(CoreSitePreferencesPage), - TranslateModule.forChild() + TranslateModule.forChild(), ], }) export class CoreSitePreferencesPageModule {} diff --git a/src/core/settings/pages/site/site.ts b/src/core/settings/pages/site/site.ts index 6f484dd44..4f35c7feb 100644 --- a/src/core/settings/pages/site/site.ts +++ b/src/core/settings/pages/site/site.ts @@ -58,7 +58,8 @@ export class CoreSitePreferencesPage { protected sharedFilesProvider: CoreSharedFilesProvider, protected translate: TranslateService, platorm: Platform, - navParams: NavParams) { + navParams: NavParams, + ) { this.isIOS = platorm.is('ios'); @@ -93,9 +94,7 @@ export class CoreSitePreferencesPage { /** * Fetch Data. */ - protected async fetchData(): Promise { - const promises = []; - + protected async fetchData(): Promise { this.handlers = this.settingsDelegate.getHandlers(); const currentSite = this.sitesProvider.getCurrentSite(); this.siteId = currentSite.id; @@ -103,17 +102,17 @@ export class CoreSitePreferencesPage { this.siteName = currentSite.getSiteName(); this.siteUrl = currentSite.getURL(); - promises.push(this.settingsHelper.getSiteSpaceUsage(this.siteId).then((spaceUsage) => { - this.spaceUsage = spaceUsage; - })); + const promises = []; + + promises.push(this.settingsHelper.getSiteSpaceUsage(this.siteId).then((spaceUsage) => this.spaceUsage = spaceUsage)); if (this.isIOS) { - promises.push(this.sharedFilesProvider.getSiteSharedFiles(this.siteId).then((files) => { - this.iosSharedFiles = files.length; - })); + promises.push(this.sharedFilesProvider.getSiteSharedFiles(this.siteId).then((files) => + this.iosSharedFiles = files.length + )); } - return Promise.all(promises); + await Promise.all(promises); } /** @@ -186,7 +185,7 @@ export class CoreSitePreferencesPage { */ showSyncInfo(): void { this.domUtils.showAlert(this.translate.instant('core.help'), - this.translate.instant('core.settings.synchelp')); + this.translate.instant('core.settings.synchronizenowhelp')); } /** diff --git a/src/core/settings/pages/space-usage/space-usage.ts b/src/core/settings/pages/space-usage/space-usage.ts index 31b3fd9a9..35a49c323 100644 --- a/src/core/settings/pages/space-usage/space-usage.ts +++ b/src/core/settings/pages/space-usage/space-usage.ts @@ -40,7 +40,8 @@ export class CoreSettingsSpaceUsagePage { constructor(protected sitesProvider: CoreSitesProvider, protected settingsHelper: CoreSettingsHelper, protected domUtils: CoreDomUtilsProvider, - protected translate: TranslateService) { + protected translate: TranslateService, + ) { this.currentSiteId = this.sitesProvider.getCurrentSiteId(); } @@ -48,38 +49,36 @@ export class CoreSettingsSpaceUsagePage { * View loaded. */ ionViewDidLoad(): void { - this.calculateSizeUsage().finally(() => { + this.loadSiteData().finally(() => { this.loaded = true; }); } /** - * Convenience function to calculate each site's usage, and the total usage. + * Convenience function to load site data/usage and calculate the totals. * * @return Resolved when done. */ - protected async calculateSizeUsage(): Promise { + protected async loadSiteData(): Promise { // Calculate total usage. - let totalSize = 0, - totalEntries = 0; + let totalSize = 0; + let totalEntries = 0; - return this.sitesProvider.getSortedSites().then((sites) => { - this.sites = sites; + this.sites = await this.sitesProvider.getSortedSites(); - // Get space usage. - return Promise.all(this.sites.map((site) => { - return this.settingsHelper.getSiteSpaceUsage(site.id).then((siteInfo) => { - site.cacheEntries = siteInfo.cacheEntries; - site.spaceUsage = siteInfo.spaceUsage; + // Get space usage. + await Promise.all(this.sites.map(async (site) => { + const siteInfo = await this.settingsHelper.getSiteSpaceUsage(site.id); - totalSize += (site.spaceUsage ? parseInt(site.spaceUsage, 10) : 0); - totalEntries += (site.cacheEntries ? parseInt(site.cacheEntries, 10) : 0); - }); - })); - }).then(() => { - this.totals.spaceUsage = totalSize; - this.totals.cacheEntries = totalEntries; - }); + site.cacheEntries = siteInfo.cacheEntries; + site.spaceUsage = siteInfo.spaceUsage; + + totalSize += (site.spaceUsage ? parseInt(site.spaceUsage, 10) : 0); + totalEntries += (site.cacheEntries ? parseInt(site.cacheEntries, 10) : 0); + })); + + this.totals.spaceUsage = totalSize; + this.totals.cacheEntries = totalEntries; } /** @@ -88,7 +87,7 @@ export class CoreSettingsSpaceUsagePage { * @param refresher Refresher. */ refreshData(refresher: any): void { - this.calculateSizeUsage().finally(() => { + this.loadSiteData().finally(() => { refresher.complete(); }); } diff --git a/src/core/settings/pages/synchronization/synchronization.ts b/src/core/settings/pages/synchronization/synchronization.ts index 1a31b32e1..77a7eddf5 100644 --- a/src/core/settings/pages/synchronization/synchronization.ts +++ b/src/core/settings/pages/synchronization/synchronization.ts @@ -44,7 +44,8 @@ export class CoreSettingsSynchronizationPage implements OnDestroy { protected sitesProvider: CoreSitesProvider, protected domUtils: CoreDomUtilsProvider, protected settingsHelper: CoreSettingsHelper, - protected translate: TranslateService) { + protected translate: TranslateService, + ) { this.currentSiteId = this.sitesProvider.getCurrentSiteId(); @@ -113,7 +114,7 @@ export class CoreSettingsSynchronizationPage implements OnDestroy { */ showInfo(): void { this.domUtils.showAlert(this.translate.instant('core.help'), - this.translate.instant('core.settings.synchelp')); + this.translate.instant('core.settings.synchronizenowhelp')); } /** diff --git a/src/core/settings/providers/helper.ts b/src/core/settings/providers/helper.ts index 14b026588..b61b0a79d 100644 --- a/src/core/settings/providers/helper.ts +++ b/src/core/settings/providers/helper.ts @@ -56,7 +56,8 @@ export class CoreSettingsHelper { protected translate: TranslateService, protected configProvider: CoreConfigProvider, protected filterProvider: CoreFilterProvider, - protected courseProvider: CoreCourseProvider) { + protected courseProvider: CoreCourseProvider, + ) { this.logger = loggerProvider.getInstance('CoreSettingsHelper'); if (!CoreConfigConstants.forceColorScheme) { @@ -95,54 +96,45 @@ export class CoreSettingsHelper { spaceUsage: 0 }; - return this.filterProvider.formatText(siteName, {clean: true, singleLine: true, filter: false}, [], siteId) - .then((siteName) => { + siteName = await this.filterProvider.formatText(siteName, {clean: true, singleLine: true, filter: false}, [], siteId); - const title = this.translate.instant('core.settings.deletesitefilestitle'); - const message = this.translate.instant('core.settings.deletesitefiles', {sitename: siteName}); + const title = this.translate.instant('core.settings.deletesitefilestitle'); + const message = this.translate.instant('core.settings.deletesitefiles', {sitename: siteName}); - return this.domUtils.showConfirm(message, title).then(() => { - return this.sitesProvider.getSite(siteId); - }).then((site) => { + await this.domUtils.showConfirm(message, title); - // Clear cache tables. - const cleanSchemas = this.sitesProvider.getSiteTableSchemasToClear(site); - const promises = cleanSchemas.map((name) => { - return site.getDb().deleteRecords(name); - }); + const site = await this.sitesProvider.getSite(siteId); - promises.push(site.deleteFolder().then(() => { - this.filePoolProvider.clearAllPackagesStatus(site.id); - this.filePoolProvider.clearFilepool(site.id); - this.courseProvider.clearAllCoursesStatus(site.id); + // Clear cache tables. + const cleanSchemas = this.sitesProvider.getSiteTableSchemasToClear(site); + const promises = cleanSchemas.map((name) => site.getDb().deleteRecords(name)); - siteInfo.spaceUsage = 0; - }).catch((error) => { - if (error && error.code === FileError.NOT_FOUND_ERR) { - // Not found, set size 0. - this.filePoolProvider.clearAllPackagesStatus(site.id); - siteInfo.spaceUsage = 0; - } else { - // Error, recalculate the site usage. - this.domUtils.showErrorModal('core.settings.errordeletesitefiles', true); + promises.push(site.deleteFolder().then(() => { + this.filePoolProvider.clearAllPackagesStatus(site.id); + this.filePoolProvider.clearFilepool(site.id); + this.courseProvider.clearAllCoursesStatus(site.id); - return site.getSpaceUsage().then((size) => { - siteInfo.spaceUsage = size; - }); - } - }).then(() => { - this.eventsProvider.trigger(CoreEventsProvider.SITE_STORAGE_DELETED, {}, site.getId()); + siteInfo.spaceUsage = 0; + }).catch(async (error) => { + if (error && error.code === FileError.NOT_FOUND_ERR) { + // Not found, set size 0. + this.filePoolProvider.clearAllPackagesStatus(site.id); + siteInfo.spaceUsage = 0; + } else { + // Error, recalculate the site usage. + this.domUtils.showErrorModal('core.settings.errordeletesitefiles', true); - return this.calcSiteClearRows(site).then((rows) => { - siteInfo.cacheEntries = rows; - }); - })); + siteInfo.spaceUsage = await site.getSpaceUsage(); + } + }).then(async () => { + this.eventsProvider.trigger(CoreEventsProvider.SITE_STORAGE_DELETED, {}, site.getId()); - return Promise.all(promises).then(() => { - return siteInfo; - }); - }); - }); + siteInfo.cacheEntries = await this.calcSiteClearRows(site); + })); + + await Promise.all(promises); + + return siteInfo; } /** @@ -152,26 +144,20 @@ export class CoreSettingsHelper { * @return Resolved with detailed info when done. */ async getSiteSpaceUsage(siteId?: string): Promise { - return this.sitesProvider.getSite(siteId).then((site) => { - // Get space usage. - const promises = []; - const siteInfo: CoreSiteSpaceUsage = { - cacheEntries: 0, - spaceUsage: 0 - }; + const site = await this.sitesProvider.getSite(siteId); - promises.push(this.calcSiteClearRows(site).then((rows) => { - siteInfo.cacheEntries = rows; - })); + // Get space usage. + const siteInfo: CoreSiteSpaceUsage = { + cacheEntries: 0, + spaceUsage: 0, + }; - promises.push(site.getSpaceUsage().then((size) => { - siteInfo.spaceUsage = size; - })); + await Promise.all([ + this.calcSiteClearRows(site).then((rows) => siteInfo.cacheEntries = rows), + site.getSpaceUsage().then((size) => siteInfo.spaceUsage = size), + ]); - return Promise.all(promises).then(() => { - return siteInfo; - }); - }); + return siteInfo; } /** @@ -185,15 +171,11 @@ export class CoreSettingsHelper { let totalEntries = 0; - const promises = clearTables.map((name) => { - return site.getDb().countRecords(name).then((rows) => { - totalEntries += rows; - }); - }); + await Promise.all(clearTables.map(async (name) => + totalEntries += await site.getDb().countRecords(name) + )); - return Promise.all(promises).then(() => { - return totalEntries; - }); + return totalEntries; } /**