Bugzilla – Attachment 152698 Details for
Bug 34092
patron-autocomplete.js and patron-search.inc search logic should match
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34092: Move search-patron.inc logic into buildPatronSearchQuery
Bug-34092-Move-search-patroninc-logic-into-buildPa.patch (text/plain), 9.08 KB, created by
Pedro Amorim
on 2023-06-26 15:45:00 UTC
(
hide
)
Description:
Bug 34092: Move search-patron.inc logic into buildPatronSearchQuery
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2023-06-26 15:45:00 UTC
Size:
9.08 KB
patch
obsolete
>From 0470cc03d23b41c8957adfc6166b6e21fc130362 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 26 Jun 2023 12:51:13 +0000 >Subject: [PATCH] Bug 34092: Move search-patron.inc logic into > buildPatronSearchQuery > >--- > .../prog/en/includes/js_includes.inc | 1 + > .../prog/en/includes/patron-search.inc | 63 +++++-------------- > .../intranet-tmpl/prog/js/staff-global.js | 61 +++++++++++++++--- > 3 files changed, 71 insertions(+), 54 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >index 1e687f8ab7..bd41d755a6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/js_includes.inc >@@ -71,6 +71,7 @@ > <script> > var defaultPatronSearchFields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]"; > var defaultPatronSearchMethod = "[% Koha.Preference('DefaultPatronSearchMethod') || 'contains' | html %]"; >+ var extendedPatronAttributes = "[% Koha.Preference('ExtendedPatronAttributes') | html %]"; > var loggedInLibrary = '[% Branches.GetLoggedInBranchcode | html %]'; > var singleBranchMode = '[% singleBranchMode | html %]'; > </script> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >index 9cead35acc..ee09b35eb2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron-search.inc >@@ -19,6 +19,8 @@ > [%# You can then pass a list of filters %] > [%# - branch: select library list %] > [%# - category: select patron category list %] >+[%# - sort1: select patron sort1 field %] >+[%# - sort2: select patron sort2 field %] > [%# - search_field: select patron field list %] > [%# - search_type: select 'contain' or 'start with' %] > [% BLOCK patron_search_filters %] >@@ -315,6 +317,20 @@ > }, > "-and": function(){ > let filters = []; >+ >+ let search_type = $("#searchtype_filter").val() || "contain"; >+ let search_fields = $("#searchfieldstype_filter").val(); >+ let pattern = $("#search_patron_filter").val(); >+ >+ filters = buildPatronSearchQuery( >+ pattern, >+ { >+ search_type: search_type, >+ search_fields: search_fields, >+ extended_attribute_types: extended_attribute_types >+ } >+ ); >+ > let f_sort1 = $("#sort1_filter").val(); > if ( f_sort1 ) { > filters.push({ >@@ -328,53 +344,6 @@ > }); > } > >- let pattern = $("#search_patron_filter").val(); >- if (!pattern) { >- if ( filters.length == 0 ) { >- return ""; >- } >- else { >- return filters; >- } >- } >- let patterns = pattern.split(/[\s,]+/).filter(function(s){ return s.length }); >- >- let search_type = $("#searchtype_filter").val() || "contain"; >- let search_fields = $("#searchfieldstype_filter").val(); >- if ( !search_fields ) { >- search_fields = "[% Koha.Preference('DefaultPatronSearchFields') || 'firstname,middle_name,surname,othernames,cardnumber,userid' | html %]"; >- } >- >- let subquery_and = []; >- patterns.forEach(function(pattern,i){ >- let sub_or = []; >- search_fields.split(',').forEach(function(attr,ii){ >- sub_or.push({["me."+attr]:{"like":(search_type == "contain" ? "%" : "" ) + pattern + "%"}}); >- if ( attr == 'dateofbirth' ) { >- try { >- let d = $date_to_rfc3339(pattern); >- sub_or.push({["me."+attr]:d}); >- } catch { >- // Hide the warning if the date is not correct >- } >- } >- }); >- subquery_and.push(sub_or); >- }); >- filters.push({"-and": subquery_and}); >- >- [% IF Koha.Preference('ExtendedPatronAttributes') && extended_attribute_types %] >- subquery_and = []; >- patterns.forEach(function(pattern,i){ >- let sub_or = []; >- sub_or.push({ >- "extended_attributes.value": { "like": "%" + pattern + (search_type == "contain" ? "%" : "" )}, >- "extended_attributes.code": extended_attribute_types >- }); >- subquery_and.push(sub_or); >- }); >- filters.push({"-and": subquery_and}); >- [% END %] > return filters; > } > }; >diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >index 3203109d23..3ab3a006dd 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js >@@ -510,23 +510,58 @@ function patron_autocomplete(node, options) { > }; > } > >- >+/** >+ * Build patron search query >+ * - term: The full search term input by the user >+ * You can then pass a list of options: >+ * - search_type: String 'contain' or 'start_with', defaults to DefaultPatronSearchMethod system preference >+ * - search_fields: String comma-separated list of specific fields, defaults to DefaultPatronSearchFields system preference >+ * - extended_attribute_types: JSON object containing the patron attribute types to be searched on >+ */ > function buildPatronSearchQuery(term, options) { > > let q = []; >- let leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; >- let search_fields = defaultPatronSearchFields; >+ let leading_wildcard; >+ let search_fields; >+ let patterns = term.split(/[\s,]+/).filter(function (s) { return s.length }); >+ >+ // Bail if no patterns >+ if (patterns.length == 0) { >+ return; >+ } >+ >+ // Leading wildcard: If search_type option exists, we use that >+ if (typeof options !== 'undefined' && options.search_type) { >+ leading_wildcard = options.search_type === "contain" ? '%' : ''; >+ // If not, we use DefaultPatronSearchMethod system preference instead >+ } else { >+ leading_wildcard = defaultPatronSearchMethod === 'contains' ? '%' : ''; >+ } >+ >+ // Search fields: If search_fields option exists, we use that >+ if (typeof options !== 'undefined' && options.search_fields) { >+ search_fields = options.search_fields; >+ // If not, we use DefaultPatronSearchFields system preference instead >+ } else { >+ search_fields = defaultPatronSearchFields; >+ } > > // Add each pattern for each search field > let pattern_subquery_and = []; >- term.split(/[\s,]+/) >- .filter(function (s) { return s.length }) >- .forEach(function (pattern, i) { >+ patterns.forEach(function (pattern, i) { > let pattern_subquery_or = []; > search_fields.split(',').forEach(function (field, i) { > pattern_subquery_or.push( > { ["me." + field]: { 'like': leading_wildcard + pattern + '%' } } > ); >+ if (field == 'dateofbirth') { >+ try { >+ let d = $date_to_rfc3339(pattern); >+ pattern_subquery_or.push({ ["me." + field]: d }); >+ } catch { >+ // Hide the warning if the date is not correct >+ } >+ } > }); > pattern_subquery_and.push(pattern_subquery_or); > }); >@@ -541,6 +576,18 @@ function buildPatronSearchQuery(term, options) { > }); > q.push({ "-or": term_subquery_or }); > >- >+ // Add each pattern for each extended patron attributes >+ if (typeof options !== 'undefined' && options.extended_attribute_types && extendedPatronAttributes) { >+ 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_attribute_subquery_and.push(extended_attribute_sub_or); >+ }); >+ q.push({ "-and": extended_attribute_subquery_and }); >+ } > return q; > } >-- >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 34092
:
152682
|
152683
|
152684
|
152698
|
152830
|
152831
|
152832
|
152854
|
152855
|
152856
|
152882
|
152883
|
152884
|
152885
|
152891