diff --git a/scripts/langindex.json b/scripts/langindex.json index a381cb81c..fb40d9d80 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -555,6 +555,7 @@ "addon.mod_data.authorfirstname": "data", "addon.mod_data.authorlastname": "data", "addon.mod_data.confirmdeleterecord": "data", + "addon.mod_data.datemodified": "data", "addon.mod_data.descending": "data", "addon.mod_data.disapprove": "data", "addon.mod_data.edittagsnotsupported": "local_moodlemobileapp", diff --git a/src/addons/mod/data/classes/base-field-plugin-component.ts b/src/addons/mod/data/classes/base-field-plugin-component.ts index 6fb1d032f..b045cca0b 100644 --- a/src/addons/mod/data/classes/base-field-plugin-component.ts +++ b/src/addons/mod/data/classes/base-field-plugin-component.ts @@ -74,7 +74,7 @@ export abstract class AddonModDataFieldPluginBaseComponent implements OnInit, On } /** - * Component being changed. + * @inheritdoc */ ngOnChanges(changes: { [name: string]: SimpleChange }): void { if ((this.showMode || this.listMode) && changes.value) { diff --git a/src/addons/mod/data/data-forms.scss b/src/addons/mod/data/data-forms.scss index d49231156..146abf1fc 100644 --- a/src/addons/mod/data/data-forms.scss +++ b/src/addons/mod/data/data-forms.scss @@ -3,25 +3,32 @@ // Edit and search modal. :host { - ::ng-deep { - table { - width: 100%; - } - td { - vertical-align: top; - } - } - .addon-data-advanced-search { padding: 16px; width: 100%; } - .addon-data-contents form, + .addon-data-edit-entry form, form .addon-data-advanced-search { background-color: var(--ion-item-background); ::ng-deep { + table { + width: 100%; + tbody { + display: block; + } + + td { + vertical-align: top; + } + } + + .edit-field, + .search-field { + border-bottom: 1px solid var(--stroke); + } + .has-errors { .input-highlight, .select-highlight, diff --git a/src/addons/mod/data/data.scss b/src/addons/mod/data/data.scss index f994af4ad..4929ee909 100644 --- a/src/addons/mod/data/data.scss +++ b/src/addons/mod/data/data.scss @@ -16,17 +16,15 @@ $grid-column-paddings: ( --border-color: var(--stroke); } -.addon-data-edit-entry { +.addon-data-contents { overflow: visible; white-space: normal; word-break: break-word; padding: 16px; - background-color: var(--ion-item-background); - border-bottom: 1px solid var(--border-color); - ::ng-deep { - table, tbody { + + table { display: block; } diff --git a/src/addons/mod/data/lang.json b/src/addons/mod/data/lang.json index 3ffdfdbce..53248678c 100644 --- a/src/addons/mod/data/lang.json +++ b/src/addons/mod/data/lang.json @@ -9,6 +9,7 @@ "authorfirstname": "First name", "authorlastname": "Last name", "confirmdeleterecord": "Are you sure you want to delete this entry?", + "datemodified": "Last edited:", "descending": "Descending", "disapprove": "Undo approval", "edittagsnotsupported": "Sorry, editing tags is not supported by the app.", diff --git a/src/addons/mod/data/services/data-helper.ts b/src/addons/mod/data/services/data-helper.ts index a5df40d37..48ab0bbc4 100644 --- a/src/addons/mod/data/services/data-helper.ts +++ b/src/addons/mod/data/services/data-helper.ts @@ -504,84 +504,165 @@ export class AddonModDataHelperProvider { /** * Returns the default template of a certain type. * - * Based on Moodle function data_generate_default_template. - * * @param type Type of template. * @param fields List of database fields. * @returns Template HTML. */ - getDefaultTemplate(type: AddonModDataTemplateType, fields: AddonModDataField[]): string { - if (type == AddonModDataTemplateType.LIST_HEADER || type == AddonModDataTemplateType.LIST_FOOTER) { - return ''; + protected getDefaultTemplate(type: AddonModDataTemplateType, fields: AddonModDataField[]): string { + switch (type) { + case AddonModDataTemplateType.LIST: + return this.getDefaultListTemplate(fields); + case AddonModDataTemplateType.SINGLE: + return this.getDefaultSingleTemplate(fields); + case AddonModDataTemplateType.SEARCH: + return this.getDefaultSearchTemplate(fields); + case AddonModDataTemplateType.ADD: + return this.getDefaultAddTemplate(fields); } + return ''; + } + + /** + * Returns the default template for the list view. + * + * @param fields List of database fields. + * @returns Template HTML. + */ + protected getDefaultListTemplate(fields: AddonModDataField[]): string { const html: string[] = []; - if (type == AddonModDataTemplateType.LIST) { - html.push('##delcheck##
'); - } + html.push(` + + ##userpicture## + +

##user##

+

##timeadded##

+

+ ${Translate.instant('addon.mod_data.datemodified')} ##timemodified## +

+
+
+ ##actionsmenu## +

##approvalstatus##

+
+
- html.push( - '
', - '', - '', - ); + `); fields.forEach((field) => { - html.push( - '', - '', - '', - '', - ); + html.push(` + + ${field.name} + [[${field.name}]] + `); }); - if (type == AddonModDataTemplateType.LIST) { - html.push( - '', - '', - '', - ); - } else if (type == AddonModDataTemplateType.SINGLE) { - html.push( - '', - '', - '', - ); - } else if (type == AddonModDataTemplateType.SEARCH) { - html.push( - '', - '', - '', - '', - '', - '', - '', - '', - ); - } - - html.push( - '', - '
', - field.name, - ': [[', - field.name, - ']]
', - '##actionsmenu## ##edit## ##more## ##delete## ##approve## ##disapprove## ##export##', - '
', - '##actionsmenu## ##edit## ##delete## ##approve## ##disapprove## ##export##', - '
Author first name: ##firstname##
Author surname: ##lastname##
', - '
', - ); - - if (type == AddonModDataTemplateType.LIST) { - html.push('
'); - } + html.push('##tags##
'); return html.join(''); } + /** + * Returns the default template for the add view. + * + * @param fields List of database fields. + * @returns Template HTML. + */ + protected getDefaultAddTemplate(fields: AddonModDataField[]): string { + const html: string[] = []; + + html.push('
'); + + fields.forEach((field) => { + html.push(` +
+

${field.name}

+ [[${field.name}]] +
`); + }); + + html.push('##otherfields## ##tags##
'); + + return html.join(''); + } + + /** + * Returns the default template for the single view. + * + * @param fields List of database fields. + * @returns Template HTML. + */ + protected getDefaultSingleTemplate(fields: AddonModDataField[]): string { + const html: string[] = []; + + html.push(`
+
+ + ##userpicture## + +

##user##

+

##timeadded##

+

+ ${Translate.instant('addon.mod_data.datemodified')} ##timemodified## +

+
+
+ ##actionsmenu## +

##approvalstatus##

+
+
`); + + fields.forEach((field) => { + html.push(` + +

${field.name}

+

[[${field.name}]]

+
`); + }); + + html.push('##otherfields## ##tags##
'); + + return html.join(''); + } + + /** + * Returns the default template for the search view. + * + * @param fields List of database fields. + * @returns Template HTML. + */ + protected getDefaultSearchTemplate(fields: AddonModDataField[]): string { + const html: string[] = []; + + html.push('
'); + + html.push(` +
+

${Translate.instant('addon.mod_data.authorfirstname')}

+ ##firstname## +
`); + + html.push(` +
+

${Translate.instant('addon.mod_data.authorlastname')}

+ ##lastname## +
`); + + fields.forEach((field) => { + html.push(` +
+

${field.name}

+ [[${field.name}]] +
`); + }); + + html.push('##tags##
'); + + return html.join(''); + + } + /** * Retrieve the entered data in the edit form. * We don't use ng-model because it doesn't detect changes done by JavaScript.