MOBILE-3325 settings: Modern syntax changes

main
Pau Ferrer Ocaña 2020-01-30 10:35:21 +01:00
parent 496a0a42a6
commit ebfec71542
11 changed files with 91 additions and 111 deletions

View File

@ -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",

View File

@ -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',
};
}

View File

@ -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',
};
}
}

View File

@ -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",

View File

@ -47,8 +47,7 @@
<ion-icon name="log-out" item-start aria-hidden="true"></ion-icon>
<h2>{{ logoutLabel | translate }}</h2>
</a>
<ion-item-divider></ion-item-divider>
<ion-item-divider></ion-item-divider>
<a ion-item (click)="openAppSettings()" title="{{ 'core.settings.appsettings' | translate }}">
<core-icon name="fa-cogs" item-start></core-icon>
<h2>{{ 'core.settings.appsettings' | translate }}</h2>

View File

@ -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"

View File

@ -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 {}

View File

@ -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<void[]> {
const promises = [];
protected async fetchData(): Promise<void> {
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'));
}
/**

View File

@ -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<void> {
protected async loadSiteData(): Promise<void> {
// 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();
});
}

View File

@ -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'));
}
/**

View File

@ -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<CoreSiteSpaceUsage> {
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;
}
/**