Permalink
Browse files

Adding BeginsWith, IBeginsWith, EndsWith and IEndsWith to the operati…

…on support list.
  • Loading branch information...
1 parent d84ce0f commit 31bc3cccd7225f740ee29eca922a44720d267634 @ctoestreich ctoestreich committed Nov 27, 2013
@@ -1,5 +1,5 @@
class FilterpaneGrailsPlugin {
- def version = "2.2.6"
+ def version = "2.3.0"
def grailsVersion = "1.3 > *"
def author = "Grails Plugin Consortium"
@@ -5,6 +5,10 @@ fp.op.Like=Contains (Case Sensitive)
fp.op.NotLike=Does Not Contain (Case Sensitive)
fp.op.Equal=Equal To
fp.op.NotEqual=Not Equal To
+fp.op.IBeginsWith=Begins With
+fp.op.BeginsWith=Begins With (Case Sensitive)
+fp.op.IEndsWith=Ends With
+fp.op.EndsWith=Ends With (Case Sensitive)
fp.op.IsNull=Is Null
fp.op.IsNotNull=Is Not Null
fp.op.GreaterThan=Greater Than
@@ -194,7 +194,9 @@ class FilterPaneService {
def criteriaMap = [(FilterPaneOperationType.Equal.operation): 'eq', (FilterPaneOperationType.NotEqual.operation): 'ne',
(FilterPaneOperationType.LessThan.operation): 'lt', (FilterPaneOperationType.LessThanEquals.operation): 'le',
(FilterPaneOperationType.GreaterThan.operation): 'gt', (FilterPaneOperationType.GreaterThanEquals.operation): 'ge',
- (FilterPaneOperationType.Like.operation): 'like', (FilterPaneOperationType.ILike.operation): 'ilike']
+ (FilterPaneOperationType.Like.operation): 'like', (FilterPaneOperationType.ILike.operation): 'ilike',
+ (FilterPaneOperationType.IBeginsWith.operation): 'ilike', (FilterPaneOperationType.BeginsWith.operation): 'like',
+ (FilterPaneOperationType.IEndsWith.operation): 'ilike', (FilterPaneOperationType.EndsWith.operation): 'like']
if(value != null) {
switch(op) {
@@ -216,6 +218,20 @@ class FilterPaneService {
}
criteria."${criteriaMap.get(op)}"(propertyName, value?.replaceAll("\\*", "%"))
break
+ case FilterPaneOperationType.BeginsWith.operation:
+ case FilterPaneOperationType.IBeginsWith.operation:
+ if(!value.endsWith('*')) {
+ value = "${value}*"
+ }
+ criteria."${criteriaMap.get(op)}"(propertyName, value?.replaceAll("\\*", "%"))
+ break
+ case FilterPaneOperationType.EndsWith.operation:
+ case FilterPaneOperationType.IEndsWith.operation:
+ if(!value.startsWith('*')) {
+ value = "*${value}"
+ }
+ criteria."${criteriaMap.get(op)}"(propertyName, value?.replaceAll("\\*", "%"))
+ break
case 'NotLike':
if(!value.startsWith('*')) {
value = "*${value}"
@@ -33,7 +33,9 @@ class FilterPaneTagLib {
text: ['', FilterPaneOperationType.ILike.operation, FilterPaneOperationType.NotILike.operation,
FilterPaneOperationType.Like.operation, FilterPaneOperationType.NotLike.operation,
FilterPaneOperationType.Equal.operation, FilterPaneOperationType.NotEqual.operation,
- FilterPaneOperationType.IsNull.operation, FilterPaneOperationType.IsNotNull.operation],
+ FilterPaneOperationType.IsNull.operation, FilterPaneOperationType.IsNotNull.operation,
+ FilterPaneOperationType.IBeginsWith.operation, FilterPaneOperationType.BeginsWith.operation,
+ FilterPaneOperationType.IEndsWith.operation, FilterPaneOperationType.EndsWith.operation],
numeric: ['', FilterPaneOperationType.Equal.operation, FilterPaneOperationType.NotEqual.operation,
FilterPaneOperationType.LessThan.operation, FilterPaneOperationType.LessThanEquals.operation,
FilterPaneOperationType.GreaterThan.operation,
@@ -583,6 +585,7 @@ class FilterPaneTagLib {
}
private void assignRenderModels(Map attrs, List sortedProps, ArrayList sortKeys, LinkedHashMap<String, Boolean> renderModel) {
+ //noinspection GroovyAssignabilityCheck
renderModel.sortModel = [sortValueMessagePrefix: attrs.sortValueMessagePrefix ?: null,
sortedProperties: sortedProps.collect { it.value },
sortKeys: sortKeys,
@@ -591,6 +594,7 @@ class FilterPaneTagLib {
orderAsc: params.order == 'asc',
orderDesc: params.order == 'desc']
+ //noinspection GroovyAssignabilityCheck
renderModel.buttonModel = [
cancelText: g.message(code: 'fp.tag.filterPane.button.cancel.text', default: 'Cancel'),
clearText: g.message(code: 'fp.tag.filterPane.button.clear.text', default: 'Clear'),
@@ -3,6 +3,7 @@ _(String, char)_
{table}
*Operator* | *Select Option Display Text*
ILike | Contains
+ILike | Begins With (Using no leading wild-card eg: ilike 'foo%')
Not ILike | Does Not Contain
Like | Contains (Case Sensitive)
Not Like | Does Not Contain (Case Sensitive)
@@ -21,6 +21,26 @@ Filtering all items by property firstName contains some text, requires that you
values="${[firstName:[op:'ILike', value:'Ada']]}"
{code}
+Filtering all items by property firstName beginning with some text (case sensitive), requires that you specify the operator. The same applies to all the other single argument operators of the filterpane see below.
+{code}
+values="${[firstName:[op:'BeginsWith', value:'Ada']]}"
+{code}
+
+Filtering all items by property firstName beginning with some text (case in-sensitive), requires that you specify the operator. The same applies to all the other single argument operators of the filterpane see below.
+{code}
+values="${[firstName:[op:'IBeginsWith', value:'Ada']]}"
+{code}
+
+Filtering all items by property firstName ending with some text (case sensitive), requires that you specify the operator. The same applies to all the other single argument operators of the filterpane see below.
+{code}
+values="${[firstName:[op:'EndsWith', value:'bert']]}"
+{code}
+
+Filtering all items by property firstName ending with some text (case in-sensitive), requires that you specify the operator. The same applies to all the other single argument operators of the filterpane see below.
+{code}
+values="${[firstName:[op:'IEndsWith', value:'bert']]}"
+{code}
+
Filtering all items by property age between 17 and 42.
{code}
values="${[age:[op:'Between', from:17, to:42]]}"
@@ -16,7 +16,11 @@ enum FilterPaneOperationType implements Serializable {
GreaterThanEquals('GreaterThanEquals'),
Between('Between'),
InList('InList'),
- NotInList('NotInList')
+ NotInList('NotInList'),
+ BeginsWith('BeginsWith'),
+ IBeginsWith('IBeginsWith'),
+ EndsWith('EndsWith'),
+ IEndsWith('IEndsWith')
String operation
@@ -170,8 +170,8 @@ class FilterPaneServiceSpec extends IntegrationSpec {
Book.list().size() == 2
books.size() == 2
books[0].authors.size() == 2
- books[0].authors.find {it.firstName == 'Cool'}
- books[0].authors.find {it.firstName == 'Another'}
+ books[0].authors.find { it.firstName == 'Cool' }
+ books[0].authors.find { it.firstName == 'Another' }
}
def "get author for book by association filter using listDistinct"() {
@@ -189,8 +189,8 @@ class FilterPaneServiceSpec extends IntegrationSpec {
Book.list().size() == 2
books.size() == 1
books[0].authors.size() == 2
- books[0].authors.find {it.firstName == 'Cool'}
- books[0].authors.find {it.firstName == 'Another'}
+ books[0].authors.find { it.firstName == 'Cool' }
+ books[0].authors.find { it.firstName == 'Another' }
}
def "test for empty params"() {
@@ -206,10 +206,146 @@ class FilterPaneServiceSpec extends IntegrationSpec {
then:
books.size() == 5
5.times {
- books.find {it.title == "Book ${it}"}
+ books.find { it.title == "Book ${it}" }
}
}
+ def "get author count for book by title using begins with"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'BeginsWith']], 'authors': ['lastName': 'Dude']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 1
+ }
+
+ def "get author count for book by title using begins with invalid case"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'BeginsWith']], 'authors': ['lastName': 'dude']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 0
+ }
+
+ def "get author count for book by title using begins with case insensitive"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'IBeginsWith']], 'authors': ['lastName': 'dude']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 1
+ }
+
+ def "get author count for book by title using begins with case insensitive caps"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'IBeginsWith']], 'authors': ['lastName': 'DUDE']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 1
+ }
+
+ def "get author count for book by title using ends with"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'EndsWith']], 'authors': ['lastName': 'Dude']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 1
+ }
+
+ def "get author count for book by title using ends with invalid case"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'EndsWith']], 'authors': ['lastName': 'dude']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 0
+ }
+
+ def "get author count for book by title using ends with case insensitive"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'IEndsWith']], 'authors': ['lastName': 'dude']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 1
+ }
+
+ def "get author count for book by title using ends with case insensitive caps"() {
+ given:
+ def params = ['filter': [op: ['authors': ['lastName': 'IEndsWith']], 'authors': ['lastName': 'DUDE']]]
+ Book.findOrSaveWhere(title: 'i hate bears')
+ Book.findOrSaveWhere(title: 'i hate zombies')
+ Book.findOrSaveWhere(title: 'i like turtles')
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Cool', lastName: 'Dude One'))
+ .addToAuthors(Author.findOrSaveWhere(firstName: 'Another', lastName: 'Another Dude'))
+
+ when:
+ def books = filterPaneService.count(params, Book)
+
+ then: 'count will be = number of authors in book since unique column not specified'
+ Book.list().size() == 3
+ books == 1
+ }
+
@Unroll
def "test all the operators filtering #operator #title"() {
given:
@@ -226,32 +362,47 @@ class FilterPaneServiceSpec extends IntegrationSpec {
books.size() == listCount
where:
- operator | title | listCount
- 'ILike' | 'BEARS*' | 2
- 'ILike' | '*ZOMBIES' | 1
- 'ILike' | '*zombies' | 1
- 'Like' | 'turtles' | 2
- 'Like' | '*turtles' | 2
- 'Like' | '*turtles*' | 2
- 'Like' | 'TURTLES' | 0
- 'Like' | '*TURTLES' | 0
- 'Like' | '*TURTLES*' | 0
- 'Like' | 'i like zombies' | 1
- 'Like' | '*LIKE*' | 0
- 'Like' | '*like*' | 3
- 'Equal' | 'like' | 0
- 'Equal' | 'i like zombies' | 1
- 'Equal' | 'I LIKE ZOMBIES' | 0
- 'NotEqual' | 'i like zombies' | 2
- 'NotEqual' | 'zombies' | 3
- 'NotLike' | 'zombies' | 2
- 'NotLike' | '*zombies' | 2
- 'NotLike' | '*like*' | 0
- 'NotILike' | '*turtles*' | 1
- 'NotILike' | '*TURTLES*' | 1
- 'NotILike' | '*ZOMBIES' | 2
- 'IsNull' | 'unused' | 1
- 'IsNotNull' | 'unused' | 3
+ operator | title | listCount
+ 'ILike' | 'BEARS*' | 2
+ 'ILike' | '*ZOMBIES' | 1
+ 'ILike' | '*zombies' | 1
+ 'Like' | 'turtles' | 2
+ 'Like' | '*turtles' | 2
+ 'Like' | '*turtles*' | 2
+ 'Like' | 'TURTLES' | 0
+ 'Like' | '*TURTLES' | 0
+ 'Like' | '*TURTLES*' | 0
+ 'Like' | 'i like zombies' | 1
+ 'Like' | '*LIKE*' | 0
+ 'Like' | '*like*' | 3
+ 'Equal' | 'like' | 0
+ 'Equal' | 'i like zombies' | 1
+ 'Equal' | 'I LIKE ZOMBIES' | 0
+ 'NotEqual' | 'i like zombies' | 2
+ 'NotEqual' | 'zombies' | 3
+ 'NotLike' | 'zombies' | 2
+ 'NotLike' | '*zombies' | 2
+ 'NotLike' | '*like*' | 0
+ 'NotILike' | '*turtles*' | 1
+ 'NotILike' | '*TURTLES*' | 1
+ 'NotILike' | '*ZOMBIES' | 2
+ 'IsNull' | 'unused' | 1
+ 'BeginsWith' | 'i like' | 3
+ 'BeginsWith' | 'I LIKE' | 0
+ 'BeginsWith' | 'like' | 0
+ 'BeginsWith' | 'LIKE' | 0
+ 'IBeginsWith' | 'i like' | 3
+ 'IBeginsWith' | 'I LIKE' | 3
+ 'IBeginsWith' | 'like' | 0
+ 'IBeginsWith' | 'LIKE' | 0
+ 'EndsWith' | 'rabbits' | 2
+ 'EndsWith' | 'RABBITS' | 0
+ 'EndsWith' | 'like' | 0
+ 'EndsWith' | 'LIKE' | 0
+ 'IEndsWith' | 'rabbits' | 2
+ 'IEndsWith' | 'RABBITS' | 2
+ 'IEndsWith' | 'like' | 0
+ 'IEndsWith' | 'LIKE' | 0
}
@@ -285,9 +436,9 @@ class FilterPaneServiceSpec extends IntegrationSpec {
then:
Book.list().size() == 3
books.size() == 2
- books.findAll{it.bookType == BookType.Fiction}.size() == 0
- books.findAll{it.bookType == BookType.Reference}.size() == 1
- books.findAll{it.bookType == BookType.NonFiction}.size() == 1
+ books.findAll { it.bookType == BookType.Fiction }.size() == 0
+ books.findAll { it.bookType == BookType.Reference }.size() == 1
+ books.findAll { it.bookType == BookType.NonFiction }.size() == 1
}
def "get book by multiple bookType InList"() {
@@ -303,9 +454,9 @@ class FilterPaneServiceSpec extends IntegrationSpec {
then:
Book.list().size() == 3
books.size() == 2
- books.findAll{it.bookType == BookType.Fiction}.size() == 1
- books.findAll{it.bookType == BookType.Reference}.size() == 0
- books.findAll{it.bookType == BookType.NonFiction}.size() == 1
+ books.findAll { it.bookType == BookType.Fiction }.size() == 1
+ books.findAll { it.bookType == BookType.Reference }.size() == 0
+ books.findAll { it.bookType == BookType.NonFiction }.size() == 1
}
def "get book by multiple bookType NotInList"() {
Oops, something went wrong.

0 comments on commit 31bc3cc

Please sign in to comment.