Skip to content

Commit

Permalink
Merge pull request #3964 from crazyserver/MOBILE-4538
Browse files Browse the repository at this point in the history
Mobile 4538
  • Loading branch information
dpalou authored Mar 11, 2024
2 parents 94f5f20 + ae4c1ce commit 162a618
Show file tree
Hide file tree
Showing 42 changed files with 354 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AddonMessageOutputDelegateService extends CoreDelegate<AddonMessage
protected handlerNameProperty = 'processorName';

constructor() {
super('AddonMessageOutputDelegate', true);
super('AddonMessageOutputDelegate');
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/addons/mod/assign/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
62 changes: 9 additions & 53 deletions src/addons/mod/assign/feedback/comments/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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,
Expand Down
17 changes: 3 additions & 14 deletions src/addons/mod/assign/feedback/editpdf/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
17 changes: 3 additions & 14 deletions src/addons/mod/assign/feedback/file/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/addons/mod/assign/services/feedback-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}

/**
Expand Down
53 changes: 44 additions & 9 deletions src/addons/mod/assign/services/handlers/default-feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,22 +31,32 @@ 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;
}

/**
* @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 [];
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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.
}

Expand Down
Loading

0 comments on commit 162a618

Please sign in to comment.