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>
</ion-item>
<ion-item>
<ion-item *ngIf="showAliases">
<ion-label position="stacked">
{{ 'addon.mod_glossary.aliases' | translate }}
</ion-label>

View File

@ -59,6 +59,7 @@ export class AddonModGlossaryEditPage implements OnInit, CanLeave {
glossary?: AddonModGlossaryGlossary;
definitionControl = new FormControl();
categories: AddonModGlossaryCategory[] = [];
showAliases = true;
editorExtraParams: Record<string, unknown> = {};
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<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.
*
@ -341,10 +349,15 @@ abstract class AddonModGlossaryFormHandler {
*/
protected getSaveOptions(glossary: AddonModGlossaryGlossary): Record<string, AddonModGlossaryEntryOption> {
const data = this.page.data;
const options: Record<string, AddonModGlossaryEntryOption> = {
aliases: data.aliases,
categories: data.categories.join(','),
};
const options: Record<string, AddonModGlossaryEntryOption> = {};
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 && (<string> entry.options.categories).split(',')) || [];
data.aliases = <string> 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<void> {
// There is no data to load, given that this is a new entry.
async loadData(glossary: AddonModGlossaryGlossary): Promise<void> {
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;

View File

@ -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