Skip to content

Commit

Permalink
MOBILE-3671 assign: Remove unneeded draft management on feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Feb 20, 2025
1 parent fa03473 commit 0701e1b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ <h1>{{'addon.mod_assign.grade' | translate}}</h1>
</ion-item>

@if (feedback) {
<addon-mod-assign-feedback-plugin *ngFor="let plugin of feedback.plugins" [assign]="assign" [submission]="userSubmission"
[userId]="submitId" [plugin]="plugin" [canEdit]="true" [edit]="true" />
<form name="addon-mod_assign-edit-feedback-plugins-form" #editFeedbackForm>
<addon-mod-assign-feedback-plugin *ngFor="let plugin of feedback.plugins" [assign]="assign" [submission]="userSubmission"
[userId]="submitId" [plugin]="plugin" [canEdit]="true" [edit]="true" />
</form>
}

<!--- Apply grade to all team members. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,10 @@ export class AddonModAssignEditFeedbackModalComponent implements OnDestroy, OnIn

/**
* Discard feedback drafts.
*
* @returns Promise resolved when done.
*/
protected async discardDrafts(): Promise<void> {
if (this.assign && this.feedback && this.feedback.plugins) {
// eslint-disable-next-line deprecation/deprecation
await AddonModAssignHelper.discardFeedbackPluginData(this.assign.id, this.submitId, this.feedback);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>{{ plugin.name }}</h1>
</ion-toolbar>
</ion-header>
<ion-content>
<form name="addon-mod_assign-edit-feedback-form" *ngIf="userId && plugin" #editFeedbackForm>
<form name="addon-mod_assign-edit-feedback-plugin-form" *ngIf="userId && plugin" #editFeedbackForm>
<addon-mod-assign-feedback-plugin [assign]="assign" [submission]="submission" [userId]="userId" [plugin]="plugin" [edit]="true" />
<ion-button expand="block" (click)="done($event)">{{ 'core.done' | translate }}</ion-button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class AddonModAssignEditPluginFeedbackModalComponent {
* @returns Object with the data.
*/
protected getInputData(): CoreFormFields {
return CoreForms.getDataFromForm(document.forms['addon-mod_assign-edit-feedback-form']);
return CoreForms.getDataFromForm(document.forms['addon-mod_assign-edit-feedback-plugin-form']);
}

/**
Expand Down
27 changes: 1 addition & 26 deletions src/addons/mod/assign/feedback/comments/component/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import { FormBuilder, FormControl } from '@angular/forms';
import { AddonModAssign } from '@addons/mod/assign/services/assign';
import { CoreFileHelper } from '@services/file-helper';
import {
AddonModAssignFeedbackCommentsDraftData,
AddonModAssignFeedbackCommentsPluginData,
} from '../services/handler';
import { AddonModAssignFeedbackDelegate } from '@addons/mod/assign/services/feedback-delegate';
import { AddonModAssignOffline } from '@addons/mod/assign/services/assign-offline';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { AddonModAssignFeedbackPluginBaseComponent } from '@addons/mod/assign/classes/base-feedback-plugin-component';
Expand All @@ -47,7 +45,6 @@ export class AddonModAssignFeedbackCommentsComponent extends AddonModAssignFeedb
control?: FormControl<string>;
component = ADDON_MOD_ASSIGN_COMPONENT_LEGACY;
text = '';
isSent = false;
loaded = false;

protected element: HTMLElement;
Expand Down Expand Up @@ -102,17 +99,7 @@ export class AddonModAssignFeedbackCommentsComponent extends AddonModAssignFeedb
* @returns Promise resolved with the text.
*/
protected async getText(): Promise<string> {
// Check if the user already modified the comment.
const draft: AddonModAssignFeedbackCommentsDraftData | undefined =
await AddonModAssignFeedbackDelegate.getPluginDraftData(this.assign.id, this.userId, this.plugin);

if (draft) {
this.isSent = false;

return this.replacePluginfileUrls(draft.text);
}

// There is no draft saved. Check if we have anything offline.
// Check if we have anything offline.
const offlineData = await CorePromiseUtils.ignoreErrors(
AddonModAssignOffline.getSubmissionGrade(this.assign.id, this.userId),
undefined,
Expand All @@ -121,21 +108,9 @@ export class AddonModAssignFeedbackCommentsComponent extends AddonModAssignFeedb
if (offlineData && offlineData.plugindata && offlineData.plugindata.assignfeedbackcomments_editor) {
const pluginData = <AddonModAssignFeedbackCommentsPluginData>offlineData.plugindata;

// Save offline as draft.
this.isSent = false;
AddonModAssignFeedbackDelegate.saveFeedbackDraft(
this.assign.id,
this.userId,
this.plugin,
pluginData.assignfeedbackcomments_editor,
);

return this.replacePluginfileUrls(pluginData.assignfeedbackcomments_editor.text);
}

// No offline data found, return online text.
this.isSent = true;

return AddonModAssign.getSubmissionPluginText(this.plugin);
}

Expand Down
91 changes: 14 additions & 77 deletions src/addons/mod/assign/feedback/comments/services/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {
import { AddonModAssignOffline } from '@addons/mod/assign/services/assign-offline';
import { AddonModAssignFeedbackHandler } from '@addons/mod/assign/services/feedback-delegate';
import { Injectable, Type } from '@angular/core';
import { CoreSites } from '@services/sites';
import { CoreText } from '@singletons/text';
import { CoreText, CoreTextFormat } from '@singletons/text';
import { CorePromiseUtils } from '@singletons/promise-utils';
import { CoreWSFile } from '@services/ws';
import { makeSingleton } from '@singletons';
import { CoreFileHelper } from '@services/file-helper';
import { CoreForms } from '@singletons/form';

/**
* Handler for comments feedback plugin.
Expand All @@ -39,9 +39,6 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
name = 'AddonModAssignFeedbackCommentsHandler';
type = 'comments';

// Store the data in this service so it isn't lost if the user performs a PTR in the page.
protected drafts: { [draftId: string]: AddonModAssignFeedbackCommentsDraftData } = {};

/**
* Get the text to submit.
*
Expand All @@ -59,16 +56,6 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
return CoreFileHelper.restorePluginfileUrls(inputData.assignfeedbackcomments_editor, files || []);
}

/**
* @inheritdoc
*/
discardDraft(assignId: number, userId: number, siteId?: string): void {
const id = this.getDraftId(assignId, userId, siteId);
if (this.drafts[id] !== undefined) {
delete this.drafts[id];
}
}

/**
* @inheritdoc
*/
Expand All @@ -78,31 +65,6 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
return AddonModAssignFeedbackCommentsComponent;
}

/**
* @inheritdoc
*/
getDraft(assignId: number, userId: number, siteId?: string): AddonModAssignFeedbackCommentsDraftData | undefined {
const id = this.getDraftId(assignId, userId, siteId);

if (this.drafts[id] !== undefined) {
return this.drafts[id];
}
}

/**
* Get a draft ID.
*
* @param assignId The assignment ID.
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @returns Draft ID.
*/
protected getDraftId(assignId: number, userId: number, siteId?: string): string {
siteId = siteId || CoreSites.getCurrentSiteId();

return siteId + '#' + assignId + '#' + userId;
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -145,16 +107,7 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
}

// Check if text has changed.
return initialText != newText;
}

/**
* @inheritdoc
*/
hasDraftData(assignId: number, userId: number, siteId?: string): boolean | Promise<boolean> {
const draft = this.getDraft(assignId, userId, siteId);

return !!draft;
return initialText !== newText;
}

/**
Expand All @@ -175,33 +128,17 @@ export class AddonModAssignFeedbackCommentsHandlerService implements AddonModAss
userId: number,
plugin: AddonModAssignPlugin,
pluginData: AddonModAssignSavePluginData,
siteId?: string,
): void {

const draft = this.getDraft(assignId, userId, siteId);

if (draft) {
// Add some HTML to the text if needed.
draft.text = CoreText.formatHtmlLines(draft.text);

pluginData.assignfeedbackcomments_editor = draft;
const data = CoreForms.getDataFromForm(document.forms['addon-mod_assign-edit-feedback-plugins-form']);
if (!data['assignfeedbackcomments_editor']) {
return;
}
}

/**
* @inheritdoc
*/
saveDraft(
assignId: number,
userId: number,
plugin: AddonModAssignPlugin,
data: AddonModAssignFeedbackCommentsDraftData,
siteId?: string,
): void {

if (data) {
this.drafts[this.getDraftId(assignId, userId, siteId)] = data;
}
const inputData: AddonModAssignFeedbackCommentsInputData = {
text: CoreText.formatHtmlLines(data['assignfeedbackcomments_editor'] as string),
format: CoreTextFormat.FORMAT_HTML,
};
pluginData.assignfeedbackcomments_editor = inputData;
}

}
Expand All @@ -212,13 +149,13 @@ export type AddonModAssignFeedbackCommentsTextData = {
assignfeedbackcomments_editor: string; // eslint-disable-line @typescript-eslint/naming-convention
};

export type AddonModAssignFeedbackCommentsDraftData = {
type AddonModAssignFeedbackCommentsInputData = {
text: string; // The text for this feedback.
format: number; // The format for this feedback.
format: CoreTextFormat; // The format for this feedback.
};

export type AddonModAssignFeedbackCommentsPluginData = {
// Editor structure.
// eslint-disable-next-line @typescript-eslint/naming-convention
assignfeedbackcomments_editor: AddonModAssignFeedbackCommentsDraftData;
assignfeedbackcomments_editor: AddonModAssignFeedbackCommentsInputData;
};
2 changes: 2 additions & 0 deletions src/addons/mod/assign/services/assign-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export class AddonModAssignHelperProvider {
* @param feedback Feedback data.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when done.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
async discardFeedbackPluginData(
assignId: number,
Expand All @@ -213,6 +214,7 @@ export class AddonModAssignHelperProvider {

const promises = feedback.plugins
? feedback.plugins.map((plugin) =>
// eslint-disable-next-line deprecation/deprecation
AddonModAssignFeedbackDelegate.discardPluginFeedbackData(assignId, userId, plugin, siteId))
: [];

Expand Down
8 changes: 8 additions & 0 deletions src/addons/mod/assign/services/feedback-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler {
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @returns If the function is async, it should return a Promise resolved when done.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
discardDraft?(assignId: number, userId: number, siteId?: string): void | Promise<void>;

Expand All @@ -62,6 +63,7 @@ export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler {
* @param userId User ID.
* @param siteId Site ID. If not defined, current site.
* @returns Data (or promise resolved with the data).
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
getDraft?(
assignId: number,
Expand Down Expand Up @@ -119,6 +121,7 @@ export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler {
* @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.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
hasDraftData?(assignId: number, userId: number, siteId?: string): boolean | Promise<boolean>;

Expand Down Expand Up @@ -166,6 +169,7 @@ export interface AddonModAssignFeedbackHandler extends CoreDelegateHandler {
* @param data The data to save.
* @param siteId Site ID. If not defined, current site.
* @returns If the function is async, it should return a Promise resolved when done.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
saveDraft?(
assignId: number,
Expand Down Expand Up @@ -205,6 +209,7 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
* @param plugin The plugin object.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when done.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
async discardPluginFeedbackData(
assignId: number,
Expand Down Expand Up @@ -235,6 +240,7 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
* @param plugin The plugin object.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved with the draft data.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
async getPluginDraftData<T>(
assignId: number,
Expand Down Expand Up @@ -309,6 +315,7 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
* @param plugin The plugin object.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved with true if it has draft data.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
async hasPluginDraftData(
assignId: number,
Expand Down Expand Up @@ -381,6 +388,7 @@ export class AddonModAssignFeedbackDelegateService extends CoreDelegate<AddonMod
* @param inputData Data to save.
* @param siteId Site ID. If not defined, current site.
* @returns Promise resolved when data has been saved.
* @deprecated since 5.0. Feedback drafts are not needed if you show form in the grading modal.
*/
async saveFeedbackDraft(
assignId: number,
Expand Down

0 comments on commit 0701e1b

Please # to comment.