MOBILE-3325 settings: Modern syntax changes
parent
496a0a42a6
commit
ebfec71542
|
@ -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",
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
<h2>{{ logoutLabel | translate }}</h2>
|
||||
</a>
|
||||
<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>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {}
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) => {
|
||||
await Promise.all(this.sites.map(async (site) => {
|
||||
const siteInfo = await this.settingsHelper.getSiteSpaceUsage(site.id);
|
||||
|
||||
site.cacheEntries = siteInfo.cacheEntries;
|
||||
site.spaceUsage = siteInfo.spaceUsage;
|
||||
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,7 +87,7 @@ export class CoreSettingsSpaceUsagePage {
|
|||
* @param refresher Refresher.
|
||||
*/
|
||||
refreshData(refresher: any): void {
|
||||
this.calculateSizeUsage().finally(() => {
|
||||
this.loadSiteData().finally(() => {
|
||||
refresher.complete();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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,21 +96,18 @@ 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});
|
||||
|
||||
return this.domUtils.showConfirm(message, title).then(() => {
|
||||
return this.sitesProvider.getSite(siteId);
|
||||
}).then((site) => {
|
||||
await this.domUtils.showConfirm(message, title);
|
||||
|
||||
const site = await this.sitesProvider.getSite(siteId);
|
||||
|
||||
// Clear cache tables.
|
||||
const cleanSchemas = this.sitesProvider.getSiteTableSchemasToClear(site);
|
||||
const promises = cleanSchemas.map((name) => {
|
||||
return site.getDb().deleteRecords(name);
|
||||
});
|
||||
const promises = cleanSchemas.map((name) => site.getDb().deleteRecords(name));
|
||||
|
||||
promises.push(site.deleteFolder().then(() => {
|
||||
this.filePoolProvider.clearAllPackagesStatus(site.id);
|
||||
|
@ -117,7 +115,7 @@ export class CoreSettingsHelper {
|
|||
this.courseProvider.clearAllCoursesStatus(site.id);
|
||||
|
||||
siteInfo.spaceUsage = 0;
|
||||
}).catch((error) => {
|
||||
}).catch(async (error) => {
|
||||
if (error && error.code === FileError.NOT_FOUND_ERR) {
|
||||
// Not found, set size 0.
|
||||
this.filePoolProvider.clearAllPackagesStatus(site.id);
|
||||
|
@ -126,23 +124,17 @@ export class CoreSettingsHelper {
|
|||
// Error, recalculate the site usage.
|
||||
this.domUtils.showErrorModal('core.settings.errordeletesitefiles', true);
|
||||
|
||||
return site.getSpaceUsage().then((size) => {
|
||||
siteInfo.spaceUsage = size;
|
||||
});
|
||||
siteInfo.spaceUsage = await site.getSpaceUsage();
|
||||
}
|
||||
}).then(() => {
|
||||
}).then(async () => {
|
||||
this.eventsProvider.trigger(CoreEventsProvider.SITE_STORAGE_DELETED, {}, site.getId());
|
||||
|
||||
return this.calcSiteClearRows(site).then((rows) => {
|
||||
siteInfo.cacheEntries = rows;
|
||||
});
|
||||
siteInfo.cacheEntries = await this.calcSiteClearRows(site);
|
||||
}));
|
||||
|
||||
return Promise.all(promises).then(() => {
|
||||
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) => {
|
||||
const site = await this.sitesProvider.getSite(siteId);
|
||||
|
||||
// Get space usage.
|
||||
const promises = [];
|
||||
const siteInfo: CoreSiteSpaceUsage = {
|
||||
cacheEntries: 0,
|
||||
spaceUsage: 0
|
||||
spaceUsage: 0,
|
||||
};
|
||||
|
||||
promises.push(this.calcSiteClearRows(site).then((rows) => {
|
||||
siteInfo.cacheEntries = rows;
|
||||
}));
|
||||
await Promise.all([
|
||||
this.calcSiteClearRows(site).then((rows) => siteInfo.cacheEntries = rows),
|
||||
site.getSpaceUsage().then((size) => siteInfo.spaceUsage = size),
|
||||
]);
|
||||
|
||||
promises.push(site.getSpaceUsage().then((size) => {
|
||||
siteInfo.spaceUsage = size;
|
||||
}));
|
||||
|
||||
return Promise.all(promises).then(() => {
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue