MOBILE-3565 settings: Implement settings delegate

main
Pau Ferrer Ocaña 2020-11-09 13:37:31 +01:00
parent a19a25dc51
commit d6a42f992b
16 changed files with 347 additions and 300 deletions

View File

@ -37,7 +37,7 @@ import { CoreGroupsProvider } from '@services/groups';
import { CoreInitDelegate, CoreInit } from '@services/init';
import { CoreLangProvider } from '@services/lang';
import { CoreLocalNotificationsProvider } from '@services/local-notifications';
import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CorePluginFileDelegate } from '@services/plugin-file.delegate';
import { CoreSitesProvider, CoreSites } from '@services/sites';
import { CoreSyncProvider } from '@services/sync';
import { CoreUpdateManagerProvider, CoreUpdateManager } from '@services/update-manager';

View File

@ -0,0 +1,104 @@
// (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 { BehaviorSubject, Subject } from 'rxjs';
import { CoreEvents } from '../singletons/events';
import { CoreDelegate, CoreDelegateDisplayHandler, CoreDelegateToDisplay } from './delegate';
/**
* Superclass to help creating sorted delegates.
*/
export class CoreSortedDelegate<
DisplayType extends CoreDelegateToDisplay,
HandlerType extends CoreDelegateDisplayHandler<DisplayType>>
extends CoreDelegate<HandlerType> {
protected loaded = false;
protected sortedHandlersRxJs: Subject<DisplayType[]> = new BehaviorSubject<DisplayType[]>([]);
protected sortedHandlers: DisplayType[] = [];
/**
* Constructor of the Delegate.
*
* @param delegateName Delegate name used for logging purposes.
* @param listenSiteEvents Whether to update the handler when a site event occurs (login, site updated, ...).
*/
constructor(delegateName: string) {
super(delegateName, true);
CoreEvents.on(CoreEvents.LOGOUT, this.clearSortedHandlers.bind(this));
}
/**
* Check if handlers are loaded.
*
* @return True if handlers are loaded, false otherwise.
*/
areHandlersLoaded(): boolean {
return this.loaded;
}
/**
* Clear current site handlers. Reserved for core use.
*/
protected clearSortedHandlers(): void {
this.loaded = false;
this.sortedHandlersRxJs.next([]);
this.sortedHandlers = [];
}
/**
* Get the handlers for the current site.
*
* @return An observable that will receive the handlers.
*/
getHandlers(): DisplayType[] {
return this.sortedHandlers;
}
/**
* Get the handlers for the current site.
*
* @return An observable that will receive the handlers.
*/
getHandlersObservable(): Subject<DisplayType[]> {
return this.sortedHandlersRxJs;
}
/**
* Update handlers Data.
*/
updateData(): void {
const displayData: DisplayType[] = [];
for (const name in this.enabledHandlers) {
const handler = this.enabledHandlers[name];
const data = <DisplayType> handler.getDisplayData();
data.priority = handler.priority;
data.name = handler.name;
displayData.push(data);
}
// Sort them by priority.
displayData.sort((a, b) => (b.priority || 0) - (a.priority || 0));
this.loaded = true;
this.sortedHandlersRxJs.next(displayData);
this.sortedHandlers = displayData;
}
}

View File

@ -20,7 +20,7 @@ import { CoreLogger } from '@singletons/logger';
/**
* Superclass to help creating delegates
*/
export class CoreDelegate {
export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
/**
* Logger instance.
@ -30,17 +30,17 @@ export class CoreDelegate {
/**
* List of registered handlers.
*/
protected handlers: { [s: string]: CoreDelegateHandler } = {};
protected handlers: { [s: string]: HandlerType } = {};
/**
* List of registered handlers enabled for the current site.
*/
protected enabledHandlers: { [s: string]: CoreDelegateHandler } = {};
protected enabledHandlers: { [s: string]: HandlerType } = {};
/**
* Default handler
*/
protected defaultHandler?: CoreDelegateHandler;
protected defaultHandler?: HandlerType;
/**
* Time when last updateHandler functions started.
@ -136,7 +136,7 @@ export class CoreDelegate {
* @param params Parameters to pass to the function.
* @return Function returned value or default value.
*/
private execute<T = unknown>(handler: CoreDelegateHandler, fnName: string, params?: unknown[]): T | undefined {
private execute<T = unknown>(handler: HandlerType, fnName: string, params?: unknown[]): T | undefined {
if (handler && handler[fnName]) {
return handler[fnName].apply(handler, params);
} else if (this.defaultHandler && this.defaultHandler[fnName]) {
@ -151,7 +151,7 @@ export class CoreDelegate {
* @param enabled Only enabled, or any.
* @return Handler.
*/
protected getHandler(handlerName: string, enabled: boolean = false): CoreDelegateHandler {
protected getHandler(handlerName: string, enabled: boolean = false): HandlerType {
return enabled ? this.enabledHandlers[handlerName] : this.handlers[handlerName];
}
@ -218,7 +218,7 @@ export class CoreDelegate {
* @param handler The handler delegate object to register.
* @return True when registered, false if already registered.
*/
registerHandler(handler: CoreDelegateHandler): boolean {
registerHandler(handler: HandlerType): boolean {
const key = handler[this.handlerNameProperty] || handler.name;
if (typeof this.handlers[key] !== 'undefined') {
@ -240,7 +240,7 @@ export class CoreDelegate {
* @param time Time this update process started.
* @return Resolved when done.
*/
protected updateHandler(handler: CoreDelegateHandler): Promise<void> {
protected updateHandler(handler: HandlerType): Promise<void> {
const siteId = CoreSites.instance.getCurrentSiteId();
const currentSite = CoreSites.instance.getCurrentSite();
let promise: Promise<boolean>;
@ -287,7 +287,7 @@ export class CoreDelegate {
* @param site Site to check.
* @return Whether is enabled or disabled in site.
*/
protected isFeatureDisabled(handler: CoreDelegateHandler, site: CoreSite): boolean {
protected isFeatureDisabled(handler: HandlerType, site: CoreSite): boolean {
return typeof this.featurePrefix != 'undefined' && site.isFeatureDisabled(this.featurePrefix + handler.name);
}
@ -334,6 +334,9 @@ export class CoreDelegate {
}
/**
* Base interface for any delegate.
*/
export interface CoreDelegateHandler {
/**
* Name of the handler, or name and sub context (AddonMessages, AddonMessages:blockContact, ...).
@ -348,3 +351,35 @@ export interface CoreDelegateHandler {
*/
isEnabled(): Promise<boolean>;
}
/**
* Data returned by the delegate for each handler to be displayed.
*/
export interface CoreDelegateToDisplay {
/**
* Name of the handler.
*/
name?: string;
/**
* Priority of the handler.
*/
priority?: number;
}
/**
* Base interface for a core delegate needed to be displayed.
*/
export interface CoreDelegateDisplayHandler<HandlerData extends CoreDelegateToDisplay> extends CoreDelegateHandler {
/**
* The highest priority is displayed first.
*/
priority?: number;
/**
* Returns the data needed to render the handler.
*
* @return Data.
*/
getDisplayData(): HandlerData;
}

View File

@ -16,7 +16,7 @@ import { Component, Input, Output, OnInit, OnDestroy, EventEmitter } from '@angu
import { CoreApp } from '@services/app';
import { CoreFilepool } from '@services/filepool';
import { CoreFileHelper } from '@services/file-helper';
import { CorePluginFileDelegate } from '@services/plugin-file-delegate';
import { CorePluginFileDelegate } from '@services/plugin-file.delegate';
import { CoreSites } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { CoreMimetypeUtils } from '@services/utils/mimetype';

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../services/delegate';
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '../services/mainmenu.delegate';
/**
* Handler to add Home into main menu.

View File

@ -21,7 +21,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CoreMainMenuDelegate } from './services/delegate';
import { CoreMainMenuDelegate } from './services/mainmenu.delegate';
import { CoreMainMenuRoutingModule } from './mainmenu-routing.module';
import { CoreMainMenuPage } from './pages/menu/menu.page';

View File

@ -44,7 +44,7 @@ export class CoreHomePage implements OnInit {
* Initialize the component.
*/
ngOnInit(): void {
this.subscription = this.homeDelegate.getHandlers().subscribe((handlers) => {
this.subscription = this.homeDelegate.getHandlersObservable().subscribe((handlers) => {
handlers && this.initHandlers(handlers);
});
}

View File

@ -21,7 +21,7 @@ import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites';
import { CoreEvents, CoreEventObserver, CoreEventLoadPageMainMenuData } from '@singletons/events';
import { CoreMainMenu } from '../../services/mainmenu';
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/delegate';
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from '../../services/mainmenu.delegate';
import { CoreDomUtils } from '@/app/services/utils/dom';
import { Translate } from '@/app/singletons/core.singletons';
@ -97,7 +97,7 @@ export class CoreMainMenuPage implements OnInit, OnDestroy {
}
});
this.subscription = this.menuDelegate.getHandlers().subscribe((handlers) => {
this.subscription = this.menuDelegate.getHandlersObservable().subscribe((handlers) => {
// Remove the handlers that should only appear in the More menu.
this.allHandlers = handlers.filter((handler) => !handler.onlyInMore);

View File

@ -19,7 +19,7 @@ import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { CoreSiteInfo } from '@classes/site';
import { CoreLoginHelper } from '@core/login/services/helper';
import { CoreMainMenuDelegate, CoreMainMenuHandlerData } from '../../services/delegate';
import { CoreMainMenuDelegate, CoreMainMenuHandlerData } from '../../services/mainmenu.delegate';
import { CoreMainMenu, CoreMainMenuCustomItem } from '../../services/mainmenu';
import { CoreEventObserver, CoreEvents } from '@singletons/events';
@ -69,7 +69,7 @@ export class CoreMainMenuMorePage implements OnInit, OnDestroy {
*/
ngOnInit(): void {
// Load the handlers.
this.subscription = this.menuDelegate.getHandlers().subscribe((handlers) => {
this.subscription = this.menuDelegate.getHandlersObservable().subscribe((handlers) => {
this.allHandlers = handlers;
this.initHandlers();
@ -149,20 +149,6 @@ export class CoreMainMenuMorePage implements OnInit, OnDestroy {
// @todo
}
/**
* Open app settings page.
*/
openAppSettings(): void {
// @todo
}
/**
* Open site settings page.
*/
openSitePreferences(): void {
// @todo
}
/**
* Scan and treat a QR code.
*/

View File

@ -1,177 +0,0 @@
// (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 { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { Subject, BehaviorSubject } from 'rxjs';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreEvents } from '@singletons/events';
/**
* Interface that all main menu handlers must implement.
*/
export interface CoreMainMenuHandler extends CoreDelegateHandler {
/**
* The highest priority is displayed first.
*/
priority?: number;
/**
* Returns the data needed to render the handler.
*
* @return Data.
*/
getDisplayData(): CoreMainMenuHandlerData;
}
/**
* Data needed to render a main menu handler. It's returned by the handler.
*/
export interface CoreMainMenuHandlerData {
/**
* Name of the page to load for the handler.
*/
page: string;
/**
* Title to display for the handler.
*/
title: string;
/**
* Name of the icon to display for the handler.
*/
icon: string; // Name of the icon to display in the tab.
/**
* Class to add to the displayed handler.
*/
class?: string;
/**
* If the handler has badge to show or not.
*/
showBadge?: boolean;
/**
* Text to display on the badge. Only used if showBadge is true.
*/
badge?: string;
/**
* If true, the badge number is being loaded. Only used if showBadge is true.
*/
loading?: boolean;
/**
* Params to pass to the page.
*/
pageParams?: Params;
/**
* Whether the handler should only appear in More menu.
*/
onlyInMore?: boolean;
}
/**
* Data returned by the delegate for each handler.
*/
export interface CoreMainMenuHandlerToDisplay extends CoreMainMenuHandlerData {
/**
* Name of the handler.
*/
name?: string;
/**
* Priority of the handler.
*/
priority?: number;
/**
* Hide tab. Used then resizing.
*/
hide?: boolean;
}
/**
* Service to interact with plugins to be shown in the main menu. Provides functions to register a plugin
* and notify an update in the data.
*/
@Injectable({
providedIn: 'root',
})
export class CoreMainMenuDelegate extends CoreDelegate {
protected loaded = false;
protected siteHandlers: Subject<CoreMainMenuHandlerToDisplay[]> = new BehaviorSubject<CoreMainMenuHandlerToDisplay[]>([]);
protected featurePrefix = 'CoreMainMenuDelegate_';
constructor() {
super('CoreMainMenuDelegate', true);
CoreEvents.on(CoreEvents.LOGOUT, this.clearSiteHandlers.bind(this));
}
/**
* Check if handlers are loaded.
*
* @return True if handlers are loaded, false otherwise.
*/
areHandlersLoaded(): boolean {
return this.loaded;
}
/**
* Clear current site handlers. Reserved for core use.
*/
protected clearSiteHandlers(): void {
this.loaded = false;
this.siteHandlers.next([]);
}
/**
* Get the handlers for the current site.
*
* @return An observable that will receive the handlers.
*/
getHandlers(): Subject<CoreMainMenuHandlerToDisplay[]> {
return this.siteHandlers;
}
/**
* Update handlers Data.
*/
updateData(): void {
const displayData: CoreMainMenuHandlerToDisplay[] = [];
for (const name in this.enabledHandlers) {
const handler = <CoreMainMenuHandler> this.enabledHandlers[name];
const data = <CoreMainMenuHandlerToDisplay> handler.getDisplayData();
data.name = name;
data.priority = handler.priority;
displayData.push(data);
}
// Sort them by priority.
displayData.sort((a, b) => (b.priority || 0) - (a.priority || 0));
this.loaded = true;
this.siteHandlers.next(displayData);
}
}

View File

@ -14,27 +14,14 @@
import { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { Subject, BehaviorSubject } from 'rxjs';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreEvents } from '@singletons/events';
import { CoreDelegateDisplayHandler, CoreDelegateToDisplay } from '@classes/delegate';
import { CoreSortedDelegate } from '@classes/delegate-sorted';
/**
* Interface that all main menu handlers must implement.
* Interface that all home handlers must implement.
*/
export interface CoreHomeHandler extends CoreDelegateHandler {
/**
* The highest priority is displayed first.
*/
priority?: number;
/**
* Returns the data needed to render the handler.
*
* @return Data.
*/
getDisplayData(): CoreHomeHandlerData;
}
export type CoreHomeHandler = CoreDelegateDisplayHandler<CoreHomeHandlerToDisplay>;
/**
* Data needed to render a main menu handler. It's returned by the handler.
@ -84,17 +71,7 @@ export interface CoreHomeHandlerData {
/**
* Data returned by the delegate for each handler.
*/
export interface CoreHomeHandlerToDisplay extends CoreHomeHandlerData {
/**
* Name of the handler.
*/
name?: string;
/**
* Priority of the handler.
*/
priority?: number;
export interface CoreHomeHandlerToDisplay extends CoreDelegateToDisplay, CoreHomeHandlerData {
/**
* Priority to select handler.
*/
@ -108,65 +85,12 @@ export interface CoreHomeHandlerToDisplay extends CoreHomeHandlerData {
@Injectable({
providedIn: 'root',
})
export class CoreHomeDelegate extends CoreDelegate {
export class CoreHomeDelegate extends CoreSortedDelegate<CoreHomeHandlerToDisplay, CoreHomeHandler> {
protected loaded = false;
protected siteHandlers: Subject<CoreHomeHandlerToDisplay[]> = new BehaviorSubject<CoreHomeHandlerToDisplay[]>([]);
protected featurePrefix = 'CoreHomeDelegate_';
constructor() {
super('CoreHomeDelegate', true);
CoreEvents.on(CoreEvents.LOGOUT, this.clearSiteHandlers.bind(this));
}
/**
* Check if handlers are loaded.
*
* @return True if handlers are loaded, false otherwise.
*/
areHandlersLoaded(): boolean {
return this.loaded;
}
/**
* Clear current site handlers. Reserved for core use.
*/
protected clearSiteHandlers(): void {
this.loaded = false;
this.siteHandlers.next([]);
}
/**
* Get the handlers for the current site.
*
* @return An observable that will receive the handlers.
*/
getHandlers(): Subject<CoreHomeHandlerToDisplay[]> {
return this.siteHandlers;
}
/**
* Update handlers Data.
*/
updateData(): void {
const displayData: CoreHomeHandlerToDisplay[] = [];
for (const name in this.enabledHandlers) {
const handler = <CoreHomeHandler> this.enabledHandlers[name];
const data = <CoreHomeHandlerToDisplay> handler.getDisplayData();
data.name = name;
data.priority = handler.priority;
displayData.push(data);
}
// Sort them by priority.
displayData.sort((a, b) => (b.priority || 0) - (a.priority || 0));
this.loaded = true;
this.siteHandlers.next(displayData);
super('CoreHomeDelegate');
}
}

View File

@ -0,0 +1,101 @@
// (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 { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { CoreDelegateDisplayHandler, CoreDelegateToDisplay } from '@classes/delegate';
import { CoreSortedDelegate } from '@classes/delegate-sorted';
/**
* Interface that all main menu handlers must implement.
*/
export type CoreMainMenuHandler = CoreDelegateDisplayHandler<CoreMainMenuHandlerToDisplay>;
/**
* Data needed to render a main menu handler. It's returned by the handler.
*/
export interface CoreMainMenuHandlerData {
/**
* Name of the page to load for the handler.
*/
page: string;
/**
* Title to display for the handler.
*/
title: string;
/**
* Name of the icon to display for the handler.
*/
icon: string; // Name of the icon to display in the tab.
/**
* Class to add to the displayed handler.
*/
class?: string;
/**
* If the handler has badge to show or not.
*/
showBadge?: boolean;
/**
* Text to display on the badge. Only used if showBadge is true.
*/
badge?: string;
/**
* If true, the badge number is being loaded. Only used if showBadge is true.
*/
loading?: boolean;
/**
* Params to pass to the page.
*/
pageParams?: Params;
/**
* Whether the handler should only appear in More menu.
*/
onlyInMore?: boolean;
}
/**
* Data returned by the delegate for each handler.
*/
export interface CoreMainMenuHandlerToDisplay extends CoreDelegateToDisplay, CoreMainMenuHandlerData {
/**
* Hide tab. Used then resizing.
*/
hide?: boolean;
}
/**
* Service to interact with plugins to be shown in the main menu. Provides functions to register a plugin
* and notify an update in the data.
*/
@Injectable({
providedIn: 'root',
})
export class CoreMainMenuDelegate extends CoreSortedDelegate<CoreMainMenuHandlerToDisplay, CoreMainMenuHandler> {
protected featurePrefix = 'CoreMainMenuDelegate_';
constructor() {
super('CoreMainMenuDelegate');
}
}

View File

@ -19,7 +19,7 @@ import { CoreLang } from '@services/lang';
import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
import { CoreConstants } from '@core/constants';
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from './delegate';
import { CoreMainMenuDelegate, CoreMainMenuHandlerToDisplay } from './mainmenu.delegate';
import { makeSingleton } from '@singletons/core.singletons';
/**
@ -47,7 +47,7 @@ export class CoreMainMenuProvider {
getCurrentMainMenuHandlers(): Promise<CoreMainMenuHandlerToDisplay[]> {
const deferred = CoreUtils.instance.promiseDefer<CoreMainMenuHandlerToDisplay[]>();
const subscription = this.menuDelegate.getHandlers().subscribe((handlers) => {
const subscription = this.menuDelegate.getHandlersObservable().subscribe((handlers) => {
subscription?.unsubscribe();
// Remove the handlers that should only appear in the More menu.

View File

@ -0,0 +1,74 @@
// (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 { Injectable } from '@angular/core';
import { Params } from '@angular/router';
import { CoreDelegateDisplayHandler, CoreDelegateToDisplay } from '@classes/delegate';
import { CoreSortedDelegate } from '@classes/delegate-sorted';
/**
* Interface that all settings handlers must implement.
*/
export type CoreSettingsHandler = CoreDelegateDisplayHandler<CoreSettingsHandlerToDisplay>;
/**
* Data needed to render a setting handler. It's 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;
/**
* Title to display for the handler.
*/
title: string;
/**
* Name of the icon to display for the handler.
*/
icon?: string; // Name of the icon to display in the menu.
/**
* Class to add to the displayed handler.
*/
class?: string;
}
/**
* Data returned by the delegate for each handler.
*/
export type CoreSettingsHandlerToDisplay = CoreDelegateToDisplay & CoreSettingsHandlerData;
/**
* Service to interact with addons to be shown in app settings. Provides functions to register a plugin
* and notify an update in the data.
*/
@Injectable({
providedIn: 'root',
})
export class CoreSettingsDelegate extends CoreSortedDelegate<CoreSettingsHandlerToDisplay, CoreSettingsHandler> {
constructor() {
super('CoreSettingsDelegate');
}
}

View File

@ -19,7 +19,7 @@ import { CoreApp } from '@services/app';
import { CoreEvents } from '@singletons/events';
import { CoreFile } from '@services/file';
import { CoreInit } from '@services/init';
import { CorePluginFile } from '@services/plugin-file-delegate';
import { CorePluginFile } from '@services/plugin-file.delegate';
import { CoreSites } from '@services/sites';
import { CoreWS, CoreWSExternalFile } from '@services/ws';
import { CoreDomUtils } from '@services/utils/dom';

View File

@ -25,7 +25,7 @@ import { makeSingleton } from '@singletons/core.singletons';
* Delegate to register pluginfile information handlers.
*/
@Injectable()
export class CorePluginFileDelegate extends CoreDelegate {
export class CorePluginFileDelegate extends CoreDelegate<CorePluginFileHandler> {
protected handlerNameProperty = 'component';
@ -98,7 +98,7 @@ export class CorePluginFileDelegate extends CoreDelegate {
*/
getComponentRevisionRegExp(args: string[]): RegExp | void {
// Get handler based on component (args[1]).
const handler = <CorePluginFileHandler> this.getHandler(args[1], true);
const handler = this.getHandler(args[1], true);
if (handler && handler.getComponentRevisionRegExp) {
return handler.getComponentRevisionRegExp(args);
@ -116,7 +116,7 @@ export class CorePluginFileDelegate extends CoreDelegate {
let files = <string[]>[];
for (const component in this.enabledHandlers) {
const handler = <CorePluginFileHandler> this.enabledHandlers[component];
const handler = this.enabledHandlers[component];
if (handler && handler.getDownloadableFilesFromHTML) {
files = files.concat(handler.getDownloadableFilesFromHTML(container));
@ -217,7 +217,7 @@ export class CorePluginFileDelegate extends CoreDelegate {
*/
protected getHandlerForFile(file: CoreWSExternalFile): CorePluginFileHandler | undefined {
for (const component in this.enabledHandlers) {
const handler = <CorePluginFileHandler> this.enabledHandlers[component];
const handler = this.enabledHandlers[component];
if (handler && handler.shouldHandleFile && handler.shouldHandleFile(file)) {
return handler;
@ -252,7 +252,7 @@ export class CorePluginFileDelegate extends CoreDelegate {
*/
removeRevisionFromUrl(url: string, args: string[]): string {
// Get handler based on component (args[1]).
const handler = <CorePluginFileHandler> this.getHandler(args[1], true);
const handler = this.getHandler(args[1], true);
if (handler && handler.getComponentRevisionRegExp && handler.getComponentRevisionReplace) {
const revisionRegex = handler.getComponentRevisionRegExp(args);