From 6d039ffba8a7e7e48d30998feeb804024dfcf9fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 23 Nov 2022 13:38:31 +0100 Subject: [PATCH 1/3] MOBILE-4081 notifications: Change notification preferences layout --- scripts/langindex.json | 2 + src/addons/notifications/lang.json | 2 + .../pages/settings/settings.html | 62 +++++++++++-------- .../pages/settings/settings.scss | 4 ++ 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index 65bdc325e..6d9c132b6 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1095,12 +1095,14 @@ "addon.notes.publishstate": "notes", "addon.notes.sitenotes": "notes", "addon.notes.warningnotenotsent": "local_moodlemobileapp", + "addon.notifications.allownotifications": "local_moodlemobileapp", "addon.notifications.errorgetnotifications": "local_moodlemobileapp", "addon.notifications.markallread": "moodle", "addon.notifications.notificationpreferences": "message", "addon.notifications.notifications": "local_moodlemobileapp", "addon.notifications.playsound": "local_moodlemobileapp", "addon.notifications.therearentnotificationsyet": "local_moodlemobileapp", + "addon.notifications.typeofnotification": "local_moodlemobileapp", "addon.notifications.unreadnotification": "message", "addon.privatefiles.couldnotloadfiles": "local_moodlemobileapp", "addon.privatefiles.emptyfilelist": "local_moodlemobileapp", diff --git a/src/addons/notifications/lang.json b/src/addons/notifications/lang.json index b3c02b52e..200844392 100644 --- a/src/addons/notifications/lang.json +++ b/src/addons/notifications/lang.json @@ -1,9 +1,11 @@ { + "allownotifications": "Allow notifications", "errorgetnotifications": "Error getting notifications.", "markallread": "Mark all as read", "notificationpreferences": "Notification preferences", "notifications": "Notifications", "playsound": "Play sound", "therearentnotificationsyet": "There are no notifications.", + "typeofnotification": "Type of notification", "unreadnotification": "Unread notification: {{$a}}" } diff --git a/src/addons/notifications/pages/settings/settings.html b/src/addons/notifications/pages/settings/settings.html index 274953f0d..97174d554 100644 --- a/src/addons/notifications/pages/settings/settings.html +++ b/src/addons/notifications/pages/settings/settings.html @@ -24,38 +24,49 @@ - {{ 'addon.notifications.notifications' | translate }} - + +

{{ 'addon.notifications.allownotifications' | translate }}

+
+
- {{ 'addon.notifications.playsound' | translate }} - + +

{{ 'addon.notifications.playsound' | translate }}

+
+
- - - - {{ processor.displayname }} - - + + + +

{{ 'addon.notifications.typeofnotification' | translate }}

+
+ + + + {{ processor.displayname }} + + +
- - - + + + - - - + + + +
+ - + - + @@ -108,7 +119,9 @@ -

{{ notification.displayname }}

+ +

{{ notification.displayname }}

+
@@ -135,12 +148,12 @@ {{ 'core.settings.disabled' | translate }}
-
+
- + - +

{{ component.displayname }}

@@ -173,6 +186,5 @@ {{ 'core.settings.disabled' | translate }}
-
- +
diff --git a/src/addons/notifications/pages/settings/settings.scss b/src/addons/notifications/pages/settings/settings.scss index d224357cb..3a21dcc3f 100644 --- a/src/addons/notifications/pages/settings/settings.scss +++ b/src/addons/notifications/pages/settings/settings.scss @@ -1,3 +1,7 @@ .addon-notifications-table-content ion-row { min-height: 35px; } + +ion-item-divider, ion-card-header { + border-top: 1px solid var(--stroke); +} From 2a1493b649f85ea1f48b3a9e213ce7aed55d0d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 23 Nov 2022 13:41:53 +0100 Subject: [PATCH 2/3] MOBILE-4081 style: Do not use display contents on iOS core-loading --- src/core/components/loading/loading.scss | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/components/loading/loading.scss b/src/core/components/loading/loading.scss index ff665fdf2..fd377dbed 100644 --- a/src/core/components/loading/loading.scss +++ b/src/core/components/loading/loading.scss @@ -95,3 +95,11 @@ } min-height: 100%; } + + +:host-context(.ios) { + &.core-loading-loaded { + --contents-display: flex; + flex-direction: column; + } +} From f61bd0f5507c76e85a53e8fb729078ce7726c3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 23 Nov 2022 14:13:29 +0100 Subject: [PATCH 3/3] MOBILE-4081 settings: Divide space usage in sites --- .../pages/space-usage/space-usage.html | 75 +++++++--- .../settings/pages/space-usage/space-usage.ts | 136 +++++++++++++----- 2 files changed, 154 insertions(+), 57 deletions(-) diff --git a/src/core/features/settings/pages/space-usage/space-usage.html b/src/core/features/settings/pages/space-usage/space-usage.html index ad5ce1a50..ec3524adb 100644 --- a/src/core/features/settings/pages/space-usage/space-usage.html +++ b/src/core/features/settings/pages/space-usage/space-usage.html @@ -17,31 +17,70 @@ - - - -

- -

-

{{ site.fullName }}

-

{{ site.siteUrlWithoutProtocol }}

- {{ site.spaceUsage | coreBytesToSize }} -
- - - - -
+ + + + +

+ +

+

{{ + accountsList.currentSite.siteUrlWithoutProtocol }} +

+
+
+ + + + + + + + +
+ + + + +

+ +

+

{{ sites[0].siteUrlWithoutProtocol }}

+
+
+ + + + +
+

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

- {{ totals.spaceUsage | coreBytesToSize }} + {{ totalSpaceUsage | coreBytesToSize }}

+ + + + + {{ 'core.pictureof' | translate:{$a: site.fullName} }} + + +

{{site.fullName}}

+ {{ site.spaceUsage | coreBytesToSize }} +
+ + + + +
diff --git a/src/core/features/settings/pages/space-usage/space-usage.ts b/src/core/features/settings/pages/space-usage/space-usage.ts index e048d0a24..be91393f2 100644 --- a/src/core/features/settings/pages/space-usage/space-usage.ts +++ b/src/core/features/settings/pages/space-usage/space-usage.ts @@ -16,9 +16,10 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; import { IonRefresher } from '@ionic/angular'; import { CoreSiteBasicInfo, CoreSites } from '@services/sites'; +import { CoreUtils } from '@services/utils/utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; -import { CoreSettingsHelper, CoreSiteSpaceUsage } from '../../services/settings-helper'; +import { CoreSettingsHelper } from '../../services/settings-helper'; /** * Page that displays the space usage settings. @@ -30,37 +31,52 @@ import { CoreSettingsHelper, CoreSiteSpaceUsage } from '../../services/settings- export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { loaded = false; - sites: CoreSiteBasicInfoWithUsage[] = []; - currentSiteId = ''; - totals: CoreSiteSpaceUsage = { - cacheEntries: 0, - spaceUsage: 0, + totalSpaceUsage = 0; + + accountsList: CoreAccountsListWithUsage = { + sameSite: [], + otherSites: [], }; protected sitesObserver: CoreEventObserver; constructor() { - this.currentSiteId = CoreSites.getCurrentSiteId(); - this.sitesObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, async (data) => { - const site = await CoreSites.getSite(data.siteId); + const siteId = data.siteId; - const siteEntry = this.sites.find((siteEntry) => siteEntry.id == site.id); - if (siteEntry) { - const siteInfo = site.getInfo(); + let siteEntry = siteId === this.accountsList.currentSite?.id + ? this.accountsList.currentSite + : undefined; - siteEntry.siteName = site.getSiteName(); + if (!siteEntry) { + siteEntry = this.accountsList.sameSite.find((siteEntry) => siteEntry.id === siteId); + } - if (siteInfo) { - siteEntry.siteUrl = siteInfo.siteurl; - siteEntry.fullName = siteInfo.fullname; - } + if (!siteEntry) { + this.accountsList.otherSites.some((sites) => { + siteEntry = sites.find((siteEntry) => siteEntry.id === siteId); + + return siteEntry; + }); + } + + if (!siteEntry) { + return; + } + + const site = await CoreSites.getSite(siteId); + const siteInfo = site.getInfo(); + siteEntry.siteName = site.getSiteName(); + + if (siteInfo) { + siteEntry.siteUrl = siteInfo.siteurl; + siteEntry.fullName = siteInfo.fullname; } }); } /** - * View loaded. + * @inheritdoc */ ngOnInit(): void { this.loadSiteData().finally(() => { @@ -76,31 +92,65 @@ export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { protected async loadSiteData(): Promise { // Calculate total usage. let totalSize = 0; - let totalEntries = 0; - this.sites = await CoreSites.getSortedSites(); + const sites = await CoreUtils.ignoreErrors(CoreSites.getSortedSites(), [] as CoreSiteBasicInfo[]); + const sitesWithUsage = await Promise.all(sites.map((site) => this.getSiteWithUsage(site))); - const settingsHelper = CoreSettingsHelper.instance; + let siteUrl = ''; + + const currentSiteId = CoreSites.getCurrentSiteId(); + + if (currentSiteId) { + const index = sitesWithUsage.findIndex((site) => site.id === currentSiteId); + + const siteWithUsage = sitesWithUsage.splice(index, 1)[0]; + this.accountsList.currentSite = siteWithUsage; + totalSize += siteWithUsage.spaceUsage || 0; + + siteUrl = this.accountsList.currentSite.siteUrlWithoutProtocol; + } + + const otherSites: Record = {}; // Get space usage. - await Promise.all(this.sites.map(async (site) => { - const siteInfo = await settingsHelper.getSiteSpaceUsage(site.id); + sitesWithUsage.forEach((siteWithUsage) => { + totalSize += siteWithUsage.spaceUsage || 0; - site.cacheEntries = siteInfo.cacheEntries; - site.spaceUsage = siteInfo.spaceUsage; + if (siteWithUsage.siteUrlWithoutProtocol === siteUrl) { + this.accountsList.sameSite.push(siteWithUsage); + } else { + if (otherSites[siteWithUsage.siteUrlWithoutProtocol] === undefined) { + otherSites[siteWithUsage.siteUrlWithoutProtocol] = []; + } - totalSize += site.spaceUsage || 0; - totalEntries += site.cacheEntries || 0; - })); + otherSites[siteWithUsage.siteUrlWithoutProtocol].push(siteWithUsage); + } + }); - this.totals.spaceUsage = totalSize; - this.totals.cacheEntries = totalEntries; + this.accountsList.otherSites = CoreUtils.objectToArray(otherSites); + + this.totalSpaceUsage = totalSize; + } + + /** + * Get site with space usage. + * + * @param site Site to check. + * @return Site with usage. + */ + protected async getSiteWithUsage(site: CoreSiteBasicInfo): Promise { + const siteInfo = await CoreSettingsHelper.getSiteSpaceUsage(site.id); + + return Object.assign(site, { + hasCacheEntries: siteInfo.cacheEntries > 0, + spaceUsage: siteInfo.spaceUsage, + }); } /** * Refresh the data. * - * @param event Refresher event. + * @param refresher Refresher event. */ refreshData(refresher?: IonRefresher): void { this.loadSiteData().finally(() => { @@ -117,21 +167,20 @@ export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { try { const newInfo = await CoreSettingsHelper.deleteSiteStorage(siteData.siteName || '', siteData.id); - this.totals.spaceUsage -= siteData.spaceUsage! - newInfo.spaceUsage; - this.totals.spaceUsage -= siteData.cacheEntries! - newInfo.cacheEntries; + this.totalSpaceUsage -= siteData.spaceUsage - newInfo.spaceUsage; siteData.spaceUsage = newInfo.spaceUsage; - siteData.cacheEntries = newInfo.cacheEntries; + siteData.hasCacheEntries = newInfo.cacheEntries > 0; } catch { // Ignore cancelled confirmation modal. } } /** - * Page destroyed. + * @inheritdoc */ ngOnDestroy(): void { - this.sitesObserver?.off(); + this.sitesObserver.off(); } } @@ -139,7 +188,16 @@ export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { /** * Basic site info with space usage and cache entries that can be erased. */ -export interface CoreSiteBasicInfoWithUsage extends CoreSiteBasicInfo { - cacheEntries?: number; // Number of cached entries that can be cleared. - spaceUsage?: number; // Space used in this site. +interface CoreSiteBasicInfoWithUsage extends CoreSiteBasicInfo { + hasCacheEntries: boolean; // If has cached entries that can be cleared. + spaceUsage: number; // Space used in this site. } + +/** + * Accounts list for selecting sites interfaces. + */ +type CoreAccountsListWithUsage = { + currentSite?: CoreSiteBasicInfoWithUsage; // If logged in, current site info. + sameSite: CoreSiteBasicInfoWithUsage[]; // If logged in, accounts info on the same site. + otherSites: CoreSiteBasicInfoWithUsage[][]; // Other accounts in other sites. +};