MOBILE-2652 glossary: Fix categories & aliases

These have been removed from online edits because of the limitations described in MDL-77798
main
Noel De Martin 2023-03-30 16:13:56 +02:00
parent d2d8a814f6
commit 84d2e9e4da
3 changed files with 38 additions and 14 deletions

View File

@ -39,7 +39,7 @@
</ion-select-option> </ion-select-option>
</ion-select> </ion-select>
</ion-item> </ion-item>
<ion-item> <ion-item *ngIf="showAliases">
<ion-label position="stacked"> <ion-label position="stacked">
{{ 'addon.mod_glossary.aliases' | translate }} {{ 'addon.mod_glossary.aliases' | translate }}
</ion-label> </ion-label>

View File

@ -59,6 +59,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
glossary?: AddonModGlossaryGlossary; glossary?: AddonModGlossaryGlossary;
definitionControl = new FormControl(); definitionControl = new FormControl();
categories: AddonModGlossaryCategory[] = []; categories: AddonModGlossaryCategory[] = [];
showAliases = true;
editorExtraParams: Record<string, unknown> = {}; editorExtraParams: Record<string, unknown> = {};
handler!: AddonModGlossaryFormHandler; handler!: AddonModGlossaryFormHandler;
data: AddonModGlossaryFormData = { data: AddonModGlossaryFormData = {
@ -125,10 +126,6 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
await this.handler.loadData(this.glossary); await this.handler.loadData(this.glossary);
this.categories = await AddonModGlossary.getAllCategories(this.glossary.id, {
cmId: this.cmId,
});
this.loaded = true; this.loaded = true;
} catch (error) { } catch (error) {
CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true); CoreDomUtils.showErrorModalDefault(error, 'addon.mod_glossary.errorloadingglossary', true);
@ -272,6 +269,17 @@ abstract class AddonModGlossaryFormHandler {
*/ */
abstract save(glossary: AddonModGlossaryGlossary): Promise<boolean>; abstract save(glossary: AddonModGlossaryGlossary): Promise<boolean>;
/**
* Load form categories.
*
* @param glossary Glossary.
*/
protected async loadCategories(glossary: AddonModGlossaryGlossary): Promise<void> {
this.page.categories = await AddonModGlossary.getAllCategories(glossary.id, {
cmId: this.page.cmId,
});
}
/** /**
* Upload attachments online. * Upload attachments online.
* *
@ -341,10 +349,15 @@ abstract class AddonModGlossaryFormHandler {
*/ */
protected getSaveOptions(glossary: AddonModGlossaryGlossary): Record<string, AddonModGlossaryEntryOption> { protected getSaveOptions(glossary: AddonModGlossaryGlossary): Record<string, AddonModGlossaryEntryOption> {
const data = this.page.data; const data = this.page.data;
const options: Record<string, AddonModGlossaryEntryOption> = { const options: Record<string, AddonModGlossaryEntryOption> = {};
aliases: data.aliases,
categories: data.categories.join(','), if (this.page.showAliases) {
}; options.aliases = data.aliases;
}
if (this.page.categories.length > 0) {
options.categories = data.categories.join(',');
}
if (glossary.usedynalink) { if (glossary.usedynalink) {
options.usedynalink = data.usedynalink ? 1 : 0; options.usedynalink = data.usedynalink ? 1 : 0;
@ -385,8 +398,8 @@ class AddonModGlossaryOfflineFormHandler extends AddonModGlossaryFormHandler {
data.timecreated = entry.timecreated; data.timecreated = entry.timecreated;
if (entry.options) { if (entry.options) {
data.categories = (entry.options.categories && (<string> entry.options.categories).split(',')) || []; data.categories = ((entry.options.categories as string)?.split(',') ?? []).map(id => Number(id));
data.aliases = <string> entry.options.aliases || ''; data.aliases = entry.options.aliases as string ?? '';
data.usedynalink = !!entry.options.usedynalink; data.usedynalink = !!entry.options.usedynalink;
if (data.usedynalink) { if (data.usedynalink) {
@ -413,6 +426,8 @@ class AddonModGlossaryOfflineFormHandler extends AddonModGlossaryFormHandler {
}; };
this.page.definitionControl.setValue(data.definition); this.page.definitionControl.setValue(data.definition);
await this.loadCategories(glossary);
} }
/** /**
@ -486,8 +501,8 @@ class AddonModGlossaryNewFormHandler extends AddonModGlossaryFormHandler {
/** /**
* @inheritdoc * @inheritdoc
*/ */
async loadData(): Promise<void> { async loadData(glossary: AddonModGlossaryGlossary): Promise<void> {
// There is no data to load, given that this is a new entry. await this.loadCategories(glossary);
} }
/** /**
@ -644,6 +659,7 @@ class AddonModGlossaryOnlineFormHandler extends AddonModGlossaryFormHandler {
}; };
this.page.definitionControl.setValue(data.definition); this.page.definitionControl.setValue(data.definition);
this.page.showAliases = false;
} }
/** /**
@ -686,7 +702,7 @@ type AddonModGlossaryFormData = {
definition: string; definition: string;
timecreated: number; timecreated: number;
attachments: CoreFileEntry[]; attachments: CoreFileEntry[];
categories: string[]; categories: number[];
aliases: string; aliases: string;
usedynalink: boolean; usedynalink: boolean;
casesensitive: boolean; casesensitive: boolean;

View File

@ -162,6 +162,8 @@ Feature: Test basic usage of glossary in app
And I press "Edit entry" in the app And I press "Edit entry" in the app
Then the field "Concept" matches value "Cucumber" in the app Then the field "Concept" matches value "Cucumber" in the app
And the field "Definition" matches value "Sweet 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: When I set the following fields to these values in the app:
| Concept | Coconut | | 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: And I set the following fields to these values in the app:
| Concept | Broccoli | | Concept | Broccoli |
| Definition | Brassica oleracea var. italica | | 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 press "Add file" in the app
And I upload "stub1.txt" to "File" ".action-sheet-button" in the app And I upload "stub1.txt" to "File" ".action-sheet-button" in the app
And I press "Add file" 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 When I press "Edit entry" in the app
Then the field "Concept" matches value "Broccoli" 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 "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 "stub1.txt" in the app
And I should find "stub2.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 And "This entry should be automatically linked" "ion-toggle" should be selected in the app