Skip to content

Commit

Permalink
Merge pull request #205 from justb4/master
Browse files Browse the repository at this point in the history
fix for gxp #191 - allow automatic wildcard attachment in LIKE Filters
  • Loading branch information
ahocevar committed Jul 22, 2013
2 parents df41c90 + 6d7929c commit 4d16c22
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/script/widgets/FilterBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ gxp.FilterBuilder = Ext.extend(Ext.Container, {
}
return filter;
},

createDefaultFilter: function() {
return new OpenLayers.Filter.Comparison({
matchCase: !this.caseInsensitiveMatch});
Expand Down
40 changes: 40 additions & 0 deletions src/script/widgets/QueryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ gxp.QueryPanel = Ext.extend(Ext.Panel, {
*/
caseInsensitiveMatch: false,

/** api: config[likeSubstring]
* ``Boolean``
* Allow substrings to be entered with LIKE comparisons? These strings will be wrapped in wildcards.
* Default is ``"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``
* The currently selected record in the layers combo.
Expand Down Expand Up @@ -325,6 +338,12 @@ 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);
}

var spatialFilter = this.spatialQuery && new OpenLayers.Filter.Spatial({
type: OpenLayers.Filter.Spatial.BBOX,
value: this.map.getExtent()
Expand All @@ -341,6 +360,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
Expand Down

0 comments on commit 4d16c22

Please sign in to comment.