From 5129ec1d1dacca97b3b76b06436cedddc7e67f7d Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 8 Nov 2023 11:34:43 -0100 Subject: [PATCH] Bug 35287: Vue preparation - Extend KohaTable to consider searchable additional fields This follows the same pattern as in subscription serials searchable additional fields, i.e. if an additional field is searchable, it is added to the list table - with the corresponding search inputs and functionality Signed-off-by: Edith Speller Signed-off-by: Michaela Sieber Signed-off-by: Paul Derscheid --- .../prog/js/vue/components/KohaTable.vue | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/KohaTable.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/KohaTable.vue index 0f35a2cab8..5734a81934 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/KohaTable.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/KohaTable.vue @@ -16,6 +16,7 @@ import "datatables.net-buttons" import "datatables.net-buttons/js/buttons.html5" import "datatables.net-buttons/js/buttons.print" import "datatables.net-buttons/js/buttons.colVis" + DataTable.use(DataTablesLib) export default { @@ -81,6 +82,57 @@ export default { }, beforeMount() { if (this.actions.hasOwnProperty("-1")) { + if (this.searchable_additional_fields.length) { + this.searchable_additional_fields.forEach(searchable_field => { + var _customRender = (function (searchable_field) { + var _render = function (data, type, row, meta) { + return row._strings.additional_field_values + .filter( + field => + field.field_id == + searchable_field.extended_attribute_type_id + ) + .map(el => el.value_str) + } + return _render + })(searchable_field) + + this.tableColumns.push({ + name: searchable_field.name, + data: "extended_attributes", + datatype: "related-object", + related: "extended_attributes", + relatedKey: "field_id", + relatedValue: + searchable_field.extended_attribute_type_id, + relatedSearchOn: "value", + className: + "searchable-additional-column-" + + searchable_field.extended_attribute_type_id, + title: searchable_field.name, + searchable: true, + sortable: false, + render: _customRender, + }) + + if (searchable_field.authorised_value_category_name) { + let options = + this.searchable_av_options[ + searchable_field.authorised_value_category_name + ] + + options.map(e => { + e["_id"] = e["value"] + e["_str"] = e["label"] + return e + }) + + this.filters_options[this.tableColumns.length - 1] = + options + } + }) + } + this.tableColumns = [ ...this.tableColumns, { @@ -242,6 +294,16 @@ export default { type: Object, required: false, }, + searchable_additional_fields: { + type: Array, + required: false, + default: [], + }, + searchable_av_options: { + type: Array, + required: false, + default: [], + }, }, } -- 2.47.0