Merge pull request #3964 from crazyserver/MOBILE-4538

Mobile 4538
main
Dani Palou 2024-03-11 14:01:28 +01:00 committed by GitHub
commit 162a618780
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
42 changed files with 353 additions and 350 deletions

View File

@ -75,7 +75,7 @@ export class AddonMessageOutputDelegateService extends CoreDelegate<AddonMessage
protected handlerNameProperty = 'processorName';
constructor() {
super('AddonMessageOutputDelegate', true);
super('AddonMessageOutputDelegate');
}
/**

View File

@ -0,0 +1,15 @@
// (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.
export const ADDON_MOD_ASSIGN_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModAssign';

View File

@ -60,11 +60,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Discard the draft data of the feedback plugin.
*
* @param assignId The assignment ID.
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @inheritdoc
*/
discardDraft(assignId: number, userId: number, siteId?: string): void {
const id = this.getDraftId(assignId, userId, siteId);
@ -74,22 +70,14 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Return the Component to use to display the plugin data.
* It's recommended to return the class of the component, but you can also return an instance of the component.
*
* @returns The component (or promise resolved with component) to use, undefined if not found.
* @inheritdoc
*/
getComponent(): Type<IAddonModAssignFeedbackPluginComponent> {
return AddonModAssignFeedbackCommentsComponent;
}
/**
* Return the draft saved data of the feedback plugin.
*
* @param assignId The assignment ID.
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @returns Data (or promise resolved with the data).
* @inheritdoc
*/
getDraft(assignId: number, userId: number, siteId?: string): AddonModAssignFeedbackCommentsDraftData | undefined {
const id = this.getDraftId(assignId, userId, siteId);
@ -114,13 +102,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Get files used by this plugin.
* The files returned by this function will be prefetched when the user prefetches the assign.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The files (or promise resolved with the files).
* @inheritdoc
*/
getPluginFiles(
assign: AddonModAssignAssign,
@ -131,14 +113,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Check if the feedback data has changed for this plugin.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param inputData Data entered by the user for the feedback.
* @param userId User ID of the submission.
* @returns Boolean (or promise resolved with boolean): whether the data has changed.
* @inheritdoc
*/
async hasDataChanged(
assign: AddonModAssignAssign,
@ -172,12 +147,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Check whether the plugin has draft data stored.
*
* @param assignId The assignment ID.
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @returns Boolean or promise resolved with boolean: whether the plugin has draft data.
* @inheritdoc
*/
hasDraftData(assignId: number, userId: number, siteId?: string): boolean | Promise<boolean> {
const draft = this.getDraft(assignId, userId, siteId);
@ -186,9 +156,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Whether or not the handler is enabled on a site level.
*
* @returns True or promise resolved with true if enabled.
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
// In here we should check if comments is not disabled in site.
@ -198,13 +166,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Prepare and add to pluginData the data to send to the server based on the draft data saved.
*
* @param assignId The assignment ID.
* @param userId User ID.
* @param plugin The plugin object.
* @param pluginData Object where to store the data to send.
* @param siteId Site ID. If not defined, current site.
* @inheritdoc
*/
prepareFeedbackData(
assignId: number,
@ -225,13 +187,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}
/**
* Save draft data of the feedback plugin.
*
* @param assignId The assignment ID.
* @param userId User ID.
* @param plugin The plugin object.
* @param data The data to save.
* @param siteId Site ID. If not defined, current site.
* @inheritdoc
*/
saveDraft(
assignId: number,

View File

@ -35,23 +35,14 @@ export class AddonModAssignFeedbackEditPdfHandlerService implements AddonModAssi
type = 'editpdf';
/**
* Return the Component to use to display the plugin data.
* It's recommended to return the class of the component, but you can also return an instance of the component.
*
* @returns The component (or promise resolved with component) to use, undefined if not found.
* @inheritdoc
*/
getComponent(): Type<IAddonModAssignFeedbackPluginComponent> {
return AddonModAssignFeedbackEditPdfComponent;
}
/**
* Get files used by this plugin.
* The files returned by this function will be prefetched when the user prefetches the assign.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The files (or promise resolved with the files).
* @inheritdoc
*/
getPluginFiles(
assign: AddonModAssignAssign,
@ -62,9 +53,7 @@ export class AddonModAssignFeedbackEditPdfHandlerService implements AddonModAssi
}
/**
* Whether or not the handler is enabled on a site level.
*
* @returns True or promise resolved with true if enabled.
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;

View File

@ -35,23 +35,14 @@ export class AddonModAssignFeedbackFileHandlerService implements AddonModAssignF
type = 'file';
/**
* Return the Component to use to display the plugin data.
* It's recommended to return the class of the component, but you can also return an instance of the component.
*
* @returns The component (or promise resolved with component) to use, undefined if not found.
* @inheritdoc
*/
getComponent(): Type<IAddonModAssignFeedbackPluginComponent> {
return AddonModAssignFeedbackFileComponent;
}
/**
* Get files used by this plugin.
* The files returned by this function will be prefetched when the user prefetches the assign.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The files (or promise resolved with the files).
* @inheritdoc
*/
getPluginFiles(
assign: AddonModAssignAssign,
@ -62,9 +53,7 @@ export class AddonModAssignFeedbackFileHandlerService implements AddonModAssignF
}
/**
* Whether or not the handler is enabled on a site level.
*
* @returns True or promise resolved with true if enabled.
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;

View File

@ -21,6 +21,8 @@ import { CoreWSFile } from '@services/ws';
import { AddonModAssignSubmissionFormatted } from './assign-helper';
import { CoreFormFields } from '@singletons/form';
import type { IAddonModAssignFeedbackPluginComponent } from '@addons/mod/assign/classes/base-feedback-plugin-component';
import { CoreSites } from '@services/sites';
import { ADDON_MOD_ASSIGN_FEATURE_NAME } from '../constants';
/**
* Interface that all feedback handlers must implement.
@ -185,7 +187,14 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
constructor(
protected defaultHandler: AddonModAssignDefaultFeedbackHandler,
) {
super('AddonModAssignFeedbackDelegate', true);
super('AddonModAssignFeedbackDelegate');
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return !(await CoreSites.isFeatureDisabled(ADDON_MOD_ASSIGN_FEATURE_NAME));
}
/**

View File

@ -15,8 +15,9 @@
import { Injectable } from '@angular/core';
import { CoreWSFile } from '@services/ws';
import { Translate } from '@singletons';
import { AddonModAssignPlugin } from '../assign';
import { AddonModAssignAssign, AddonModAssignPlugin, AddonModAssignSavePluginData, AddonModAssignSubmission } from '../assign';
import { AddonModAssignFeedbackHandler } from '../feedback-delegate';
import { CoreFormFields } from '@singletons/form';
/**
* Default handler used when a feedback plugin doesn't have a specific implementation.
@ -30,14 +31,19 @@ export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedb
/**
* @inheritdoc
*/
discardDraft(): void {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
discardDraft(assignId: number, userId: number, siteId?: string): void | Promise<void> {
// Nothing to do.
}
/**
* @inheritdoc
*/
getDraft(): undefined {
getDraft(
assignId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
userId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): CoreFormFields | Promise<CoreFormFields | undefined> | undefined {
// Nothing to do.
return;
}
@ -45,7 +51,12 @@ export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedb
/**
* @inheritdoc
*/
getPluginFiles(): CoreWSFile[] {
getPluginFiles(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): CoreWSFile[] | Promise<CoreWSFile[]> {
return [];
}
@ -73,14 +84,21 @@ export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedb
/**
* @inheritdoc
*/
hasDataChanged(): boolean {
async hasDataChanged(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
inputData: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars
userId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<boolean> {
return false;
}
/**
* @inheritdoc
*/
hasDraftData(): boolean {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasDraftData(assignId: number, userId: number, siteId?: string): boolean | Promise<boolean> {
return false;
}
@ -94,21 +112,38 @@ export class AddonModAssignDefaultFeedbackHandler implements AddonModAssignFeedb
/**
* @inheritdoc
*/
async prefetch(): Promise<void> {
async prefetch(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<void> {
return;
}
/**
* @inheritdoc
*/
prepareFeedbackData(): void {
prepareFeedbackData(
assignId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
userId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
pluginData: AddonModAssignSavePluginData, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): void | Promise<void> {
// Nothing to do.
}
/**
* @inheritdoc
*/
saveDraft(): void {
saveDraft(
assignId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
userId: number, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
data: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): void | Promise<void> {
// Nothing to do.
}

View File

@ -15,8 +15,10 @@
import { Injectable } from '@angular/core';
import { CoreWSFile } from '@services/ws';
import { Translate } from '@singletons';
import { AddonModAssignPlugin } from '../assign';
import { AddonModAssignAssign, AddonModAssignPlugin, AddonModAssignSavePluginData, AddonModAssignSubmission } from '../assign';
import { AddonModAssignSubmissionHandler } from '../submission-delegate';
import { CoreFormFields } from '@singletons/form';
import { AddonModAssignSubmissionsDBRecordFormatted } from '../assign-offline';
/**
* Default handler used when a submission plugin doesn't have a specific implementation.
@ -30,42 +32,71 @@ export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSub
/**
* @inheritdoc
*/
canEditOffline(): boolean | Promise<boolean> {
canEditOffline(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
): boolean | Promise<boolean> {
return false;
}
/**
* @inheritdoc
*/
isEmpty(): boolean {
isEmpty(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
): boolean {
return true;
}
/**
* @inheritdoc
*/
clearTmpData(): void {
clearTmpData(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
inputData: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars
): void {
// Nothing to do.
}
/**
* @inheritdoc
*/
copySubmissionData(): void {
copySubmissionData(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
pluginData: AddonModAssignSavePluginData, // eslint-disable-line @typescript-eslint/no-unused-vars
userId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): void | Promise<void> {
// Nothing to do.
}
/**
* @inheritdoc
*/
deleteOfflineData(): void {
deleteOfflineData(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
offlineData: AddonModAssignSubmissionsDBRecordFormatted, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): void | Promise<void> {
// Nothing to do.
}
/**
* @inheritdoc
*/
getPluginFiles(): CoreWSFile[] {
getPluginFiles(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): CoreWSFile[] | Promise<CoreWSFile[]> {
return [];
}
@ -93,21 +124,34 @@ export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSub
/**
* @inheritdoc
*/
getSizeForCopy(): number {
getSizeForCopy(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
): number | Promise<number> {
return 0;
}
/**
* @inheritdoc
*/
getSizeForEdit(): number {
getSizeForEdit(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
inputData: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars
): number | Promise<number> {
return 0;
}
/**
* @inheritdoc
*/
hasDataChanged(): boolean {
async hasDataChanged(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
inputData: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<boolean> {
return false;
}
@ -121,28 +165,49 @@ export class AddonModAssignDefaultSubmissionHandler implements AddonModAssignSub
/**
* @inheritdoc
*/
isEnabledForEdit(): boolean {
isEnabledForEdit(): boolean | Promise<boolean> {
return false;
}
/**
* @inheritdoc
*/
async prefetch(): Promise<void> {
async prefetch(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): Promise<void> {
return;
}
/**
* @inheritdoc
*/
prepareSubmissionData(): void {
prepareSubmissionData(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
inputData: CoreFormFields, // eslint-disable-line @typescript-eslint/no-unused-vars
pluginData: AddonModAssignSavePluginData, // eslint-disable-line @typescript-eslint/no-unused-vars
offline?: boolean, // eslint-disable-line @typescript-eslint/no-unused-vars
userId?: number, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): void | Promise<void> {
// Nothing to do.
}
/**
* @inheritdoc
*/
prepareSyncData(): void {
prepareSyncData(
assign: AddonModAssignAssign, // eslint-disable-line @typescript-eslint/no-unused-vars
submission: AddonModAssignSubmission, // eslint-disable-line @typescript-eslint/no-unused-vars
plugin: AddonModAssignPlugin, // eslint-disable-line @typescript-eslint/no-unused-vars
offlineData: AddonModAssignSubmissionsDBRecordFormatted, // eslint-disable-line @typescript-eslint/no-unused-vars
pluginData: AddonModAssignSavePluginData, // eslint-disable-line @typescript-eslint/no-unused-vars
siteId?: string, // eslint-disable-line @typescript-eslint/no-unused-vars
): void | Promise<void> {
// Nothing to do.
}

View File

@ -20,6 +20,7 @@ import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonModAssign } from '../assign';
import { ADDON_MOD_ASSIGN_FEATURE_NAME } from '../../constants';
/**
* Handler for assign push notifications clicks.
@ -29,7 +30,7 @@ export class AddonModAssignPushClickHandlerService implements CorePushNotificati
name = 'AddonModAssignPushClickHandler';
priority = 200;
featureName = 'CoreCourseModuleDelegate_AddonModAssign';
featureName = ADDON_MOD_ASSIGN_FEATURE_NAME;
/**
* Check if a notification click is handled by this handler.

View File

@ -21,6 +21,8 @@ import { CoreWSFile } from '@services/ws';
import { AddonModAssignSubmissionsDBRecordFormatted } from './assign-offline';
import { CoreFormFields } from '@singletons/form';
import type { AddonModAssignSubmissionPluginBaseComponent } from '@addons/mod/assign/classes/base-submission-plugin-component';
import { CoreSites } from '@services/sites';
import { ADDON_MOD_ASSIGN_FEATURE_NAME } from '../constants';
/**
* Interface that all submission handlers must implement.
@ -194,7 +196,7 @@ export interface AddonModAssignSubmissionHandler extends CoreDelegateHandler {
submission: AddonModAssignSubmission,
plugin: AddonModAssignPlugin,
inputData: CoreFormFields,
): boolean | Promise<boolean>;
): Promise<boolean>;
/**
* Whether or not the handler is enabled for edit on a site level.
@ -277,7 +279,14 @@ export class AddonModAssignSubmissionDelegateService extends CoreDelegate<AddonM
constructor(
protected defaultHandler: AddonModAssignDefaultSubmissionHandler,
) {
super('AddonModAssignSubmissionDelegate', true);
super('AddonModAssignSubmissionDelegate');
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return !(await CoreSites.isFeatureDisabled(ADDON_MOD_ASSIGN_FEATURE_NAME));
}
/**

View File

@ -30,11 +30,7 @@ export class AddonModAssignSubmissionCommentsHandlerService implements AddonModA
type = 'comments';
/**
* Whether the plugin can be edited in offline for existing submissions. In general, this should return false if the
* plugin uses Moodle filters. The reason is that the app only prefetches filtered data, and the user should edit
* unfiltered data.
*
* @returns Boolean or promise resolved with boolean: whether it can be edited in offline.
* @inheritdoc
*/
canEditOffline(): boolean {
// This plugin is read only, but return true to prevent blocking the edition.
@ -42,44 +38,28 @@ export class AddonModAssignSubmissionCommentsHandlerService implements AddonModA
}
/**
* Return the Component to use to display the plugin data, either in read or in edit mode.
* It's recommended to return the class of the component, but you can also return an instance of the component.
*
* @param plugin The plugin object.
* @param edit Whether the user is editing.
* @returns The component (or promise resolved with component) to use, undefined if not found.
* @inheritdoc
*/
getComponent(plugin: AddonModAssignPlugin, edit = false): Type<AddonModAssignSubmissionPluginBaseComponent> | undefined {
return edit ? undefined : AddonModAssignSubmissionCommentsComponent;
}
/**
* Whether or not the handler is enabled on a site level.
*
* @returns True or promise resolved with true if enabled.
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* Whether or not the handler is enabled for edit on a site level.
*
* @returns Whether or not the handler is enabled for edit on a site level.
* @inheritdoc
*/
isEnabledForEdit(): boolean{
return true;
}
/**
* Prefetch any required data for the plugin.
* This should NOT prefetch files. Files to be prefetched should be returned by the getPluginFiles function.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when done.
* @inheritdoc
*/
async prefetch(
assign: AddonModAssignAssign,

View File

@ -45,11 +45,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
type = 'file';
/**
* Whether the plugin can be edited in offline for existing submissions. In general, this should return false if the
* plugin uses Moodle filters. The reason is that the app only prefetches filtered data, and the user should edit
* unfiltered data.
*
* @returns Boolean or promise resolved with boolean: whether it can be edited in offline.
* @inheritdoc
*/
canEditOffline(): boolean {
// This plugin doesn't use Moodle filters, it can be edited in offline.
@ -57,11 +53,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Check if a plugin has no data.
*
* @param assign The assignment.
* @param plugin The plugin object.
* @returns Whether the plugin is empty.
* @inheritdoc
*/
isEmpty(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean {
const files = AddonModAssign.getSubmissionPluginAttachments(plugin);
@ -70,9 +62,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Should clear temporary data for a cancelled submission.
*
* @param assign The assignment.
* @inheritdoc
*/
clearTmpData(assign: AddonModAssignAssign): void {
const files = CoreFileSession.getFiles(AddonModAssignProvider.COMPONENT, assign.id);
@ -85,13 +75,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* This function will be called when the user wants to create a new submission based on the previous one.
* It should add to pluginData the data to send to server based in the data in plugin (previous attempt).
*
* @param assign The assignment.
* @param plugin The plugin object.
* @param pluginData Object where to store the data to send.
* @returns If the function is async, it should return a Promise resolved when done.
* @inheritdoc
*/
async copySubmissionData(
assign: AddonModAssignAssign,
@ -106,24 +90,14 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Return the Component to use to display the plugin data, either in read or in edit mode.
* It's recommended to return the class of the component, but you can also return an instance of the component.
*
* @returns The component (or promise resolved with component) to use, undefined if not found.
* @inheritdoc
*/
getComponent(): Type<AddonModAssignSubmissionPluginBaseComponent> {
return AddonModAssignSubmissionFileComponent;
}
/**
* Delete any stored data for the plugin and submission.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param offlineData Offline data stored.
* @param siteId Site ID. If not defined, current site.
* @returns If the function is async, it should return a Promise resolved when done.
* @inheritdoc
*/
async deleteOfflineData(
assign: AddonModAssignAssign,
@ -144,13 +118,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Get files used by this plugin.
* The files returned by this function will be prefetched when the user prefetches the assign.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The files (or promise resolved with the files).
* @inheritdoc
*/
getPluginFiles(
assign: AddonModAssignAssign,
@ -161,11 +129,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Get the size of data (in bytes) this plugin will send to copy a previous submission.
*
* @param assign The assignment.
* @param plugin The plugin object.
* @returns The size (or promise resolved with size).
* @inheritdoc
*/
async getSizeForCopy(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): Promise<number> {
const files = AddonModAssign.getSubmissionPluginAttachments(plugin);
@ -174,12 +138,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Get the size of data (in bytes) this plugin will send to add or edit a submission.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The size (or promise resolved with size).
* @inheritdoc
*/
async getSizeForEdit(
assign: AddonModAssignAssign,
@ -199,12 +158,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Check if the submission data has changed for this plugin.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns Boolean (or promise resolved with boolean): whether the data has changed.
* @inheritdoc
*/
async hasDataChanged(
assign: AddonModAssignAssign,
@ -243,35 +197,21 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Whether or not the handler is enabled on a site level.
*
* @returns True or promise resolved with true if enabled.
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* Whether or not the handler is enabled for edit on a site level.
*
* @returns Whether or not the handler is enabled for edit on a site level.
* @inheritdoc
*/
isEnabledForEdit(): boolean {
return true;
}
/**
* Prepare and add to pluginData the data to send to the server based on the input data.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param inputData Data entered by the user for the submission.
* @param pluginData Object where to store the data to send.
* @param offline Whether the user is editing in offline.
* @param userId User ID. If not defined, site's current user.
* @param siteId Site ID. If not defined, current site.
* @returns If the function is async, it should return a Promise resolved when done.
* @inheritdoc
*/
async prepareSubmissionData(
assign: AddonModAssignAssign,
@ -308,16 +248,7 @@ export class AddonModAssignSubmissionFileHandlerService implements AddonModAssig
}
/**
* Prepare and add to pluginData the data to send to the server based on the offline data stored.
* This will be used when performing a synchronization.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param offlineData Offline data stored.
* @param pluginData Object where to store the data to send.
* @param siteId Site ID. If not defined, current site.
* @returns If the function is async, it should return a Promise resolved when done.
* @inheritdoc
*/
async prepareSyncData(
assign: AddonModAssignAssign,

View File

@ -41,11 +41,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
type = 'onlinetext';
/**
* Whether the plugin can be edited in offline for existing submissions. In general, this should return false if the
* plugin uses Moodle filters. The reason is that the app only prefetches filtered data, and the user should edit
* unfiltered data.
*
* @returns Boolean or promise resolved with boolean: whether it can be edited in offline.
* @inheritdoc
*/
canEditOffline(): boolean {
// This plugin uses Moodle filters, it cannot be edited in offline.
@ -53,11 +49,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Check if a plugin has no data.
*
* @param assign The assignment.
* @param plugin The plugin object.
* @returns Whether the plugin is empty.
* @inheritdoc
*/
isEmpty(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): boolean {
const text = AddonModAssign.getSubmissionPluginText(plugin, true);
@ -67,15 +59,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* This function will be called when the user wants to create a new submission based on the previous one.
* It should add to pluginData the data to send to server based in the data in plugin (previous attempt).
*
* @param assign The assignment.
* @param plugin The plugin object.
* @param pluginData Object where to store the data to send.
* @param userId User ID. If not defined, site's current user.
* @param siteId Site ID. If not defined, current site.
* @returns If the function is async, it should return a Promise resolved when done.
* @inheritdoc
*/
async copySubmissionData(
assign: AddonModAssignAssign,
@ -102,23 +86,14 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Return the Component to use to display the plugin data, either in read or in edit mode.
* It's recommended to return the class of the component, but you can also return an instance of the component.
*
* @returns The component (or promise resolved with component) to use, undefined if not found.
* @inheritdoc
*/
getComponent(): Type<AddonModAssignSubmissionPluginBaseComponent> {
return AddonModAssignSubmissionOnlineTextComponent;
}
/**
* Get files used by this plugin.
* The files returned by this function will be prefetched when the user prefetches the assign.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The files (or promise resolved with the files).
* @inheritdoc
*/
getPluginFiles(
assign: AddonModAssignAssign,
@ -129,11 +104,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Get the size of data (in bytes) this plugin will send to copy a previous submission.
*
* @param assign The assignment.
* @param plugin The plugin object.
* @returns The size (or promise resolved with size).
* @inheritdoc
*/
async getSizeForCopy(assign: AddonModAssignAssign, plugin: AddonModAssignPlugin): Promise<number> {
const text = AddonModAssign.getSubmissionPluginText(plugin, true);
@ -145,12 +116,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Get the size of data (in bytes) this plugin will send to add or edit a submission.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @returns The size (or promise resolved with size).
* @inheritdoc
*/
getSizeForEdit(
assign: AddonModAssignAssign,
@ -177,13 +143,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Check if the submission data has changed for this plugin.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param inputData Data entered by the user for the submission.
* @returns Boolean (or promise resolved with boolean): whether the data has changed.
* @inheritdoc
*/
async hasDataChanged(
assign: AddonModAssignAssign,
@ -209,31 +169,21 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Whether or not the handler is enabled on a site level.
*
* @returns True or promise resolved with true if enabled.
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return true;
}
/**
* Whether or not the handler is enabled for edit on a site level.
*
* @returns Whether or not the handler is enabled for edit on a site level.
* @inheritdoc
*/
isEnabledForEdit(): boolean {
return true;
}
/**
* Prepare and add to pluginData the data to send to the server based on the input data.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param inputData Data entered by the user for the submission.
* @param pluginData Object where to store the data to send.
* @inheritdoc
*/
prepareSubmissionData(
assign: AddonModAssignAssign,
@ -269,14 +219,7 @@ export class AddonModAssignSubmissionOnlineTextHandlerService implements AddonMo
}
/**
* Prepare and add to pluginData the data to send to the server based on the offline data stored.
* This will be used when performing a synchronization.
*
* @param assign The assignment.
* @param submission The submission.
* @param plugin The plugin object.
* @param offlineData Offline data stored.
* @param pluginData Object where to store the data to send.
* @inheritdoc
*/
prepareSyncData(
assign: AddonModAssignAssign,

View File

@ -0,0 +1,15 @@
// (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.
export const ADDON_MOD_DATA_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModData';

View File

@ -25,6 +25,8 @@ import { CoreFormFields } from '@singletons/form';
import { FileEntry } from '@awesome-cordova-plugins/file/ngx';
import { CoreFileEntry } from '@services/file-helper';
import type { AddonModDataFieldPluginBaseComponent } from '@addons/mod/data/classes/base-field-plugin-component';
import { CoreSites } from '@services/sites';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../constants';
/**
* Interface that all fields handlers must implement.
@ -132,7 +134,14 @@ export class AddonModDataFieldsDelegateService extends CoreDelegate<AddonModData
constructor(
protected defaultHandler: AddonModDataDefaultFieldHandler,
) {
super('AddonModDataFieldsDelegate', true);
super('AddonModDataFieldsDelegate');
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return !(await CoreSites.isFeatureDisabled(ADDON_MOD_DATA_FEATURE_NAME));
}
/**

View File

@ -17,6 +17,7 @@ import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { makeSingleton } from '@singletons';
import { AddonModDataHelper } from '../data-helper';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
/**
* Content links handler for database approve/disapprove entry.
@ -26,7 +27,7 @@ import { AddonModDataHelper } from '../data-helper';
export class AddonModDataApproveLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModDataApproveLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
featureName = ADDON_MOD_DATA_FEATURE_NAME;
pattern = /\/mod\/data\/view\.php.*([?&](d|approve|disapprove)=\d+)/;
priority = 50; // Higher priority than the default link handler for view.php.

View File

@ -17,6 +17,7 @@ import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { makeSingleton } from '@singletons';
import { AddonModDataHelper } from '../data-helper';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
/**
* Content links handler for database delete entry.
@ -26,7 +27,7 @@ import { AddonModDataHelper } from '../data-helper';
export class AddonModDataDeleteLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModDataDeleteLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
featureName = ADDON_MOD_DATA_FEATURE_NAME;
pattern = /\/mod\/data\/view\.php.*([?&](d|delete)=\d+)/;
/**

View File

@ -22,6 +22,7 @@ import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton } from '@singletons';
import { AddonModDataModuleHandlerService } from './module';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
/**
* Content links handler for database add or edit entry.
@ -31,7 +32,7 @@ import { AddonModDataModuleHandlerService } from './module';
export class AddonModDataEditLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModDataEditLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
featureName = ADDON_MOD_DATA_FEATURE_NAME;
pattern = /\/mod\/data\/edit\.php.*([?&](d|rid)=\d+)/;
/**

View File

@ -22,6 +22,7 @@ import { CoreSitesReadingStrategy } from '@services/sites';
import { CoreDomUtils } from '@services/utils/dom';
import { makeSingleton } from '@singletons';
import { AddonModDataModuleHandlerService } from './module';
import { ADDON_MOD_DATA_FEATURE_NAME } from '../../constants';
/**
* Content links handler for database show entry.
@ -31,7 +32,7 @@ import { AddonModDataModuleHandlerService } from './module';
export class AddonModDataShowLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModDataShowLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModData';
featureName = ADDON_MOD_DATA_FEATURE_NAME;
pattern = /\/mod\/data\/view\.php.*([?&](d|rid|page|group|mode)=\d+)/;
priority = 50; // Higher priority than the default link handler for view.php.

View File

@ -0,0 +1,15 @@
// (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.
export const ADDON_MOD_QUIZ_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModQuiz';

View File

@ -18,6 +18,8 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonModQuizAttemptWSData, AddonModQuizQuizWSData } from './quiz';
import { CoreSites } from '@services/sites';
import { ADDON_MOD_QUIZ_FEATURE_NAME } from '../constants';
/**
* Interface that all access rules handlers must implement.
@ -128,7 +130,14 @@ export class AddonModQuizAccessRuleDelegateService extends CoreDelegate<AddonMod
protected handlerNameProperty = 'ruleName';
constructor() {
super('AddonModQuizAccessRulesDelegate', true);
super('AddonModQuizAccessRulesDelegate');
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return !(await CoreSites.isFeatureDisabled(ADDON_MOD_QUIZ_FEATURE_NAME));
}
/**

View File

@ -23,6 +23,7 @@ import { makeSingleton } from '@singletons';
import { AddonModQuiz } from '../quiz';
import { AddonModQuizHelper } from '../quiz-helper';
import { isSafeNumber } from '@/core/utils/types';
import { ADDON_MOD_QUIZ_FEATURE_NAME } from '../../constants';
/**
* Handler for quiz push notifications clicks.
@ -32,7 +33,7 @@ export class AddonModQuizPushClickHandlerService implements CorePushNotification
name = 'AddonModQuizPushClickHandler';
priority = 200;
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
featureName = ADDON_MOD_QUIZ_FEATURE_NAME;
protected readonly SUPPORTED_NAMES = ['submission', 'confirmation', 'attempt_overdue'];

View File

@ -17,6 +17,7 @@ import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { makeSingleton } from '@singletons';
import { AddonModQuizHelper } from '../quiz-helper';
import { ADDON_MOD_QUIZ_FEATURE_NAME } from '../../constants';
/**
* Handler to treat links to quiz review.
@ -25,7 +26,7 @@ import { AddonModQuizHelper } from '../quiz-helper';
export class AddonModQuizReviewLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModQuizReviewLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
featureName = ADDON_MOD_QUIZ_FEATURE_NAME;
pattern = /\/mod\/quiz\/review\.php.*([&?]attempt=\d+)/;
/**

View File

@ -39,3 +39,5 @@ export const ADDON_MOD_WORKSHOP_PREFETCH_UPDATE_NAMES = new RegExp(
);
export const ADDON_MOD_WORKSHOP_SYNC_CRON_NAME = 'AddonModWorkshopSyncCronHandler';
export const ADDON_MOD_WORKSHOP_FEATURE_NAME = 'CoreCourseModuleDelegate_AddonModWorkshop';

View File

@ -17,6 +17,8 @@ import { CoreDelegateHandler, CoreDelegate } from '@classes/delegate';
import { makeSingleton } from '@singletons';
import { CoreFormFields } from '@singletons/form';
import { AddonModWorkshopGetAssessmentFormDefinitionData, AddonModWorkshopGetAssessmentFormFieldsParsedData } from './workshop';
import { CoreSites } from '@services/sites';
import { ADDON_MOD_WORKSHOP_FEATURE_NAME } from '../constants';
/**
* Interface that all assessment strategy handlers must implement.
@ -83,7 +85,14 @@ export class AddonWorkshopAssessmentStrategyDelegateService extends CoreDelegate
protected handlerNameProperty = 'strategyName';
constructor() {
super('AddonWorkshopAssessmentStrategyDelegate', true);
super('AddonWorkshopAssessmentStrategyDelegate');
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return !(await CoreSites.isFeatureDisabled(ADDON_MOD_WORKSHOP_FEATURE_NAME));
}
/**

View File

@ -34,7 +34,7 @@ export class CoreSortedDelegate<
* @inheritdoc
*/
constructor(delegateName: string) {
super(delegateName, true);
super(delegateName);
CoreEvents.on(CoreEvents.LOGOUT, () => this.clearSortedHandlers());
CoreEvents.on(CoreEvents.SITE_POLICY_AGREED, (data) => {

View File

@ -72,28 +72,28 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
/**
* Promise to wait for handlers to be initialized.
*
* @returns Promise resolved when handlers are enabled.
*/
protected handlersInitPromise: Promise<void>;
protected handlersInitPromise: Promise<boolean>;
/**
* Function to resolve the handlers init promise.
*/
protected handlersInitResolve!: () => void;
protected handlersInitResolve!: (enabled: boolean) => void;
/**
* 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, listenSiteEvents: boolean = true) {
constructor(delegateName: string) {
this.logger = CoreLogger.getInstance(delegateName);
this.handlersInitPromise = new Promise((resolve): void => {
this.handlersInitResolve = resolve;
});
if (listenSiteEvents) {
// Update handlers on this cases.
CoreEvents.on(CoreEvents.LOGIN, () => this.updateHandlers());
CoreEvents.on(CoreEvents.SITE_UPDATED, () => this.updateHandlers());
@ -109,7 +109,6 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
}
});
}
}
/**
* Check if the delegate is enabled so handlers are not updated if not..
@ -286,9 +285,12 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
}
// Checks if the handler is enabled.
this.updatePromises[siteId][handler.name] = promise.then((enabled: boolean) => {
this.updatePromises[siteId][handler.name] = promise.then((enabled) => {
// Check that site hasn't changed since the check started.
if (CoreSites.getCurrentSiteId() === siteId) {
if (CoreSites.getCurrentSiteId() !== siteId) {
return;
}
const key = handler[this.handlerNameProperty] || handler.name;
if (enabled) {
@ -296,7 +298,6 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
} else {
delete this.enabledHandlers[key];
}
}
return;
}).finally(() => {
@ -327,6 +328,10 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
const enabled = await this.isEnabled();
if (!enabled) {
this.logger.debug('Delegate not enabled.');
this.handlersInitResolve(false);
return;
}
@ -351,7 +356,7 @@ export class CoreDelegate<HandlerType extends CoreDelegateHandler> {
// Verify that this call is the last one that was started.
if (this.isLastUpdateCall(now)) {
this.handlersInitialized = true;
this.handlersInitResolve();
this.handlersInitResolve(true);
this.updateData();
}

View File

@ -104,7 +104,7 @@ export class CoreBlockDelegateService extends CoreDelegate<CoreBlockHandler> {
constructor(
protected defaultHandler: CoreBlockDefaultHandler,
) {
super('CoreBlockDelegate', true);
super('CoreBlockDelegate');
this.blocksUpdateObservable = new Subject<void>();
}

View File

@ -166,7 +166,7 @@ export class CoreCourseFormatDelegateService extends CoreDelegate<CoreCourseForm
protected handlerNameProperty = 'format';
constructor(protected defaultHandler: CoreCourseFormatDefaultHandler) {
super('CoreCoursesCourseFormatDelegate', true);
super('CoreCoursesCourseFormatDelegate');
}
/**

View File

@ -286,7 +286,7 @@ export class CoreCourseModuleDelegateService extends CoreDelegate<CoreCourseModu
protected handlerNameProperty = 'modName';
constructor(protected defaultHandler: CoreCourseModuleDefaultHandler) {
super('CoreCourseModuleDelegate', true);
super('CoreCourseModuleDelegate');
}
/**

View File

@ -54,7 +54,7 @@ export class CoreCourseModulePrefetchDelegateService extends CoreDelegate<CoreCo
protected prefetchData: Record<string, Record<string, OngoingPrefetch>> = {};
constructor() {
super('CoreCourseModulePrefetchDelegate', true);
super('CoreCourseModulePrefetchDelegate');
}
/**

View File

@ -129,7 +129,7 @@ export class CoreEnrolDelegateService extends CoreDelegate<CoreEnrolHandler> {
protected featurePrefix = 'CoreEnrolDelegate_';
constructor() {
super('CoreEnrolDelegate', true);
super('CoreEnrolDelegate');
}
/**

View File

@ -143,7 +143,7 @@ export interface CoreFileUploaderHandlerDataToReturn extends CoreFileUploaderHan
export class CoreFileUploaderDelegateService extends CoreDelegate<CoreFileUploaderHandler> {
constructor() {
super('CoreFileUploaderDelegate', true);
super('CoreFileUploaderDelegate');
CoreEvents.on(CoreEvents.LOGOUT, () => this.clearSiteHandlers());
}

View File

@ -15,7 +15,7 @@
import { Injectable, ViewContainerRef } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreFilterFilter, CoreFilterFormatTextOptions } from './filter';
import { CoreFilter, CoreFilterFilter, CoreFilterFormatTextOptions } from './filter';
import { CoreFilterDefaultHandler } from './handlers/default-filter';
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
import { CoreSite } from '@classes/sites/site';
@ -84,7 +84,14 @@ export class CoreFilterDelegateService extends CoreDelegate<CoreFilterHandler> {
protected handlerNameProperty = 'filterName';
constructor(protected defaultHandler: CoreFilterDefaultHandler) {
super('CoreFilterDelegate', true);
super('CoreFilterDelegate');
}
/**
* @inheritdoc
*/
async isEnabled(): Promise<boolean> {
return CoreFilter.canGetFiltersInSite();
}
/**
@ -106,7 +113,11 @@ export class CoreFilterDelegateService extends CoreDelegate<CoreFilterHandler> {
): Promise<string> {
// Wait for filters to be initialized.
await this.handlersInitPromise;
const enabled = await this.handlersInitPromise;
if (!enabled) {
// No enabled filters, return the text.
return text;
}
const site = await CoreSites.getSite(siteId);
@ -189,7 +200,10 @@ export class CoreFilterDelegateService extends CoreDelegate<CoreFilterHandler> {
): Promise<void> {
// Wait for filters to be initialized.
await this.handlersInitPromise;
const enabled = await this.handlersInitPromise;
if (!enabled) {
return;
}
const site = await CoreSites.getSite(siteId);
@ -258,17 +272,14 @@ export class CoreFilterDelegateService extends CoreDelegate<CoreFilterHandler> {
*/
async shouldBeApplied(filters: CoreFilterFilter[], options: CoreFilterFormatTextOptions, site?: CoreSite): Promise<boolean> {
// Wait for filters to be initialized.
await this.handlersInitPromise;
for (let i = 0; i < filters.length; i++) {
if (this.shouldFilterBeApplied(filters[i], options, site)) {
return true;
}
}
const enabled = await this.handlersInitPromise;
if (!enabled) {
return false;
}
return filters.some((filter) => this.shouldFilterBeApplied(filter, options, site));
}
/**
* Check whether a filter should be applied in a certain site and with certain options.
*

View File

@ -80,7 +80,7 @@ export class CoreFilterProvider {
* @returns Promise resolved with boolean: whethe can get filters.
*/
canGetFiltersInSite(site?: CoreSite): boolean {
return this.checkFiltersDisabledInSite(site);
return !this.checkFiltersDisabledInSite(site);
}
/**

View File

@ -68,7 +68,7 @@ export class CoreQuestionBehaviourDelegateService extends CoreDelegate<CoreQuest
protected handlerNameProperty = 'type';
constructor(protected defaultHandler: CoreQuestionBehaviourDefaultHandler) {
super('CoreQuestionBehaviourDelegate', true);
super('CoreQuestionBehaviourDelegate');
}
/**

View File

@ -217,7 +217,7 @@ export class CoreQuestionDelegateService extends CoreDelegate<CoreQuestionHandle
protected handlerNameProperty = 'type';
constructor(protected defaultHandler: CoreQuestionDefaultHandler) {
super('CoreQuestionDelegate', true);
super('CoreQuestionDelegate');
}
/**

View File

@ -51,7 +51,7 @@ export class CoreTagAreaDelegateService extends CoreDelegate<CoreTagAreaHandler>
protected handlerNameProperty = 'type';
constructor() {
super('CoreTagAreaDelegate', true);
super('CoreTagAreaDelegate');
}
/**

View File

@ -229,7 +229,7 @@ export class CoreUserDelegateService extends CoreDelegate<CoreUserProfileHandler
protected userHandlers: Record<number, Record<string, CoreUserDelegateHandlersData>> = {};
constructor() {
super('CoreUserDelegate', true);
super('CoreUserDelegate');
CoreEvents.on(USER_DELEGATE_UPDATE_HANDLER_EVENT, (data) => {
const handlersData = this.getHandlersData(data.userId, data.context, data.contextId);

View File

@ -80,7 +80,7 @@ export class CoreUserProfileFieldDelegateService extends CoreDelegate<CoreUserPr
protected handlerNameProperty = 'type';
constructor() {
super('CoreUserProfileFieldDelegate', true);
super('CoreUserProfileFieldDelegate');
}
/**

View File

@ -30,7 +30,7 @@ import { CoreTextUtils } from '@services/utils/text';
export class CoreAnalyticsService extends CoreDelegate<CoreAnalyticsHandler> {
constructor() {
super('CoreAnalyticsService', true);
super('CoreAnalyticsService');
CoreEvents.on(CoreConfigProvider.ENVIRONMENT_UPDATED, () => this.updateHandlers());
CoreEvents.on(CoreEvents.LOGOUT, () => this.clearSiteHandlers());

View File

@ -30,7 +30,7 @@ import { CoreFileHelper } from './file-helper';
export class CorePluginFileDelegateService extends CoreDelegate<CorePluginFileHandler> {
constructor() {
super('CorePluginFileDelegate', true);
super('CorePluginFileDelegate');
}
/**