MOBILE-3325 settings: Modern syntax changes
parent
496a0a42a6
commit
ebfec71542
|
@ -1953,9 +1953,9 @@
|
||||||
"core.settings.sites": "moodle",
|
"core.settings.sites": "moodle",
|
||||||
"core.settings.spaceusage": "local_moodlemobileapp",
|
"core.settings.spaceusage": "local_moodlemobileapp",
|
||||||
"core.settings.spaceusagehelp": "local_moodlemobileapp",
|
"core.settings.spaceusagehelp": "local_moodlemobileapp",
|
||||||
"core.settings.synchelp": "local_moodlemobileapp",
|
|
||||||
"core.settings.synchronization": "local_moodlemobileapp",
|
"core.settings.synchronization": "local_moodlemobileapp",
|
||||||
"core.settings.synchronizenow": "local_moodlemobileapp",
|
"core.settings.synchronizenow": "local_moodlemobileapp",
|
||||||
|
"core.settings.synchronizenowhelp": "local_moodlemobileapp",
|
||||||
"core.settings.syncsettings": "local_moodlemobileapp",
|
"core.settings.syncsettings": "local_moodlemobileapp",
|
||||||
"core.settings.total": "moodle",
|
"core.settings.total": "moodle",
|
||||||
"core.settings.wificonnection": "local_moodlemobileapp",
|
"core.settings.wificonnection": "local_moodlemobileapp",
|
||||||
|
|
|
@ -46,7 +46,7 @@ export class AddonMessagesSettingsHandler implements CoreSettingsHandler {
|
||||||
icon: 'chatbubbles',
|
icon: 'chatbubbles',
|
||||||
title: 'addon.messages.messages',
|
title: 'addon.messages.messages',
|
||||||
page: 'AddonMessagesSettingsPage',
|
page: 'AddonMessagesSettingsPage',
|
||||||
class: 'addon-messages-settings-handler'
|
class: 'addon-messages-settings-handler',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ export class AddonNotificationsSettingsHandler implements CoreSettingsHandler {
|
||||||
icon: 'notifications',
|
icon: 'notifications',
|
||||||
title: 'addon.notifications.notifications',
|
title: 'addon.notifications.notifications',
|
||||||
page: 'AddonNotificationsSettingsPage',
|
page: 'AddonNotificationsSettingsPage',
|
||||||
class: 'addon-notifications-settings-handler'
|
class: 'addon-notifications-settings-handler',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1953,9 +1953,9 @@
|
||||||
"core.settings.sites": "Sites",
|
"core.settings.sites": "Sites",
|
||||||
"core.settings.spaceusage": "Space usage",
|
"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.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.synchronization": "Synchronisation",
|
||||||
"core.settings.synchronizenow": "Synchronise now",
|
"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.syncsettings": "Synchronisation settings",
|
||||||
"core.settings.total": "Total",
|
"core.settings.total": "Total",
|
||||||
"core.settings.wificonnection": "Wi-Fi connection",
|
"core.settings.wificonnection": "Wi-Fi connection",
|
||||||
|
|
|
@ -47,8 +47,7 @@
|
||||||
<ion-icon name="log-out" item-start aria-hidden="true"></ion-icon>
|
<ion-icon name="log-out" item-start aria-hidden="true"></ion-icon>
|
||||||
<h2>{{ logoutLabel | translate }}</h2>
|
<h2>{{ logoutLabel | translate }}</h2>
|
||||||
</a>
|
</a>
|
||||||
<ion-item-divider></ion-item-divider>
|
<ion-item-divider></ion-item-divider>
|
||||||
|
|
||||||
<a ion-item (click)="openAppSettings()" title="{{ 'core.settings.appsettings' | translate }}">
|
<a ion-item (click)="openAppSettings()" title="{{ 'core.settings.appsettings' | translate }}">
|
||||||
<core-icon name="fa-cogs" item-start></core-icon>
|
<core-icon name="fa-cogs" item-start></core-icon>
|
||||||
<h2>{{ 'core.settings.appsettings' | translate }}</h2>
|
<h2>{{ 'core.settings.appsettings' | translate }}</h2>
|
||||||
|
|
|
@ -63,9 +63,9 @@
|
||||||
"sites": "Sites",
|
"sites": "Sites",
|
||||||
"spaceusage": "Space usage",
|
"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. ",
|
"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",
|
"synchronization": "Synchronisation",
|
||||||
"synchronizenow": "Synchronise now",
|
"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",
|
"syncsettings": "Synchronisation settings",
|
||||||
"total": "Total",
|
"total": "Total",
|
||||||
"wificonnection": "Wi-Fi connection"
|
"wificonnection": "Wi-Fi connection"
|
||||||
|
|
|
@ -22,14 +22,14 @@ import { CorePipesModule } from '@pipes/pipes.module';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
CoreSitePreferencesPage
|
CoreSitePreferencesPage,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
CoreComponentsModule,
|
CoreComponentsModule,
|
||||||
CoreDirectivesModule,
|
CoreDirectivesModule,
|
||||||
CorePipesModule,
|
CorePipesModule,
|
||||||
IonicPageModule.forChild(CoreSitePreferencesPage),
|
IonicPageModule.forChild(CoreSitePreferencesPage),
|
||||||
TranslateModule.forChild()
|
TranslateModule.forChild(),
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreSitePreferencesPageModule {}
|
export class CoreSitePreferencesPageModule {}
|
||||||
|
|
|
@ -58,7 +58,8 @@ export class CoreSitePreferencesPage {
|
||||||
protected sharedFilesProvider: CoreSharedFilesProvider,
|
protected sharedFilesProvider: CoreSharedFilesProvider,
|
||||||
protected translate: TranslateService,
|
protected translate: TranslateService,
|
||||||
platorm: Platform,
|
platorm: Platform,
|
||||||
navParams: NavParams) {
|
navParams: NavParams,
|
||||||
|
) {
|
||||||
|
|
||||||
this.isIOS = platorm.is('ios');
|
this.isIOS = platorm.is('ios');
|
||||||
|
|
||||||
|
@ -93,9 +94,7 @@ export class CoreSitePreferencesPage {
|
||||||
/**
|
/**
|
||||||
* Fetch Data.
|
* Fetch Data.
|
||||||
*/
|
*/
|
||||||
protected async fetchData(): Promise<void[]> {
|
protected async fetchData(): Promise<void> {
|
||||||
const promises = [];
|
|
||||||
|
|
||||||
this.handlers = this.settingsDelegate.getHandlers();
|
this.handlers = this.settingsDelegate.getHandlers();
|
||||||
const currentSite = this.sitesProvider.getCurrentSite();
|
const currentSite = this.sitesProvider.getCurrentSite();
|
||||||
this.siteId = currentSite.id;
|
this.siteId = currentSite.id;
|
||||||
|
@ -103,17 +102,17 @@ export class CoreSitePreferencesPage {
|
||||||
this.siteName = currentSite.getSiteName();
|
this.siteName = currentSite.getSiteName();
|
||||||
this.siteUrl = currentSite.getURL();
|
this.siteUrl = currentSite.getURL();
|
||||||
|
|
||||||
promises.push(this.settingsHelper.getSiteSpaceUsage(this.siteId).then((spaceUsage) => {
|
const promises = [];
|
||||||
this.spaceUsage = spaceUsage;
|
|
||||||
}));
|
promises.push(this.settingsHelper.getSiteSpaceUsage(this.siteId).then((spaceUsage) => this.spaceUsage = spaceUsage));
|
||||||
|
|
||||||
if (this.isIOS) {
|
if (this.isIOS) {
|
||||||
promises.push(this.sharedFilesProvider.getSiteSharedFiles(this.siteId).then((files) => {
|
promises.push(this.sharedFilesProvider.getSiteSharedFiles(this.siteId).then((files) =>
|
||||||
this.iosSharedFiles = files.length;
|
this.iosSharedFiles = files.length
|
||||||
}));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.all(promises);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,7 +185,7 @@ export class CoreSitePreferencesPage {
|
||||||
*/
|
*/
|
||||||
showSyncInfo(): void {
|
showSyncInfo(): void {
|
||||||
this.domUtils.showAlert(this.translate.instant('core.help'),
|
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,
|
constructor(protected sitesProvider: CoreSitesProvider,
|
||||||
protected settingsHelper: CoreSettingsHelper,
|
protected settingsHelper: CoreSettingsHelper,
|
||||||
protected domUtils: CoreDomUtilsProvider,
|
protected domUtils: CoreDomUtilsProvider,
|
||||||
protected translate: TranslateService) {
|
protected translate: TranslateService,
|
||||||
|
) {
|
||||||
this.currentSiteId = this.sitesProvider.getCurrentSiteId();
|
this.currentSiteId = this.sitesProvider.getCurrentSiteId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,38 +49,36 @@ export class CoreSettingsSpaceUsagePage {
|
||||||
* View loaded.
|
* View loaded.
|
||||||
*/
|
*/
|
||||||
ionViewDidLoad(): void {
|
ionViewDidLoad(): void {
|
||||||
this.calculateSizeUsage().finally(() => {
|
this.loadSiteData().finally(() => {
|
||||||
this.loaded = true;
|
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.
|
* @return Resolved when done.
|
||||||
*/
|
*/
|
||||||
protected async calculateSizeUsage(): Promise<void> {
|
protected async loadSiteData(): Promise<void> {
|
||||||
// Calculate total usage.
|
// Calculate total usage.
|
||||||
let totalSize = 0,
|
let totalSize = 0;
|
||||||
totalEntries = 0;
|
let totalEntries = 0;
|
||||||
|
|
||||||
return this.sitesProvider.getSortedSites().then((sites) => {
|
this.sites = await this.sitesProvider.getSortedSites();
|
||||||
this.sites = sites;
|
|
||||||
|
|
||||||
// Get space usage.
|
// Get space usage.
|
||||||
return Promise.all(this.sites.map((site) => {
|
await Promise.all(this.sites.map(async (site) => {
|
||||||
return this.settingsHelper.getSiteSpaceUsage(site.id).then((siteInfo) => {
|
const siteInfo = await this.settingsHelper.getSiteSpaceUsage(site.id);
|
||||||
site.cacheEntries = siteInfo.cacheEntries;
|
|
||||||
site.spaceUsage = siteInfo.spaceUsage;
|
|
||||||
|
|
||||||
totalSize += (site.spaceUsage ? parseInt(site.spaceUsage, 10) : 0);
|
site.cacheEntries = siteInfo.cacheEntries;
|
||||||
totalEntries += (site.cacheEntries ? parseInt(site.cacheEntries, 10) : 0);
|
site.spaceUsage = siteInfo.spaceUsage;
|
||||||
});
|
|
||||||
}));
|
totalSize += (site.spaceUsage ? parseInt(site.spaceUsage, 10) : 0);
|
||||||
}).then(() => {
|
totalEntries += (site.cacheEntries ? parseInt(site.cacheEntries, 10) : 0);
|
||||||
this.totals.spaceUsage = totalSize;
|
}));
|
||||||
this.totals.cacheEntries = totalEntries;
|
|
||||||
});
|
this.totals.spaceUsage = totalSize;
|
||||||
|
this.totals.cacheEntries = totalEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,7 +87,7 @@ export class CoreSettingsSpaceUsagePage {
|
||||||
* @param refresher Refresher.
|
* @param refresher Refresher.
|
||||||
*/
|
*/
|
||||||
refreshData(refresher: any): void {
|
refreshData(refresher: any): void {
|
||||||
this.calculateSizeUsage().finally(() => {
|
this.loadSiteData().finally(() => {
|
||||||
refresher.complete();
|
refresher.complete();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,8 @@ export class CoreSettingsSynchronizationPage implements OnDestroy {
|
||||||
protected sitesProvider: CoreSitesProvider,
|
protected sitesProvider: CoreSitesProvider,
|
||||||
protected domUtils: CoreDomUtilsProvider,
|
protected domUtils: CoreDomUtilsProvider,
|
||||||
protected settingsHelper: CoreSettingsHelper,
|
protected settingsHelper: CoreSettingsHelper,
|
||||||
protected translate: TranslateService) {
|
protected translate: TranslateService,
|
||||||
|
) {
|
||||||
|
|
||||||
this.currentSiteId = this.sitesProvider.getCurrentSiteId();
|
this.currentSiteId = this.sitesProvider.getCurrentSiteId();
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ export class CoreSettingsSynchronizationPage implements OnDestroy {
|
||||||
*/
|
*/
|
||||||
showInfo(): void {
|
showInfo(): void {
|
||||||
this.domUtils.showAlert(this.translate.instant('core.help'),
|
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 translate: TranslateService,
|
||||||
protected configProvider: CoreConfigProvider,
|
protected configProvider: CoreConfigProvider,
|
||||||
protected filterProvider: CoreFilterProvider,
|
protected filterProvider: CoreFilterProvider,
|
||||||
protected courseProvider: CoreCourseProvider) {
|
protected courseProvider: CoreCourseProvider,
|
||||||
|
) {
|
||||||
this.logger = loggerProvider.getInstance('CoreSettingsHelper');
|
this.logger = loggerProvider.getInstance('CoreSettingsHelper');
|
||||||
|
|
||||||
if (!CoreConfigConstants.forceColorScheme) {
|
if (!CoreConfigConstants.forceColorScheme) {
|
||||||
|
@ -95,54 +96,45 @@ export class CoreSettingsHelper {
|
||||||
spaceUsage: 0
|
spaceUsage: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.filterProvider.formatText(siteName, {clean: true, singleLine: true, filter: false}, [], siteId)
|
siteName = await this.filterProvider.formatText(siteName, {clean: true, singleLine: true, filter: false}, [], siteId);
|
||||||
.then((siteName) => {
|
|
||||||
|
|
||||||
const title = this.translate.instant('core.settings.deletesitefilestitle');
|
const title = this.translate.instant('core.settings.deletesitefilestitle');
|
||||||
const message = this.translate.instant('core.settings.deletesitefiles', {sitename: siteName});
|
const message = this.translate.instant('core.settings.deletesitefiles', {sitename: siteName});
|
||||||
|
|
||||||
return this.domUtils.showConfirm(message, title).then(() => {
|
await this.domUtils.showConfirm(message, title);
|
||||||
return this.sitesProvider.getSite(siteId);
|
|
||||||
}).then((site) => {
|
|
||||||
|
|
||||||
// Clear cache tables.
|
const site = await this.sitesProvider.getSite(siteId);
|
||||||
const cleanSchemas = this.sitesProvider.getSiteTableSchemasToClear(site);
|
|
||||||
const promises = cleanSchemas.map((name) => {
|
|
||||||
return site.getDb().deleteRecords(name);
|
|
||||||
});
|
|
||||||
|
|
||||||
promises.push(site.deleteFolder().then(() => {
|
// Clear cache tables.
|
||||||
this.filePoolProvider.clearAllPackagesStatus(site.id);
|
const cleanSchemas = this.sitesProvider.getSiteTableSchemasToClear(site);
|
||||||
this.filePoolProvider.clearFilepool(site.id);
|
const promises = cleanSchemas.map((name) => site.getDb().deleteRecords(name));
|
||||||
this.courseProvider.clearAllCoursesStatus(site.id);
|
|
||||||
|
|
||||||
siteInfo.spaceUsage = 0;
|
promises.push(site.deleteFolder().then(() => {
|
||||||
}).catch((error) => {
|
this.filePoolProvider.clearAllPackagesStatus(site.id);
|
||||||
if (error && error.code === FileError.NOT_FOUND_ERR) {
|
this.filePoolProvider.clearFilepool(site.id);
|
||||||
// Not found, set size 0.
|
this.courseProvider.clearAllCoursesStatus(site.id);
|
||||||
this.filePoolProvider.clearAllPackagesStatus(site.id);
|
|
||||||
siteInfo.spaceUsage = 0;
|
|
||||||
} else {
|
|
||||||
// Error, recalculate the site usage.
|
|
||||||
this.domUtils.showErrorModal('core.settings.errordeletesitefiles', true);
|
|
||||||
|
|
||||||
return site.getSpaceUsage().then((size) => {
|
siteInfo.spaceUsage = 0;
|
||||||
siteInfo.spaceUsage = size;
|
}).catch(async (error) => {
|
||||||
});
|
if (error && error.code === FileError.NOT_FOUND_ERR) {
|
||||||
}
|
// Not found, set size 0.
|
||||||
}).then(() => {
|
this.filePoolProvider.clearAllPackagesStatus(site.id);
|
||||||
this.eventsProvider.trigger(CoreEventsProvider.SITE_STORAGE_DELETED, {}, site.getId());
|
siteInfo.spaceUsage = 0;
|
||||||
|
} else {
|
||||||
|
// Error, recalculate the site usage.
|
||||||
|
this.domUtils.showErrorModal('core.settings.errordeletesitefiles', true);
|
||||||
|
|
||||||
return this.calcSiteClearRows(site).then((rows) => {
|
siteInfo.spaceUsage = await site.getSpaceUsage();
|
||||||
siteInfo.cacheEntries = rows;
|
}
|
||||||
});
|
}).then(async () => {
|
||||||
}));
|
this.eventsProvider.trigger(CoreEventsProvider.SITE_STORAGE_DELETED, {}, site.getId());
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
siteInfo.cacheEntries = await this.calcSiteClearRows(site);
|
||||||
return siteInfo;
|
}));
|
||||||
});
|
|
||||||
});
|
await Promise.all(promises);
|
||||||
});
|
|
||||||
|
return siteInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,26 +144,20 @@ export class CoreSettingsHelper {
|
||||||
* @return Resolved with detailed info when done.
|
* @return Resolved with detailed info when done.
|
||||||
*/
|
*/
|
||||||
async getSiteSpaceUsage(siteId?: string): Promise<CoreSiteSpaceUsage> {
|
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
|
|
||||||
};
|
|
||||||
|
|
||||||
promises.push(this.calcSiteClearRows(site).then((rows) => {
|
// Get space usage.
|
||||||
siteInfo.cacheEntries = rows;
|
const siteInfo: CoreSiteSpaceUsage = {
|
||||||
}));
|
cacheEntries: 0,
|
||||||
|
spaceUsage: 0,
|
||||||
|
};
|
||||||
|
|
||||||
promises.push(site.getSpaceUsage().then((size) => {
|
await Promise.all([
|
||||||
siteInfo.spaceUsage = size;
|
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;
|
let totalEntries = 0;
|
||||||
|
|
||||||
const promises = clearTables.map((name) => {
|
await Promise.all(clearTables.map(async (name) =>
|
||||||
return site.getDb().countRecords(name).then((rows) => {
|
totalEntries += await site.getDb().countRecords(name)
|
||||||
totalEntries += rows;
|
));
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return Promise.all(promises).then(() => {
|
return totalEntries;
|
||||||
return totalEntries;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue