From 84d2e9e4da526f844f2a307edfba465a4f240423 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 30 Mar 2023 16:13:56 +0200 Subject: [PATCH] MOBILE-2652 glossary: Fix categories & aliases These have been removed from online edits because of the limitations described in MDL-77798 --- src/addons/mod/glossary/pages/edit/edit.html | 2 +- src/addons/mod/glossary/pages/edit/edit.ts | 42 +++++++++++++------ .../glossary/tests/behat/basic_usage.feature | 8 ++++ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/src/addons/mod/glossary/pages/edit/edit.html b/src/addons/mod/glossary/pages/edit/edit.html index eee439c4a..0af9d5629 100644 --- a/src/addons/mod/glossary/pages/edit/edit.html +++ b/src/addons/mod/glossary/pages/edit/edit.html @@ -39,7 +39,7 @@ - + {{ 'addon.mod_glossary.aliases' | translate }} diff --git a/src/addons/mod/glossary/pages/edit/edit.ts b/src/addons/mod/glossary/pages/edit/edit.ts index ec8ef84d8..e27fb967d 100644 --- a/src/addons/mod/glossary/pages/edit/edit.ts +++ b/src/addons/mod/glossary/pages/edit/edit.ts @@ -59,6 +59,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { glossary?: AddonModGlossaryGlossary; definitionControl = new FormControl(); categories: AddonModGlossaryCategory[] = []; + showAliases = true; editorExtraParams: Record = {}; handler!: AddonModGlossaryFormHandler; data: AddonModGlossaryFormData = { @@ -125,10 +126,6 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave { await this.handler.loadData(this.glossary); - this.categories = await AddonModGlossary.getAllCategories(this.glossary.id, { - cmId: this.cmId, - }); - this.loaded = true; } catch (error) { CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true); @@ -272,6 +269,17 @@ abstract class AddonModGlossaryFormHandler { */ abstract save(glossary: AddonModGlossaryGlossary): Promise; + /** + * Load form categories. + * + * @param glossary Glossary. + */ + protected async loadCategories(glossary: AddonModGlossaryGlossary): Promise { + this.page.categories = await AddonModGlossary.getAllCategories(glossary.id, { + cmId: this.page.cmId, + }); + } + /** * Upload attachments online. * @@ -341,10 +349,15 @@ abstract class AddonModGlossaryFormHandler { */ protected getSaveOptions(glossary: AddonModGlossaryGlossary): Record { const data = this.page.data; - const options: Record = { - aliases: data.aliases, - categories: data.categories.join(','), - }; + const options: Record = {}; + + if (this.page.showAliases) { + options.aliases = data.aliases; + } + + if (this.page.categories.length > 0) { + options.categories = data.categories.join(','); + } if (glossary.usedynalink) { options.usedynalink = data.usedynalink ? 1 : 0; @@ -385,8 +398,8 @@ class AddonModGlossaryOfflineFormHandler extends AddonModGlossaryFormHandler { data.timecreated = entry.timecreated; if (entry.options) { - data.categories = (entry.options.categories && ( entry.options.categories).split(',')) || []; - data.aliases = entry.options.aliases || ''; + data.categories = ((entry.options.categories as string)?.split(',') ?? []).map(id => Number(id)); + data.aliases = entry.options.aliases as string ?? ''; data.usedynalink = !!entry.options.usedynalink; if (data.usedynalink) { @@ -413,6 +426,8 @@ class AddonModGlossaryOfflineFormHandler extends AddonModGlossaryFormHandler { }; this.page.definitionControl.setValue(data.definition); + + await this.loadCategories(glossary); } /** @@ -486,8 +501,8 @@ class AddonModGlossaryNewFormHandler extends AddonModGlossaryFormHandler { /** * @inheritdoc */ - async loadData(): Promise { - // There is no data to load, given that this is a new entry. + async loadData(glossary: AddonModGlossaryGlossary): Promise { + await this.loadCategories(glossary); } /** @@ -644,6 +659,7 @@ class AddonModGlossaryOnlineFormHandler extends AddonModGlossaryFormHandler { }; this.page.definitionControl.setValue(data.definition); + this.page.showAliases = false; } /** @@ -686,7 +702,7 @@ type AddonModGlossaryFormData = { definition: string; timecreated: number; attachments: CoreFileEntry[]; - categories: string[]; + categories: number[]; aliases: string; usedynalink: boolean; casesensitive: boolean; diff --git a/src/addons/mod/glossary/tests/behat/basic_usage.feature b/src/addons/mod/glossary/tests/behat/basic_usage.feature index f4a4f9862..4d2e0d270 100644 --- a/src/addons/mod/glossary/tests/behat/basic_usage.feature +++ b/src/addons/mod/glossary/tests/behat/basic_usage.feature @@ -162,6 +162,8 @@ Feature: Test basic usage of glossary in app And I press "Edit entry" in the app Then the field "Concept" matches value "Cucumber" in the app And the field "Definition" matches value "Sweet cucumber" in the app + But I should not find "Keyword(s)" in the app + And I should not find "Categories" in the app When I set the following fields to these values in the app: | Concept | Coconut | @@ -206,6 +208,10 @@ Feature: Test basic usage of glossary in app And I set the following fields to these values in the app: | Concept | Broccoli | | Definition | Brassica oleracea var. italica | + | Keyword(s) | vegetable, healthy | + And I press "Categories" in the app + And I press "The ones I like" in the app + And I press "OK" in the app And I press "Add file" in the app And I upload "stub1.txt" to "File" ".action-sheet-button" in the app And I press "Add file" in the app @@ -225,6 +231,8 @@ Feature: Test basic usage of glossary in app When I press "Edit entry" in the app Then the field "Concept" matches value "Broccoli" in the app And the field "Definition" matches value "Brassica oleracea var. italica" in the app + And the field "Keyword(s)" matches value "vegetable, healthy" in the app + And I should find "The ones I like" in the app And I should find "stub1.txt" in the app And I should find "stub2.txt" in the app And "This entry should be automatically linked" "ion-toggle" should be selected in the app