Bugzilla – Attachment 154573 Details for
Bug 26916
Show searchable patron attributes in patron search dropdown
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26916: Show searchable patron attributes in patron search dropdown
Bug-26916-Show-searchable-patron-attributes-in-pat.patch (text/plain), 5.47 KB, created by
Nick Clemens (kidclamp)
on 2023-08-17 19:48:34 UTC
(
hide
)
Description:
Bug 26916: Show searchable patron attributes in patron search dropdown
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-08-17 19:48:34 UTC
Size:
5.47 KB
patch
obsolete
>From bee38767f45c8f75d8a8e95c15ade8c37962cb24 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 11 Aug 2023 15:57:42 +0000 >Subject: [PATCH] Bug 26916: Show searchable patron attributes in patron search > dropdown > >This patch adds attributes that have been marked searchable to the patron >search dropdowns > >To test: >1 - Define some new patron attribute types and make then staff_searchable >2 - Add some values to patrons >3 - Confirm they are searched in 'Standard' search, but there is no other way to search them >4 - Apply patch >5 - Confirm the fields now show in patorn search dropdowns >6 - Search using 'standard' and confirm the searhc works >7 - Search specific attributes and confirm the searhc works >--- > .../prog/en/includes/patronfields.inc | 9 ++++++++ > .../intranet-tmpl/prog/js/staff-global.js | 23 ++++++++++++++----- > 2 files changed, 26 insertions(+), 6 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc >index 777cc300bd9..d3e111eb3dd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patronfields.inc >@@ -99,5 +99,14 @@ > <option value=[% s_o | html %]>[% display_name | $raw %]</option> > [% END %] > [% END %] >+ [% IF Koha.Preference('ExtendedPatronAttributes') %] >+ [% FOREACH attribute IN ExtendedAttributeTypes.all( staff_searchable => 1 ) %] >+ [% IF searchfieldstype == "_ATTR_" _ attribute.code %] >+ <option value=[% "_ATTR_" _ attribute.code | html %] selected="selected">[% attribute.description | html %]</option> >+ [% ELSE %] >+ <option value=[% "_ATTR_" _ attribute.code | html %]>[% attribute.description | html %]</option> >+ [% END %] >+ [% END %] >+ [% END %] > </select> > [%- END -%] >diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >index 884a430c104..b254bd69a0a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >@@ -548,7 +548,7 @@ function buildPatronSearchQuery(term, options) { > > let q = []; > let leading_wildcard; >- let search_fields; >+ let search_fields = []; > let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length }); > > // Bail if no patterns >@@ -564,9 +564,18 @@ function buildPatronSearchQuery(term, options) { > leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; > } > >+ let searched_attribute_fields = []; > // Search fields: If search_fields option exists, we use that > if (typeof options !== 'undefined' && options.search_fields) { >- search_fields = expandPatronSearchFields(options.search_fields); >+ expand_fields = expandPatronSearchFields(options.search_fields); >+ expand_fields.split('\|').forEach(function (field, i) { >+ if( field.startsWith('_ATTR_') ){ >+ let attr_field = field.replace("_ATTR_",""); >+ searched_attribute_fields.push( attr_field ); >+ } else { >+ search_fields.push( field ); >+ } >+ }); > // If not, we use DefaultPatronSearchFields system preference instead > } else { > search_fields = defaultPatronSearchFields; >@@ -576,7 +585,7 @@ function buildPatronSearchQuery(term, options) { > let pattern_subquery_and = []; > patterns.forEach(function (pattern, i) { > let pattern_subquery_or = []; >- search_fields.split('\|').forEach(function (field, i) { >+ search_fields.forEach(function (field, i) { > pattern_subquery_or.push( > { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } > ); >@@ -593,9 +602,10 @@ function buildPatronSearchQuery(term, options) { > }); > q.push({ "-and": pattern_subquery_and }); > >+ > // Add full search term for each search field > let term_subquery_or = []; >- search_fields.split('\|').forEach(function (field, i) { >+ search_fields.forEach(function (field, i) { > term_subquery_or.push( > { ["me." + field]: { 'like': leading_wildcard + term + '%' } } > ); >@@ -603,13 +613,14 @@ function buildPatronSearchQuery(term, options) { > q.push({ "-or": term_subquery_or }); > > // Add each pattern for each extended patron attributes >- if (typeof options !== 'undefined' && options.search_fields == 'standard' && options.extended_attribute_types && extendedPatronAttributes) { >+ if ( typeof options !== 'undefined' && ( (options.search_fields == 'standard' && options.extended_attribute_types) || searched_attribute_fields ) && extendedPatronAttributes) { >+ extended_attribute_codes_to_search = (searched_attribute_fields.length > 0) ? searched_attribute_fields : options.extended_attribute_types; > extended_attribute_subquery_and = []; > patterns.forEach(function (pattern, i) { > let extended_attribute_sub_or = []; > extended_attribute_sub_or.push({ > "extended_attributes.value": { "like": leading_wildcard + pattern + '%' }, >- "extended_attributes.code": options.extended_attribute_types >+ "extended_attributes.code": extended_attribute_codes_to_search > }); > extended_attribute_subquery_and.push(extended_attribute_sub_or); > }); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26916
:
154385
|
154386
|
154573
|
154574
|
154653
|
154654
|
158427
|
158428