diff --git a/src/core/features/settings/classes/settings-handlers-source.ts b/src/core/features/settings/classes/settings-handlers-source.ts index 30db670ce..b5da09aff 100644 --- a/src/core/features/settings/classes/settings-handlers-source.ts +++ b/src/core/features/settings/classes/settings-handlers-source.ts @@ -14,31 +14,41 @@ import { Params } from '@angular/router'; import { CoreRoutedItemsManagerSource } from '@classes/items-management/routed-items-manager-source'; -import { CoreSettingsDelegate, CoreSettingsHandlerToDisplay } from '../services/settings-delegate'; +import { + CoreSettingsDelegate, + CoreSettingsHandlerToDisplay, + CoreSettingsPageHandlerToDisplay, +} from '../services/settings-delegate'; /** * Provides a collection of site settings. */ -export class CoreSettingsHandlersSource extends CoreRoutedItemsManagerSource { +export class CoreSettingsHandlersSource extends CoreRoutedItemsManagerSource { + + handlers: CoreSettingsHandlerToDisplay[] = []; /** * @inheritdoc */ - protected async loadPageItems(): Promise<{ items: CoreSettingsHandlerToDisplay[] }> { - return { items: CoreSettingsDelegate.getHandlers() }; + protected async loadPageItems(): Promise<{ items: CoreSettingsPageHandlerToDisplay[] }> { + this.handlers = CoreSettingsDelegate.getHandlers(); + + return { + items: this.handlers.filter((handler): handler is CoreSettingsPageHandlerToDisplay => 'page' in handler), + }; } /** * @inheritdoc */ - getItemPath(handler: CoreSettingsHandlerToDisplay): string { + getItemPath(handler: CoreSettingsPageHandlerToDisplay): string { return handler.page; } /** * @inheritdoc */ - getItemQueryParams(handler: CoreSettingsHandlerToDisplay): Params { + getItemQueryParams(handler: CoreSettingsPageHandlerToDisplay): Params { return handler.params || {}; } diff --git a/src/core/features/settings/pages/site/site.html b/src/core/features/settings/pages/site/site.html index 215d5f82e..74f0eb710 100644 --- a/src/core/features/settings/pages/site/site.html +++ b/src/core/features/settings/pages/site/site.html @@ -17,14 +17,17 @@ - +

{{ handler.title | translate}}

+ +
diff --git a/src/core/features/settings/pages/site/site.ts b/src/core/features/settings/pages/site/site.ts index 4a017185b..88de8b221 100644 --- a/src/core/features/settings/pages/site/site.ts +++ b/src/core/features/settings/pages/site/site.ts @@ -15,14 +15,13 @@ import { AfterViewInit, Component, OnDestroy, ViewChild } from '@angular/core'; import { IonRefresher } from '@ionic/angular'; -import { CoreSettingsHandlerToDisplay } from '../../services/settings-delegate'; +import { CoreSettingsHandlerToDisplay, CoreSettingsPageHandlerToDisplay } from '../../services/settings-delegate'; import { CoreEventObserver, CoreEvents } from '@singletons/events'; import { CoreSites } from '@services/sites'; import { CoreNavigator } from '@services/navigator'; import { CoreSplitViewComponent } from '@components/split-view/split-view'; import { CoreListItemsManager } from '@classes/items-management/list-items-manager'; import { CoreRoutedItemsManagerSourcesTracker } from '@classes/items-management/routed-items-manager-sources-tracker'; -import { CoreSettingsHandlersSource } from '@features/settings/classes/settings-handlers-source'; import { CoreSettingsHelper } from '@features/settings/services/settings-helper'; import { CoreDomUtils } from '@services/utils/dom'; import { CoreNetwork } from '@services/network'; @@ -30,6 +29,7 @@ import { Subscription } from 'rxjs'; import { NgZone } from '@singletons'; import { CoreConstants } from '@/core/constants'; import { CoreConfig } from '@services/config'; +import { CoreSettingsHandlersSource } from '@features/settings/classes/settings-handlers-source'; /** * Page that displays the list of site settings pages. @@ -42,7 +42,7 @@ export class CoreSitePreferencesPage implements AfterViewInit, OnDestroy { @ViewChild(CoreSplitViewComponent) splitView!: CoreSplitViewComponent; - handlers: CoreListItemsManager; + handlers: CoreListItemsManager; dataSaver = false; limitedConnection = false; @@ -53,6 +53,10 @@ export class CoreSitePreferencesPage implements AfterViewInit, OnDestroy { protected networkObserver: Subscription; protected isDestroyed = false; + get handlerItems(): CoreSettingsHandlerToDisplay[] { + return this.handlers.getSource().handlers; + } + constructor() { this.siteId = CoreSites.getCurrentSiteId(); diff --git a/src/core/features/settings/services/settings-delegate.ts b/src/core/features/settings/services/settings-delegate.ts index 2d0d10fae..076d8e050 100644 --- a/src/core/features/settings/services/settings-delegate.ts +++ b/src/core/features/settings/services/settings-delegate.ts @@ -25,19 +25,9 @@ import { makeSingleton } from '@singletons'; export type CoreSettingsHandler = CoreDelegateDisplayHandler; /** - * Data needed to render a setting handler. It's returned by the handler. + * Main data returned by the handler. */ -export interface CoreSettingsHandlerData { - /** - * Name of the page to load for the handler. - */ - page: string; - - /** - * Params list of the page to load for the handler. - */ - params?: Params; - +interface CoreSettingsHandlerBaseData { /** * Title to display for the handler. */ @@ -54,11 +44,45 @@ export interface CoreSettingsHandlerData { class?: string; } +interface CoreSettingsToggleHandlerData extends CoreSettingsHandlerBaseData { + /** + * Toggle checked. + */ + toggleChecked?: boolean; + + /** + * Method for emit events to the handler. + */ + toggle(checked: boolean): void; +} + +interface CoreSettingsPageHandlerData extends CoreSettingsHandlerBaseData { + /** + * Name of the page to load for the handler. + */ + page: string; + + /** + * Params list of the page to load for the handler. + */ + params?: Params; +} + +/** + * Data needed to render a setting handler. It's returned by the handler. + */ +export type CoreSettingsHandlerData = CoreSettingsPageHandlerData | CoreSettingsToggleHandlerData; + /** * Data returned by the delegate for each handler. */ export type CoreSettingsHandlerToDisplay = CoreDelegateToDisplay & CoreSettingsHandlerData; +/** + * Data returned by the delegate for each handler to be displayed in pages. + */ +export type CoreSettingsPageHandlerToDisplay = CoreDelegateToDisplay & CoreSettingsPageHandlerData; + /** * Service to interact with addons to be shown in app settings. Provides functions to register a plugin * and notify an update in the data.