Skip to content

Commit

Permalink
refactor filter widget creation to `GtPharoStreamingMethodsFiltersEle…
Browse files Browse the repository at this point in the history
…mentStencil` [feenkcom/gtoolkit#3983]
  • Loading branch information
JurajKubelka committed Sep 27, 2024
1 parent a5e00e7 commit 9f7eb2c
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #GtFilterItemsElement }

{ #category : #'*GToolkit-Pharo-Coder-Method-UI' }
GtFilterItemsElement >> filterUpdater [
^ GtPharoStreamingMethodsFiltersElementFromModelStencil new
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #GtFiltersElement }

{ #category : #'*GToolkit-Pharo-Coder-Method-UI' }
GtFiltersElement >> filterUpdater [
^ GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil new
]
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,9 @@ GtPharoStreamingMethodsCoderElement >> asScrollableElement [

{ #category : #'instance creation' }
GtPharoStreamingMethodsCoderElement >> buildFilter [
| filterElement filterDescriptors |
filterDescriptors := streamingCodersViewModel streamingCodersModel
filterDescriptors.
filterDescriptors isEmpty ifTrue: [ ^ self ].
filterElement := GtFiltersElement new
padding: (BlInsets all: 2);
descriptors: filterDescriptors;
yourself.
filterElement
buildFilters: [ streamingCodersViewModel streamingCodersModel additionalFilters
do: [ :each |
(each class filterDescriptorFor: streamingCodersViewModel streamingCodersModel)
ifNotNil: [ :descriptor |
| label |
label := descriptor valueIsRequired ifTrue: [ each filterValueString ].
filterElement addFilterForDescriptor: descriptor andValue: label ] ] ].
filterElement
when: GtFiltersChangedEvent
do: [ :event | self updateCodersFilters: event ].
^ filterElement
^ GtPharoStreamingMethodsFiltersElementStencil defaultStencil
streamingCodersViewModel: streamingCodersViewModel;
asElement.
]

{ #category : #'instance creation' }
Expand Down Expand Up @@ -167,18 +150,9 @@ GtPharoStreamingMethodsCoderElement >> onFilterChanged: anAnnouncement [
self
childWithId: #filter
ifFound: [ :aFiltersElement |
aFiltersElement
buildFilters: [
streamingCodersViewModel additionalFilters do: [ :each |
(each filterDescriptorFor: streamingCodersViewModel streamingCodersModel)
ifNotNil: [ :descriptor |
| label |
label := descriptor valueIsRequired
ifTrue: [ each filterValueString ].

aFiltersElement
addFilterForDescriptor: descriptor
andValue: label ] ] ] ]
aFiltersElement filterUpdater
streamingCodersViewModel: streamingCodersViewModel;
updateFiltersElement: aFiltersElement ]
ifNone: [ ]
]

Expand Down Expand Up @@ -270,7 +244,7 @@ GtPharoStreamingMethodsCoderElement >> unsubscribeFromStreamingCodersViewModel [
{ #category : #'private - update' }
GtPharoStreamingMethodsCoderElement >> updateCodersFilters: anEvent [
| filters |

self flag: 'Can be deleted since it is moved to GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil>>#updateCodersFilters:'.
filters := OrderedCollection new.

anEvent filterElement filtersDo: [ :descriptor :value |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Class {
#name : #GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil,
#superclass : #GtPharoStreamingMethodsFiltersElementStencil,
#category : #'GToolkit-Pharo-Coder-Method-UI-Support'
}

{ #category : #'api - instantiation' }
GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> create [
<return: #GtFiltersElement>
| aFilterDescriptors aFiltersElement |
self
assert: [ streamingCodersViewModel isNotNil ]
description: [ 'Streaming coders view model must be initialized' ].

aFilterDescriptors := streamingCodersViewModel streamingCodersModel
filterDescriptors.

aFiltersElement := GtFiltersElement new
padding: (BlInsets all: 2);
descriptors: aFilterDescriptors;
yourself.
self updateFiltersElement: aFiltersElement.
aFiltersElement
when: GtFiltersChangedEvent
do: [ :anEvent | self updateCodersFilters: anEvent ].

^ aFiltersElement
]

{ #category : #'event handling' }
GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> updateCodersFilters: anEvent [
| filters |

filters := OrderedCollection new.

anEvent filterElement filtersDo: [ :descriptor :value |
filters add: (descriptor newFilterWithValue: value) ].

streamingCodersViewModel streamingCodersModel additionalFilters: filters
]

{ #category : #'api - updating' }
GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil >> updateFiltersElement: aFiltersElement [
self
assert: [ aFiltersElement isKindOf: GtFiltersElement ]
description: [ '{1} must be kind of {2}'
format: {aFiltersElement.
GtFiltersElement} ].
self
assert: [ streamingCodersViewModel isNotNil ]
description: [ 'Streaming coders view model must be initialized' ].

aFiltersElement
buildFilters: [ streamingCodersViewModel streamingCodersModel additionalFilters
do: [ :eachFilter |
(eachFilter class filterDescriptorFor: streamingCodersViewModel streamingCodersModel)
ifNotNil: [ :aDescriptor |
| aLabel |
aLabel := aDescriptor valueIsRequired ifTrue: [ eachFilter filterValueString ].
aFiltersElement addFilterForDescriptor: aDescriptor andValue: aLabel ] ] ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Class {
#name : #GtPharoStreamingMethodsFiltersElementFromModelStencil,
#superclass : #GtPharoStreamingMethodsFiltersElementStencil,
#category : #'GToolkit-Pharo-Coder-Method-UI-Support'
}

{ #category : #'api - instantiation' }
GtPharoStreamingMethodsFiltersElementFromModelStencil >> create [
| aModel aMethodsCoder aBuilder anUpdater aFiltersElement |
aModel := GtFilterItemsModel new.
aFiltersElement := aModel asFiltersElement.
aMethodsCoder := streamingCodersViewModel streamingCodersModel.
self updateFiltersElement: aFiltersElement.
aBuilder := GtFilterMethodsCoderAvailableFiltersBuilder new
coders: aMethodsCoder.
aModel availableFiltersBuilder: aBuilder.
anUpdater := GtFilterMethodCodersAdditionalFiltersUpdater new
coders: aMethodsCoder;
filtersModel: aModel.
aModel weak
when: GtFiltersModelUpdated
send: #onFiltersUpdated:
to: anUpdater.
aFiltersElement userData at: GtFilterMethodCodersAdditionalFiltersUpdater put: anUpdater.

^ aFiltersElement
]

{ #category : #'api - updating' }
GtPharoStreamingMethodsFiltersElementFromModelStencil >> updateFiltersElement: aFiltersElement [
| aFiltersModel someFilterModels |
self
assert: [ streamingCodersViewModel isNotNil ]
description: [ 'Streaming coders view model must be initialized' ].

aFiltersElement hasFiltersViewModel ifFalse: [ ^ self ].
aFiltersModel := aFiltersElement filtersViewModel filtersModel.

"aFiltersModel items ifNotEmpty: [ ^ self ]."

someFilterModels := streamingCodersViewModel streamingCodersModel
additionalFilters
collect: [ :eachFilter |
eachFilter class
filterDescriptor2For: streamingCodersViewModel streamingCodersModel ]
thenReject: #isNil.

aFiltersModel items: someFilterModels.
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Class {
#name : #GtPharoStreamingMethodsFiltersElementStencil,
#superclass : #BrStencil,
#instVars : [
'streamingCodersViewModel'
],
#classVars : [
'DefaultBuilderClass'
],
#category : #'GToolkit-Pharo-Coder-Method-UI-Support'
}

{ #category : #defaults }
GtPharoStreamingMethodsFiltersElementStencil class >> beDescriptorsStencilDefault [
DefaultBuilderClass := GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil
]

{ #category : #defaults }
GtPharoStreamingMethodsFiltersElementStencil class >> beModelStencilDefault [
DefaultBuilderClass := GtPharoStreamingMethodsFiltersElementFromModelStencil
]

{ #category : #defaults }
GtPharoStreamingMethodsFiltersElementStencil class >> defaultStencil [
^ self defaultStencilClass new
]

{ #category : #defaults }
GtPharoStreamingMethodsFiltersElementStencil class >> defaultStencilClass [
^ DefaultBuilderClass
ifNil: [ DefaultBuilderClass := GtPharoStreamingMethodsFiltersElementFromDescriptorsStencil ]
]

{ #category : #accessing }
GtPharoStreamingMethodsFiltersElementStencil >> streamingCodersViewModel [
^ streamingCodersViewModel
]

{ #category : #accessing }
GtPharoStreamingMethodsFiltersElementStencil >> streamingCodersViewModel: aViewModel [
self
assert: [ aViewModel isNotNil ]
description: [ 'Streaming coders view model must be non-nil' ].
self
assert: [ streamingCodersViewModel isNil ]
description: [ 'Streaming coders view model can be set only once' ].

streamingCodersViewModel := aViewModel
]

{ #category : #'api - updating' }
GtPharoStreamingMethodsFiltersElementStencil >> updateFiltersElement: aFilterElement [
self subclassResponsibility
]

0 comments on commit 9f7eb2c

Please sign in to comment.