Skip to content

Commit

Permalink
Merge pull request #318 from DuneSt/feat/allow-override-filter
Browse files Browse the repository at this point in the history
feat: allow override filter to work on specific collection
  • Loading branch information
LesageYann authored Dec 1, 2021
2 parents 374d738 + e58f7e9 commit d8227c6
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/Material-Design-Lite-Widgets/Collection.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : #Collection }

{ #category : #'*Material-Design-Lite-Widgets' }
Collection >> selectMatchingFromMDLFilter: mdlFilter format: aFormatBlock with: aPattern [
^ self
select: [ :each |
mdlFilter
formatedElement: (aFormatBlock value: each)
matches: aPattern ]
]
10 changes: 9 additions & 1 deletion src/Material-Design-Lite-Widgets/MDLAbstractFilter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ MDLAbstractFilter class >> isAbstract [
MDLAbstractFilter class >> selectMatchingFrom: aCollection format: aFormatBlock with: aPattern [
"I take as parameter a collection of elements to match, a block to get the readable format of the element and a pattern and I should return a collection of elements matching the pattern in their readable format."

^ aCollection select: [ :each | self formatedElement: (aFormatBlock value: each) matches: aPattern ]
^ aCollection selectMatchingFromMDLFilter: self format: aFormatBlock with: aPattern
]

{ #category : #accessing }
MDLAbstractFilter class >> selectMatchingOnQueryCollection: aQueryCollection with: aFormatBlock like: aPattern [
|newQuery|
newQuery := aQueryCollection copy.
self applySelectMatchingOnQueryCollection: newQuery with: aFormatBlock like: aPattern.
^ newQuery
]
10 changes: 9 additions & 1 deletion src/Material-Design-Lite-Widgets/MDLBeginsWithFilter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ I am a nested list filter keeping only elements whose name begins with the patte
Class {
#name : #MDLBeginsWithFilter,
#superclass : #MDLAbstractFilter,
#category : 'Material-Design-Lite-Widgets-List'
#category : #'Material-Design-Lite-Widgets-List'
}

{ #category : #accessing }
MDLBeginsWithFilter class >> applySelectMatchingOnQueryCollection: aQueryCollection with: aFormatBlock like: aPattern [

^ aQueryCollection wrappedQuery
with: aFormatBlock
like: aPattern , '%'
]

{ #category : #accessing }
MDLBeginsWithFilter class >> formatedElement: aString matches: aPattern [
^ aString beginsWith: aPattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ I am a nested list filter keeping only elements whose name begins with the patte
Class {
#name : #MDLInsensitiveBeginsWithFilter,
#superclass : #MDLAbstractFilter,
#category : 'Material-Design-Lite-Widgets-List'
#category : #'Material-Design-Lite-Widgets-List'
}

{ #category : #accessing }
MDLInsensitiveBeginsWithFilter class >> applySelectMatchingOnQueryCollection: aQueryCollection with: aFormatBlock like: aPattern [
^ aQueryCollection wrappedQuery
with: aFormatBlock
ilike: aPattern , '%'
]

{ #category : #accessing }
MDLInsensitiveBeginsWithFilter class >> formatedElement: aString matches: aPattern [
^ aString asLowercase beginsWith: aPattern asLowercase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ I am a nested list filter keeping only elements whose name includes the pattern
Class {
#name : #MDLInsensitiveSubstringFilter,
#superclass : #MDLAbstractFilter,
#category : 'Material-Design-Lite-Widgets-List'
#category : #'Material-Design-Lite-Widgets-List'
}

{ #category : #accessing }
MDLInsensitiveSubstringFilter class >> applySelectMatchingOnQueryCollection: aQueryCollection with: aFormatBlock like: aPattern [
^ aQueryCollection wrappedQuery
with: aFormatBlock
iLike: '%' , aPattern asLowercase , '%'
]

{ #category : #accessing }
MDLInsensitiveSubstringFilter class >> formatedElement: aString matches: aPattern [
^ aString asLowercase includesSubstring: aPattern asLowercase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ MDLNestedListItemRenderAbstractStrategy >> renderIcon: aBlock Of: anItem on: htm
{ #category : #rendering }
MDLNestedListItemRenderAbstractStrategy >> renderItem: aNode index: anIndex inDiv: div indentedBy: anInteger on: html [
| htmlElement |
htmlElement := self getHtmlElementForNode: aNode inDiv: div index: anIndex indentedBy: anInteger on: html.
htmlElement := self
getHtmlElementForNode: aNode
inDiv: div
index: anIndex
indentedBy: anInteger
on: html.
htmlElement
with: [ html span
class: #item;
id: html nextId;
with: ((self format value: aNode element) ifEmpty: [ $  ]).
with: (((self format value: aNode element) ifNil: [ '' ]) ifEmpty: [ $  ]).
self renderHelpOf: aNode element at: html lastId on: html ].
aNode children
ifNotEmpty: [ html div
Expand Down
14 changes: 10 additions & 4 deletions src/Material-Design-Lite-Widgets/MDLPseudoRegexFilter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ I am a nested list filter keeping only elements whose name includes the pattern
Class {
#name : #MDLPseudoRegexFilter,
#superclass : #MDLAbstractFilter,
#category : 'Material-Design-Lite-Widgets-List'
#category : #'Material-Design-Lite-Widgets-List'
}

{ #category : #accessing }
Expand All @@ -18,14 +18,20 @@ MDLPseudoRegexFilter class >> adaptPattern: aPattern [
ifFalse: [ s nextPutAll: '.*' ] ]
]

{ #category : #accessing }
MDLPseudoRegexFilter class >> applySelectMatchingOnQueryCollection: aQueryCollection with: aFormatBlock like: aPattern [
self shouldBeImplemented.
]

{ #category : #accessing }
MDLPseudoRegexFilter class >> formatedElement: aString matches: aRegex [
^ aRegex matches: aString
]

{ #category : #accessing }
MDLPseudoRegexFilter class >> selectMatchingFrom: aCollection format: aFormatBlock with: aPattern [
| regex |
regex := (self adaptPattern: aPattern) asRegexIgnoringCase.
^ aCollection select: [ :each | self formatedElement: (aFormatBlock value: each) matches: regex ]
^ super
selectMatchingFrom: aCollection
format: aFormatBlock
with: (self adaptPattern: aPattern) asRegexIgnoringCase
]
9 changes: 8 additions & 1 deletion src/Material-Design-Lite-Widgets/MDLSubstringFilter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ I am a nested list filter keeping only elements whose name includes the pattern
Class {
#name : #MDLSubstringFilter,
#superclass : #MDLAbstractFilter,
#category : 'Material-Design-Lite-Widgets-List'
#category : #'Material-Design-Lite-Widgets-List'
}

{ #category : #accessing }
MDLSubstringFilter class >> applySelectMatchingOnQueryCollection: aQueryCollection with: aFormatBlock like: aPattern [
^ aQueryCollection wrappedQuery
with: aFormatBlock
like: '%', aPattern , '%'
]

{ #category : #accessing }
MDLSubstringFilter class >> formatedElement: aString matches: aPattern [
^ aString includesSubstring: aPattern
Expand Down

0 comments on commit d8227c6

Please sign in to comment.