diff --git a/src/core/components/components.module.ts b/src/core/components/components.module.ts index fc64175b1..fd78701a6 100644 --- a/src/core/components/components.module.ts +++ b/src/core/components/components.module.ts @@ -65,6 +65,7 @@ import { CoreGroupSelectorComponent } from './group-selector/group-selector'; import { CoreRefreshButtonModalComponent } from './refresh-button-modal/refresh-button-modal'; import { CoreSheetModalComponent } from '@components/sheet-modal/sheet-modal'; import { CoreCourseImageComponent } from '@components/course-image/course-image'; +import { CoreSitesListComponent } from './sites-list/sites-list'; @NgModule({ declarations: [ @@ -112,6 +113,7 @@ import { CoreCourseImageComponent } from '@components/course-image/course-image' CoreSwipeNavigationTourComponent, CoreRefreshButtonModalComponent, CoreSheetModalComponent, + CoreSitesListComponent, ], imports: [ CommonModule, @@ -166,6 +168,7 @@ import { CoreCourseImageComponent } from '@components/course-image/course-image' CoreSwipeNavigationTourComponent, CoreRefreshButtonModalComponent, CoreSheetModalComponent, + CoreSitesListComponent, ], }) export class CoreComponentsModule {} diff --git a/src/core/components/sites-list/sites-list.html b/src/core/components/sites-list/sites-list.html new file mode 100644 index 000000000..99cc0bc53 --- /dev/null +++ b/src/core/components/sites-list/sites-list.html @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +

+ +

+

+ + {{ site.siteUrlWithoutProtocol }} + +

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

{{site.fullname}}

+ + +
+ + + +
+
diff --git a/src/core/features/login/sitelist.scss b/src/core/components/sites-list/sites-list.scss similarity index 71% rename from src/core/features/login/sitelist.scss rename to src/core/components/sites-list/sites-list.scss index 22a83f842..57b45009f 100644 --- a/src/core/features/login/sitelist.scss +++ b/src/core/components/sites-list/sites-list.scss @@ -1,5 +1,5 @@ -ion-list.core-sitelist { - .core-sitelist-sitename { +ion-list.core-sites-list { + .core-sites-list-sitename { ion-label { margin-top: 8px; margin-bottom: 8px; diff --git a/src/core/components/sites-list/sites-list.ts b/src/core/components/sites-list/sites-list.ts new file mode 100644 index 000000000..57477b125 --- /dev/null +++ b/src/core/components/sites-list/sites-list.ts @@ -0,0 +1,80 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, ContentChild, Input, Output, TemplateRef, EventEmitter } from '@angular/core'; + +import { CoreSiteBasicInfo } from '@services/sites'; +import { CoreAccountsList } from '@features/login/services/login-helper'; + +/** + * Component to display a list of sites (accounts). + * + * By default this component will display the avatar and user fullname for each site, but it allows adding more information + * in the item and in the label for each site, using #siteItem and #siteLabel ng-templates. These templates will receive the + * site being rendered and whether it's the current site or not. Example: + * + * + * + * - - - - - -

{{site.fullname}}

-
- - - {{ 'core.login.sitebadgedescription' | translate:{ count: site.badge } - }} - - - - -
-
diff --git a/src/core/features/login/components/sites/sites.ts b/src/core/features/login/components/sites/sites.ts index bcd7be96d..fb873b29d 100644 --- a/src/core/features/login/components/sites/sites.ts +++ b/src/core/features/login/components/sites/sites.ts @@ -28,7 +28,6 @@ import { ModalController } from '@singletons'; @Component({ selector: 'core-login-sites', templateUrl: 'sites.html', - styleUrls: ['../../sitelist.scss'], animations: [CoreAnimations.SLIDE_IN_OUT, CoreAnimations.SHOW_HIDE], }) export class CoreLoginSitesComponent implements OnInit { @@ -99,15 +98,14 @@ export class CoreLoginSitesComponent implements OnInit { /** * Login in a site. * - * @param event Click event. - * @param siteId The site ID. + * @param site The site. * @returns Promise resolved when done. */ - async login(event: Event, siteId: string): Promise { - await this.close(event, true); + async login(site: CoreSiteBasicInfo): Promise { + await this.close(undefined, true); // This navigation will logout and navigate to the site home. - await CoreNavigator.navigateToSiteHome({ preferCurrentTab: false , siteId }); + await CoreNavigator.navigateToSiteHome({ preferCurrentTab: false , siteId: site.id }); } /** @@ -122,9 +120,9 @@ export class CoreLoginSitesComponent implements OnInit { * * @param event Click event. */ - async close(event: Event, closeAll = false): Promise { - event.preventDefault(); - event.stopPropagation(); + async close(event?: Event, closeAll = false): Promise { + event?.preventDefault(); + event?.stopPropagation(); await ModalController.dismiss(closeAll); } diff --git a/src/core/features/login/pages/sites/sites.html b/src/core/features/login/pages/sites/sites.html index d5901198b..a6cbe0f01 100644 --- a/src/core/features/login/pages/sites/sites.html +++ b/src/core/features/login/pages/sites/sites.html @@ -21,37 +21,19 @@ - - - - -

- -

-

- {{ sites[0].siteUrlWithoutProtocol }} -

-
-
- - - - - -

{{site.fullname}}

-
- - - {{ 'core.login.sitebadgedescription' | translate:{ count: site.badge } - }} - - - - -
-
-
+ + + + + {{ 'core.login.sitebadgedescription' | translate:{ count: site.badge } + }} + + + + + +
diff --git a/src/core/features/login/pages/sites/sites.ts b/src/core/features/login/pages/sites/sites.ts index 2d7f4c549..38a8d4bb3 100644 --- a/src/core/features/login/pages/sites/sites.ts +++ b/src/core/features/login/pages/sites/sites.ts @@ -22,12 +22,11 @@ import { CoreFilter } from '@features/filter/services/filter'; import { CoreAnimations } from '@components/animations'; /** - * Page that displays a "splash screen" while the app is being initialized. + * Page that displays the list of sites stored in the device. */ @Component({ selector: 'page-core-login-sites', templateUrl: 'sites.html', - styleUrls: ['../../sitelist.scss'], animations: [CoreAnimations.SLIDE_IN_OUT, CoreAnimations.SHOW_HIDE], }) export class CoreLoginSitesPage implements OnInit { @@ -102,18 +101,14 @@ export class CoreLoginSitesPage implements OnInit { /** * Login in a site. * - * @param event Click event. - * @param siteId The site ID. + * @param site The site. * @returns Promise resolved when done. */ - async login(event: Event, siteId: string): Promise { - event.preventDefault(); - event.stopPropagation(); - + async login(site: CoreSiteBasicInfo): Promise { const modal = await CoreDomUtils.showModalLoading(); try { - const loggedIn = await CoreSites.loadSite(siteId); + const loggedIn = await CoreSites.loadSite(site.id); if (loggedIn) { await CoreNavigator.navigateToSiteHome(); diff --git a/src/core/features/login/services/login-helper.ts b/src/core/features/login/services/login-helper.ts index 5905764cd..d2b1abf64 100644 --- a/src/core/features/login/services/login-helper.ts +++ b/src/core/features/login/services/login-helper.ts @@ -1541,10 +1541,10 @@ export const CoreLoginHelper = makeSingleton(CoreLoginHelperProvider); /** * Accounts list for selecting sites interfaces. */ -export type CoreAccountsList = { - currentSite?: CoreSiteBasicInfo; // If logged in, current site info. - sameSite: CoreSiteBasicInfo[]; // If logged in, accounts info on the same site. - otherSites: CoreSiteBasicInfo[][]; // Other accounts in other sites. +export type CoreAccountsList = { + currentSite?: T; // If logged in, current site info. + sameSite: T[]; // If logged in, accounts info on the same site. + otherSites: T[][]; // Other accounts in other sites. count: number; // Number of sites. }; 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 388809ba4..939553d14 100644 --- a/src/core/features/settings/pages/space-usage/space-usage.html +++ b/src/core/features/settings/pages/space-usage/space-usage.html @@ -17,47 +17,21 @@ - - - - -

- -

-

- - {{ accountsList.currentSite.siteUrlWithoutProtocol }} - -

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

- -

-

- {{ sites[0].siteUrlWithoutProtocol }} -

-
-
- - - - -
+ + + + + + +
@@ -70,19 +44,3 @@ - - - - - - -

{{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 62a82a743..7a3265a2c 100644 --- a/src/core/features/settings/pages/space-usage/space-usage.ts +++ b/src/core/features/settings/pages/space-usage/space-usage.ts @@ -20,6 +20,7 @@ import { CoreUtils } from '@services/utils/utils'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSettingsHelper } from '../../services/settings-helper'; +import { CoreAccountsList } from '@features/login/services/login-helper'; /** * Page that displays the space usage settings. @@ -33,9 +34,10 @@ export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { loaded = false; totalSpaceUsage = 0; - accountsList: CoreAccountsListWithUsage = { + accountsList: CoreAccountsList = { sameSite: [], otherSites: [], + count: 0, }; protected sitesObserver: CoreEventObserver; @@ -128,6 +130,7 @@ export class CoreSettingsSpaceUsagePage implements OnInit, OnDestroy { }); this.accountsList.otherSites = CoreUtils.objectToArray(otherSites); + this.accountsList.count = sites.length; this.totalSpaceUsage = totalSize; } @@ -192,12 +195,3 @@ 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. -}; diff --git a/src/core/features/settings/pages/synchronization/synchronization.html b/src/core/features/settings/pages/synchronization/synchronization.html index 84b1dc163..ab6439509 100644 --- a/src/core/features/settings/pages/synchronization/synchronization.html +++ b/src/core/features/settings/pages/synchronization/synchronization.html @@ -17,7 +17,7 @@ - +

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

@@ -51,65 +51,25 @@
- - - -

- -

-

- - {{ accountsList.currentSite.siteUrlWithoutProtocol }} - -

-
-
+ + +

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

+
- - - - - - - -
- - - - -

- -

-

- {{ sites[0].siteUrlWithoutProtocol }} -

-
-
- - - - -
+ + + + + + + + + + +
- - - - - - -

{{site.fullname}}

-

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

-
- - - - - - - - -
diff --git a/src/core/features/settings/pages/synchronization/synchronization.ts b/src/core/features/settings/pages/synchronization/synchronization.ts index dd80abad3..513885173 100644 --- a/src/core/features/settings/pages/synchronization/synchronization.ts +++ b/src/core/features/settings/pages/synchronization/synchronization.ts @@ -32,7 +32,6 @@ import { CoreNavigator } from '@services/navigator'; @Component({ selector: 'page-core-app-settings-synchronization', templateUrl: 'synchronization.html', - styleUrls: ['../../../login/sitelist.scss'], }) export class CoreSettingsSynchronizationPage implements OnInit, OnDestroy { diff --git a/src/core/features/sharedfiles/pages/choose-site/choose-site.html b/src/core/features/sharedfiles/pages/choose-site/choose-site.html index 61512f48b..4c56c753d 100644 --- a/src/core/features/sharedfiles/pages/choose-site/choose-site.html +++ b/src/core/features/sharedfiles/pages/choose-site/choose-site.html @@ -17,17 +17,8 @@

{{fileName}}

- - - - -

{{site.fullname}}

-

- -

-

{{site.siteUrl}}

-
-
+ + diff --git a/src/core/features/sharedfiles/pages/choose-site/choose-site.ts b/src/core/features/sharedfiles/pages/choose-site/choose-site.ts index b42d1fded..115e190de 100644 --- a/src/core/features/sharedfiles/pages/choose-site/choose-site.ts +++ b/src/core/features/sharedfiles/pages/choose-site/choose-site.ts @@ -13,6 +13,7 @@ // limitations under the License. import { Component, OnInit } from '@angular/core'; +import { CoreAccountsList, CoreLoginHelper } from '@features/login/services/login-helper'; import { CoreSharedFilesHelper } from '@features/sharedfiles/services/sharedfiles-helper'; import { FileEntry } from '@ionic-native/file/ngx'; import { CoreFile } from '@services/file'; @@ -30,8 +31,12 @@ import { CoreDomUtils } from '@services/utils/dom'; export class CoreSharedFilesChooseSitePage implements OnInit { fileName?: string; - sites?: CoreSiteBasicInfo[]; loaded = false; + accountsList: CoreAccountsList = { + sameSite: [], + otherSites: [], + count: 0, + }; protected filePath?: string; protected fileEntry?: FileEntry; @@ -89,15 +94,15 @@ export class CoreSharedFilesChooseSitePage implements OnInit { * @returns Promise resolved when done. */ protected async loadSites(): Promise { - this.sites = await CoreSites.getSites(); + this.accountsList = await CoreLoginHelper.getAccountsList(CoreSites.getCurrentSiteId()); } /** * Store the file in a certain site. * - * @param siteId Site ID. + * @param site Site. */ - async storeInSite(siteId: string): Promise { + async storeInSite(site: CoreSiteBasicInfo): Promise { if (!this.fileEntry) { return; } @@ -105,7 +110,7 @@ export class CoreSharedFilesChooseSitePage implements OnInit { this.loaded = false; try { - await CoreSharedFilesHelper.storeSharedFileInSite(this.fileEntry, siteId, this.isInbox); + await CoreSharedFilesHelper.storeSharedFileInSite(this.fileEntry, site.id, this.isInbox); CoreNavigator.back(); } finally {