From ee1ecba1fc5779bab6a519ad52f30178e2b9bcde Mon Sep 17 00:00:00 2001 From: Just van den Broecke Date: Mon, 27 May 2013 12:34:31 +0200 Subject: [PATCH 1/3] fix for gxp #191 - allow automatic wildcard attachment in LIKE Filters --- src/script/widgets/FilterBuilder.js | 41 +++++++++++++++++++++++++++++ src/script/widgets/QueryPanel.js | 10 ++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/script/widgets/FilterBuilder.js b/src/script/widgets/FilterBuilder.js index c643186b..34d42928 100644 --- a/src/script/widgets/FilterBuilder.js +++ b/src/script/widgets/FilterBuilder.js @@ -52,6 +52,21 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, { */ caseInsensitiveMatch: false, + + /** api: config[autoWildCardAttach] + * ``Boolean`` + * Should search strings (LIKE comparison only) for attribute queries always be pre- and postfixed with wildcards? + * The ``wildCardString`` variable determines the wildcard string to be attached. + * Default is ``"false"``. + */ + autoWildCardAttach: false, + + /** api: config[wildCardString] + * ``String`` + * String to be pre- and postfixed for wildcards in LIKE Comparison Filters. + */ + wildCardString: '.*', + /** api: config[preComboText] * ``String`` * String to display before filter type combo. Default is ``"Match"``. @@ -193,6 +208,11 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, { if(filter instanceof OpenLayers.Filter.Logical) { filter = this.cleanFilter(filter); } + + // Should wildcard chars be attached to LIKE Filters? + if (this.autoWildCardAttach) { + filter = this.attachWildCards(filter); + } } return filter; }, @@ -332,6 +352,27 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, { return filter; }, + /** api: method[attachWildCards] + * :return: ``OpenLayers.Filter`` + * + * Returns a filter where wildcard symbols are pre/appended for + * Comparison LIKE Filters. + */ + attachWildCards: function (filter) { + + if (filter instanceof OpenLayers.Filter.Logical) { + // Go recursively through composite filter + for (var i = 0, len = filter.filters.length; i < len; ++i) { + filter = this.attachWildCards(filter.filters[i]); + } + } else if (filter.type === OpenLayers.Filter.Comparison.LIKE) { + // Wrap the value in Wildcard strings. + filter.value = this.wildCardString + filter.value + this.wildCardString; + } + + return filter; + }, + createDefaultFilter: function() { return new OpenLayers.Filter.Comparison({ matchCase: !this.caseInsensitiveMatch}); diff --git a/src/script/widgets/QueryPanel.js b/src/script/widgets/QueryPanel.js index 4ff7eb07..a9494c37 100644 --- a/src/script/widgets/QueryPanel.js +++ b/src/script/widgets/QueryPanel.js @@ -77,6 +77,13 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { */ caseInsensitiveMatch: false, + /** api: config[autoWildCardAttach] + * ``Boolean`` + * Should search strings (LIKE comparison only) for attribute queries always be pre/postpended with a wildcard '*' character? + * Default is ``"false"``. + */ + autoWildCardAttach: false, + /** private: property[selectedLayer] * ``Ext.data.Record`` * The currently selected record in the layers combo. @@ -299,7 +306,8 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { //anchor: "-8px", attributes: this.attributeStore, allowGroups: false, - caseInsensitiveMatch: this.caseInsensitiveMatch + caseInsensitiveMatch: this.caseInsensitiveMatch, + autoWildCardAttach: this.autoWildCardAttach }); if(owner) { From 132ee8e49bf64890c37b539f9f2cb7a170fefa8f Mon Sep 17 00:00:00 2001 From: Just van den Broecke Date: Mon, 22 Jul 2013 15:07:02 +0200 Subject: [PATCH 2/3] fix for issue #191 : allow LIKE substrings in QueryBuilder form --- src/script/widgets/FilterBuilder.js | 41 ----------------------------- src/script/widgets/QueryPanel.js | 41 +++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/src/script/widgets/FilterBuilder.js b/src/script/widgets/FilterBuilder.js index 34d42928..e5641644 100644 --- a/src/script/widgets/FilterBuilder.js +++ b/src/script/widgets/FilterBuilder.js @@ -52,21 +52,6 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, { */ caseInsensitiveMatch: false, - - /** api: config[autoWildCardAttach] - * ``Boolean`` - * Should search strings (LIKE comparison only) for attribute queries always be pre- and postfixed with wildcards? - * The ``wildCardString`` variable determines the wildcard string to be attached. - * Default is ``"false"``. - */ - autoWildCardAttach: false, - - /** api: config[wildCardString] - * ``String`` - * String to be pre- and postfixed for wildcards in LIKE Comparison Filters. - */ - wildCardString: '.*', - /** api: config[preComboText] * ``String`` * String to display before filter type combo. Default is ``"Match"``. @@ -208,11 +193,6 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, { if(filter instanceof OpenLayers.Filter.Logical) { filter = this.cleanFilter(filter); } - - // Should wildcard chars be attached to LIKE Filters? - if (this.autoWildCardAttach) { - filter = this.attachWildCards(filter); - } } return filter; }, @@ -351,27 +331,6 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, { } return filter; }, - - /** api: method[attachWildCards] - * :return: ``OpenLayers.Filter`` - * - * Returns a filter where wildcard symbols are pre/appended for - * Comparison LIKE Filters. - */ - attachWildCards: function (filter) { - - if (filter instanceof OpenLayers.Filter.Logical) { - // Go recursively through composite filter - for (var i = 0, len = filter.filters.length; i < len; ++i) { - filter = this.attachWildCards(filter.filters[i]); - } - } else if (filter.type === OpenLayers.Filter.Comparison.LIKE) { - // Wrap the value in Wildcard strings. - filter.value = this.wildCardString + filter.value + this.wildCardString; - } - - return filter; - }, createDefaultFilter: function() { return new OpenLayers.Filter.Comparison({ diff --git a/src/script/widgets/QueryPanel.js b/src/script/widgets/QueryPanel.js index a9494c37..55cc6078 100644 --- a/src/script/widgets/QueryPanel.js +++ b/src/script/widgets/QueryPanel.js @@ -77,12 +77,18 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { */ caseInsensitiveMatch: false, - /** api: config[autoWildCardAttach] + /** api: config[likeSubstring] * ``Boolean`` - * Should search strings (LIKE comparison only) for attribute queries always be pre/postpended with a wildcard '*' character? + * Allow substrings to be entered with LIKE comparisons? These strings will be wrapped in wildcards. * Default is ``"false"``. */ - autoWildCardAttach: false, + likeSubstring: false, + + /** api: config[wildCardString] + * ``String`` + * String to be pre- and postfixed for substrings in LIKE Comparison Filters. + */ + wildCardString: '.*', /** private: property[selectedLayer] * ``Ext.data.Record`` @@ -306,8 +312,7 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { //anchor: "-8px", attributes: this.attributeStore, allowGroups: false, - caseInsensitiveMatch: this.caseInsensitiveMatch, - autoWildCardAttach: this.autoWildCardAttach + caseInsensitiveMatch: this.caseInsensitiveMatch }); if(owner) { @@ -333,6 +338,11 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { */ getFilter: function() { var attributeFilter = this.attributeQuery && this.filterBuilder.getFilter(); + + if (attributeFilter && this.likeSubstring) { + attributeFilter = this.wrapWildCards(attributeFilter); + } + var spatialFilter = this.spatialQuery && new OpenLayers.Filter.Spatial({ type: OpenLayers.Filter.Spatial.BBOX, value: this.map.getExtent() @@ -349,6 +359,27 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { return filter; }, + /** private: method[wrapWildCards] + * :return: ``OpenLayers.Filter`` + * + * Returns the same (Composite) Filter with string literals wrapped with wildcard symbols + * for all Comparison LIKE Filters. + */ + wrapWildCards: function (filter) { + + if (filter instanceof OpenLayers.Filter.Logical) { + // Go recursively through composite filter + for (var i = 0, len = filter.filters.length; i < len; ++i) { + filter = this.wrapWildCards(filter.filters[i]); + } + } else if (filter.type === OpenLayers.Filter.Comparison.LIKE) { + // Wrap the value in Wildcard strings. + filter.value = this.wildCardString + filter.value + this.wildCardString; + } + + return filter; + }, + /** private: method[getFieldType] * :arg attrType: ``String`` Attribute type. * :returns: ``String`` Field type From 6d7929ccfeadfeb0c50895548a28cc01e71d62e9 Mon Sep 17 00:00:00 2001 From: Just van den Broecke Date: Mon, 22 Jul 2013 15:08:39 +0200 Subject: [PATCH 3/3] fix for issue #191 : allow LIKE substrings in QueryBuilder form (comments) --- src/script/widgets/QueryPanel.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/script/widgets/QueryPanel.js b/src/script/widgets/QueryPanel.js index 55cc6078..339325e1 100644 --- a/src/script/widgets/QueryPanel.js +++ b/src/script/widgets/QueryPanel.js @@ -339,6 +339,7 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, { getFilter: function() { var attributeFilter = this.attributeQuery && this.filterBuilder.getFilter(); + // If LIKE comparison substrings are enabled, wrap their string literals in wildcards if (attributeFilter && this.likeSubstring) { attributeFilter = this.wrapWildCards(attributeFilter); }