From 5a79151b01f1999de6c1f927cbe00c1fa28d303a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 31 Jan 2020 10:08:24 +0100 Subject: [PATCH] MOBILE-3323 editor: Save and restore drafts --- scripts/langindex.json | 2 + .../calendar/pages/edit-event/edit-event.html | 2 +- .../addon-mod-assign-feedback-comments.html | 3 +- ...ddon-mod-assign-submission-onlinetext.html | 2 +- .../onlinetext/component/onlinetext.ts | 14 +- .../addon-mod-data-field-textarea.html | 2 +- .../fields/textarea/component/textarea.ts | 6 +- .../components/post/addon-mod-forum-post.html | 2 +- .../edit-post/addon-mod-forum-edit-post.html | 2 +- .../pages/new-discussion/new-discussion.html | 2 +- src/addon/mod/glossary/pages/edit/edit.html | 2 +- src/addon/mod/glossary/pages/edit/edit.ts | 5 + src/addon/mod/lesson/pages/player/player.html | 2 +- src/addon/mod/wiki/pages/edit/edit.html | 2 +- src/addon/mod/wiki/pages/edit/edit.ts | 15 ++ ...ddon-mod-workshop-assessment-strategy.html | 2 +- .../workshop/pages/assessment/assessment.html | 2 +- .../edit-submission/edit-submission.html | 2 +- .../pages/edit-submission/edit-submission.ts | 5 + .../workshop/pages/submission/submission.html | 2 +- .../essay/component/addon-qtype-essay.html | 2 +- .../addon-user-profile-field-textarea.html | 2 +- src/assets/lang/en.json | 2 + .../core-editor-rich-text-editor.html | 13 +- .../rich-text-editor/rich-text-editor.scss | 18 ++- .../rich-text-editor/rich-text-editor.ts | 142 +++++++++++++++++- src/core/editor/lang/en.json | 4 + src/theme/variables.scss | 5 - 28 files changed, 228 insertions(+), 36 deletions(-) create mode 100644 src/core/editor/lang/en.json diff --git a/scripts/langindex.json b/scripts/langindex.json index 344e7460d..339c56c5a 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -1482,6 +1482,8 @@ "core.downloaded": "local_moodlemobileapp", "core.downloading": "local_moodlemobileapp", "core.edit": "moodle", + "core.editor.autosavesucceeded": "editor_atto", + "core.editor.textrecovered": "editor_atto", "core.emptysplit": "local_moodlemobileapp", "core.error": "moodle", "core.errorchangecompletion": "local_moodlemobileapp", diff --git a/src/addon/calendar/pages/edit-event/edit-event.html b/src/addon/calendar/pages/edit-event/edit-event.html index 9eae210f8..55a2cd584 100644 --- a/src/addon/calendar/pages/edit-event/edit-event.html +++ b/src/addon/calendar/pages/edit-event/edit-event.html @@ -86,7 +86,7 @@

{{ 'core.description' | translate }}

- +
diff --git a/src/addon/mod/assign/feedback/comments/component/addon-mod-assign-feedback-comments.html b/src/addon/mod/assign/feedback/comments/component/addon-mod-assign-feedback-comments.html index 6a2fff370..75892386b 100644 --- a/src/addon/mod/assign/feedback/comments/component/addon-mod-assign-feedback-comments.html +++ b/src/addon/mod/assign/feedback/comments/component/addon-mod-assign-feedback-comments.html @@ -19,5 +19,6 @@ - + + diff --git a/src/addon/mod/assign/submission/onlinetext/component/addon-mod-assign-submission-onlinetext.html b/src/addon/mod/assign/submission/onlinetext/component/addon-mod-assign-submission-onlinetext.html index a629ab325..a659af7a9 100644 --- a/src/addon/mod/assign/submission/onlinetext/component/addon-mod-assign-submission-onlinetext.html +++ b/src/addon/mod/assign/submission/onlinetext/component/addon-mod-assign-submission-onlinetext.html @@ -15,6 +15,6 @@

{{ 'core.numwords' | translate: {'$a': words + ' / ' + configs.wordlimit} }}

- + diff --git a/src/addon/mod/assign/submission/onlinetext/component/onlinetext.ts b/src/addon/mod/assign/submission/onlinetext/component/onlinetext.ts index 70ee9d183..a788de667 100644 --- a/src/addon/mod/assign/submission/onlinetext/component/onlinetext.ts +++ b/src/addon/mod/assign/submission/onlinetext/component/onlinetext.ts @@ -14,6 +14,7 @@ import { Component, OnInit, ElementRef } from '@angular/core'; import { FormBuilder, FormControl } from '@angular/forms'; +import { CoreSitesProvider } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { AddonModAssignProvider } from '../../../providers/assign'; @@ -35,16 +36,23 @@ export class AddonModAssignSubmissionOnlineTextComponent extends AddonModAssignS text: string; loaded: boolean; wordLimitEnabled: boolean; + currentUserId: number; protected wordCountTimeout: any; protected element: HTMLElement; - constructor(protected fb: FormBuilder, protected domUtils: CoreDomUtilsProvider, protected textUtils: CoreTextUtilsProvider, - protected assignProvider: AddonModAssignProvider, protected assignOfflineProvider: AddonModAssignOfflineProvider, - element: ElementRef) { + constructor( + protected fb: FormBuilder, + protected domUtils: CoreDomUtilsProvider, + protected textUtils: CoreTextUtilsProvider, + protected assignProvider: AddonModAssignProvider, + protected assignOfflineProvider: AddonModAssignOfflineProvider, + element: ElementRef, + sitesProvider: CoreSitesProvider) { super(); this.element = element.nativeElement; + this.currentUserId = sitesProvider.getCurrentSiteUserId(); } /** diff --git a/src/addon/mod/data/fields/textarea/component/addon-mod-data-field-textarea.html b/src/addon/mod/data/fields/textarea/component/addon-mod-data-field-textarea.html index 02ce6f367..680b92f89 100644 --- a/src/addon/mod/data/fields/textarea/component/addon-mod-data-field-textarea.html +++ b/src/addon/mod/data/fields/textarea/component/addon-mod-data-field-textarea.html @@ -2,7 +2,7 @@ - + diff --git a/src/addon/mod/data/fields/textarea/component/textarea.ts b/src/addon/mod/data/fields/textarea/component/textarea.ts index ba54212d7..d0d03359a 100644 --- a/src/addon/mod/data/fields/textarea/component/textarea.ts +++ b/src/addon/mod/data/fields/textarea/component/textarea.ts @@ -49,10 +49,10 @@ export class AddonModDataFieldTextareaComponent extends AddonModDataFieldPluginC * Initialize field. */ protected init(): void { - if (this.isShowOrListMode()) { - this.component = AddonModDataProvider.COMPONENT; - this.componentId = this.database.coursemodule; + this.component = AddonModDataProvider.COMPONENT; + this.componentId = this.database.coursemodule; + if (this.isShowOrListMode()) { return; } diff --git a/src/addon/mod/forum/components/post/addon-mod-forum-post.html b/src/addon/mod/forum/components/post/addon-mod-forum-post.html index 02a3bbe42..cafe72514 100644 --- a/src/addon/mod/forum/components/post/addon-mod-forum-post.html +++ b/src/addon/mod/forum/components/post/addon-mod-forum-post.html @@ -64,7 +64,7 @@ {{ 'addon.mod_forum.message' | translate }} - + {{ 'addon.mod_forum.privatereply' | translate }} diff --git a/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html b/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html index 0a934fa27..3fd8d6e4a 100644 --- a/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html +++ b/src/addon/mod/forum/pages/edit-post/addon-mod-forum-edit-post.html @@ -16,7 +16,7 @@ {{ 'addon.mod_forum.message' | translate }} - + diff --git a/src/addon/mod/forum/pages/new-discussion/new-discussion.html b/src/addon/mod/forum/pages/new-discussion/new-discussion.html index 95bb6e5ce..6cfeb39f8 100644 --- a/src/addon/mod/forum/pages/new-discussion/new-discussion.html +++ b/src/addon/mod/forum/pages/new-discussion/new-discussion.html @@ -19,7 +19,7 @@ {{ 'addon.mod_forum.message' | translate }} - + diff --git a/src/addon/mod/glossary/pages/edit/edit.html b/src/addon/mod/glossary/pages/edit/edit.html index 3c3bfa0d7..0bf02b458 100644 --- a/src/addon/mod/glossary/pages/edit/edit.html +++ b/src/addon/mod/glossary/pages/edit/edit.html @@ -15,7 +15,7 @@ {{ 'addon.mod_glossary.definition' | translate }} - + {{ 'addon.mod_glossary.categories' | translate }} diff --git a/src/addon/mod/glossary/pages/edit/edit.ts b/src/addon/mod/glossary/pages/edit/edit.ts index 7bb9e60eb..9cf8b4355 100644 --- a/src/addon/mod/glossary/pages/edit/edit.ts +++ b/src/addon/mod/glossary/pages/edit/edit.ts @@ -51,6 +51,7 @@ export class AddonModGlossaryEditPage implements OnInit { attachments = []; definitionControl = new FormControl(); categories = []; + editorExtraParams: {[name: string]: any} = {}; protected courseId: number; protected module: any; @@ -113,6 +114,10 @@ export class AddonModGlossaryEditPage implements OnInit { this.originalData.files = files.slice(); }); } + + if (entry.id) { + this.editorExtraParams.id = entry.id; + } } this.definitionControl.setValue(this.entry.definition); diff --git a/src/addon/mod/lesson/pages/player/player.html b/src/addon/mod/lesson/pages/player/player.html index 13c7e7f0b..b8526c401 100644 --- a/src/addon/mod/lesson/pages/player/player.html +++ b/src/addon/mod/lesson/pages/player/player.html @@ -57,7 +57,7 @@ - +

{{ 'addon.mod_lesson.youranswer' | translate }}

diff --git a/src/addon/mod/wiki/pages/edit/edit.html b/src/addon/mod/wiki/pages/edit/edit.html index c9f61f896..2381df6c3 100644 --- a/src/addon/mod/wiki/pages/edit/edit.html +++ b/src/addon/mod/wiki/pages/edit/edit.html @@ -17,7 +17,7 @@
- + diff --git a/src/addon/mod/wiki/pages/edit/edit.ts b/src/addon/mod/wiki/pages/edit/edit.ts index 160bfeeb2..033ec982e 100644 --- a/src/addon/mod/wiki/pages/edit/edit.ts +++ b/src/addon/mod/wiki/pages/edit/edit.ts @@ -45,6 +45,7 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy { component = AddonModWikiProvider.COMPONENT; // Component to link the files to. componentId: number; // Component ID to link the files to. wrongVersionLock: boolean; // Whether the page lock doesn't match the initial one. + editorExtraParams: {[name: string]: any} = {}; protected module: any; // Wiki module instance. protected courseId: number; // Course the wiki belongs to. @@ -101,6 +102,20 @@ export class AddonModWikiEditPage implements OnInit, OnDestroy { // Block the wiki so it cannot be synced. this.syncProvider.blockOperation(this.component, this.blockId); + + if (!this.module.id) { + this.editorExtraParams.type = 'wiki'; + } + + if (this.pageId) { + this.editorExtraParams.pageid = this.pageId; + + if (this.section) { + this.editorExtraParams.section = this.section; + } + } else if (pageTitle) { + this.editorExtraParams.pagetitle = pageTitle; + } } /** diff --git a/src/addon/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html b/src/addon/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html index 7f3b2bba7..b79857e1d 100644 --- a/src/addon/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html +++ b/src/addon/mod/workshop/components/assessment-strategy/addon-mod-workshop-assessment-strategy.html @@ -16,7 +16,7 @@ {{ 'addon.mod_workshop.feedbackauthor' | translate }} - + {{ 'addon.mod_workshop.feedbackreviewer' | translate }} - + diff --git a/src/addon/mod/workshop/pages/edit-submission/edit-submission.html b/src/addon/mod/workshop/pages/edit-submission/edit-submission.html index 71b1e535d..a7f3bad68 100644 --- a/src/addon/mod/workshop/pages/edit-submission/edit-submission.html +++ b/src/addon/mod/workshop/pages/edit-submission/edit-submission.html @@ -18,7 +18,7 @@ {{ 'addon.mod_workshop.submissioncontent' | translate }} - + diff --git a/src/addon/mod/workshop/pages/edit-submission/edit-submission.ts b/src/addon/mod/workshop/pages/edit-submission/edit-submission.ts index 816a29b46..c3fb1edbb 100644 --- a/src/addon/mod/workshop/pages/edit-submission/edit-submission.ts +++ b/src/addon/mod/workshop/pages/edit-submission/edit-submission.ts @@ -51,6 +51,7 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy { component = AddonModWorkshopProvider.COMPONENT; componentId: number; editForm: FormGroup; // The form group. + editorExtraParams: {[name: string]: any} = {}; protected workshopId: number; protected submissionId: number; @@ -86,6 +87,10 @@ export class AddonModWorkshopEditSubmissionPage implements OnInit, OnDestroy { this.editForm = new FormGroup({}); this.editForm.addControl('title', this.fb.control('', Validators.required)); this.editForm.addControl('content', this.fb.control('')); + + if (this.submissionId) { + this.editorExtraParams.id = this.submissionId; + } } /** diff --git a/src/addon/mod/workshop/pages/submission/submission.html b/src/addon/mod/workshop/pages/submission/submission.html index 41fbecd1d..0951709ae 100644 --- a/src/addon/mod/workshop/pages/submission/submission.html +++ b/src/addon/mod/workshop/pages/submission/submission.html @@ -87,7 +87,7 @@
{{ 'addon.mod_workshop.feedbackauthor' | translate }} - + diff --git a/src/addon/qtype/essay/component/addon-qtype-essay.html b/src/addon/qtype/essay/component/addon-qtype-essay.html index 5c171fedc..13462423b 100644 --- a/src/addon/qtype/essay/component/addon-qtype-essay.html +++ b/src/addon/qtype/essay/component/addon-qtype-essay.html @@ -11,7 +11,7 @@ - + diff --git a/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html b/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html index 1d149a8ed..8908db521 100644 --- a/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html +++ b/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html @@ -9,5 +9,5 @@ {{ field.name }} - + \ No newline at end of file diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index e9673f525..d3f4ff056 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -1482,6 +1482,8 @@ "core.downloaded": "Downloaded", "core.downloading": "Downloading", "core.edit": "Edit", + "core.editor.autosavesucceeded": "Draft saved.", + "core.editor.textrecovered": "A draft version of this text was automatically restored.", "core.emptysplit": "This page will appear blank if the left panel is empty or is loading.", "core.error": "Error", "core.errorchangecompletion": "An error occurred while changing the completion status. Please try again.", diff --git a/src/core/editor/components/rich-text-editor/core-editor-rich-text-editor.html b/src/core/editor/components/rich-text-editor/core-editor-rich-text-editor.html index ba2bd897f..6b3a503ed 100644 --- a/src/core/editor/components/rich-text-editor/core-editor-rich-text-editor.html +++ b/src/core/editor/components/rich-text-editor/core-editor-rich-text-editor.html @@ -1,7 +1,14 @@ -
-
+
+
+
- + + +
+ + {{ infoMessage | translate }} +
+