Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

300-Allow-the-MDLTableWidget-to-be-paginated #304

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Material-Design-Lite-Demo/MDLDemoLibrary.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ I contain all the pictures and stylesheets usefull for the demo
Class {
#name : #MDLDemoLibrary,
#superclass : #WAFileLibrary,
#category : #'Material-Design-Lite-Demo-Core'
#category : 'Material-Design-Lite-Demo-Core'
}

{ #category : #uploaded }
Expand Down
17 changes: 17 additions & 0 deletions src/Material-Design-Lite-Demo/MDLTableWidgetScreen.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ MDLTableWidgetScreen class >> title [
^ 'Table widget'
]

{ #category : #accessing }
MDLTableWidgetScreen >> renderPaginatedTableWidgetOn: html [
html
render:
(MDLTableWidget new
addNumericColumnNamed: 'Integer' evaluated: #yourself;
addStringColumnNamed: 'String with commas' evaluated: [ :x | x asStringWithCommas ];
addStringColumnNamed: 'As words' evaluated: [ :x | x asWords capitalized ];
addAjaxButtonColumnWithIconName: 'explore'
onClick: [ :htmlCanvas :x | htmlCanvas javascript alert: 'Explore ' , x asString ]
tooltip: 'Explore integer related to the row.';
collection: (1000 to: 5000 by: 100);
bePaginated;
yourself)
]

{ #category : #rendering }
MDLTableWidgetScreen >> renderScreenContentOn: html [
self render: self table on: html
Expand Down Expand Up @@ -48,5 +64,6 @@ MDLTableWidgetScreen >> renderTableWidgetOn: html [
MDLTableWidgetScreen >> table [
^ OrderedDictionary new
add: 'Table Widget' -> #renderTableWidgetOn:;
add: 'Paginated table widget' -> #renderPaginatedTableWidgetOn:;
yourself
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
"
A MDLDisplayPaginatedTableContentTest is a test class for testing the behavior of MDLDisplayPaginatedTableContent
"
Class {
#name : #MDLDisplayPaginatedTableContentTest,
#superclass : #SGTAbstractSeasideTestCase,
#category : #'Material-Design-Lite-Widgets-Tests-Table'
}

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testIndexOfLastRowToShow [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

self assert: contentDisplayStrategy rowsPerPage equals: 5.
self assert: contentDisplayStrategy indexOfLastRowToShow equals: 5.

contentDisplayStrategy rowsPerPage: 10.

self assert: contentDisplayStrategy rowsPerPage equals: 10.
self assert: contentDisplayStrategy indexOfLastRowToShow equals: 10.

]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testInitialize [
| contentDisplayStrategy |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.

self assert: contentDisplayStrategy position equals: contentDisplayStrategy initialPosition.
self assert: contentDisplayStrategy rowsPerPagePossibilities equals: contentDisplayStrategy defaultRowsPerPagePossibilities
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testIsAtEnd [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

self assert: contentDisplayStrategy position equals: contentDisplayStrategy initialPosition.
contentDisplayStrategy rowsPerPage: 50.

self deny: contentDisplayStrategy isAtEnd.
self assert: contentDisplayStrategy position equals: contentDisplayStrategy initialPosition.

contentDisplayStrategy nextPosition.

self assert: contentDisplayStrategy isAtEnd.
self assert: contentDisplayStrategy position equals: 51.

"Do not move if we call #nextPosition again."
contentDisplayStrategy nextPosition.

self assert: contentDisplayStrategy isAtEnd.
self assert: contentDisplayStrategy position equals: 51.
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testNextPosition [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

self assert: contentDisplayStrategy position equals: contentDisplayStrategy initialPosition.
self assert: contentDisplayStrategy rowsPerPage equals: 5.

contentDisplayStrategy nextPosition.

self assert: contentDisplayStrategy position equals: 6.

contentDisplayStrategy nextPosition.

self assert: contentDisplayStrategy position equals: 11.
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testNextPosition2 [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

self assert: contentDisplayStrategy position equals: contentDisplayStrategy initialPosition.
contentDisplayStrategy rowsPerPage: 10.

contentDisplayStrategy nextPosition.

self assert: contentDisplayStrategy position equals: 11.

contentDisplayStrategy nextPosition.

self assert: contentDisplayStrategy position equals: 21.
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testPreviousPosition [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.
contentDisplayStrategy rowsPerPage: 10.
contentDisplayStrategy position: 91.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 81.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 71.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 61.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 51.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 41.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 31.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 21.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 11.

contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 1.

"Check it does nothing once we reached beginning of collection."
contentDisplayStrategy previousPosition.
self assert: contentDisplayStrategy position equals: 1.
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testRenderPagesInfoOn [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.
self
assert: [ :html | contentDisplayStrategy renderPagesInfoOn: html ]
generates: '1 - 5 of 100'.

contentDisplayStrategy nextPosition.

self
assert: [ :html | contentDisplayStrategy renderPagesInfoOn: html ]
generates: '6 - 10 of 100'.
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testRenderPagesInfoOn2 [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

contentDisplayStrategy rowsPerPage: 10.

self
assert: [ :html | contentDisplayStrategy renderPagesInfoOn: html ]
generates: '1 - 10 of 100'.

contentDisplayStrategy nextPosition.

self
assert: [ :html | contentDisplayStrategy renderPagesInfoOn: html ]
generates: '11 - 20 of 100'.
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testRowsPerPage [
| contentDisplayStrategy |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.

self assert: contentDisplayStrategy rowsPerPage equals: contentDisplayStrategy rowsPerPagePossibilities first
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testRowsPerPageRowsPerPagePossibilitiesIsEmpty [
| contentDisplayStrategy |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.

contentDisplayStrategy rowsPerPagePossibilities: #().

self
should: [ contentDisplayStrategy rowsPerPage ]
raise: Error
withExceptionDo: [ :ex | self assert: ex messageText equals: '#rowsPerPagePossibilities is empty' ]
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testRowsToDisplayDo [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

self assertCollection: (Array streamContents: [ :stream | contentDisplayStrategy rowsToDisplayDo: [ :i | stream nextPut: i ] ]) equals: #(1 2 3 4 5).

contentDisplayStrategy nextPosition.

self assertCollection: (Array streamContents: [ :stream | contentDisplayStrategy rowsToDisplayDo: [ :i | stream nextPut: i ] ]) equals: #(6 7 8 9 10).
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testRowsToDisplayDo2 [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

contentDisplayStrategy rowsPerPage: 10.

self assertCollection: (Array streamContents: [ :stream | contentDisplayStrategy rowsToDisplayDo: [ :i | stream nextPut: i ] ]) equals: #(1 2 3 4 5 6 7 8 9 10).

contentDisplayStrategy nextPosition.

self assertCollection: (Array streamContents: [ :stream | contentDisplayStrategy rowsToDisplayDo: [ :i | stream nextPut: i ] ]) equals: #(11 12 13 14 15 16 17 18 19 20).
]

{ #category : #test }
MDLDisplayPaginatedTableContentTest >> testTotalNumberOfRows [
| contentDisplayStrategy table |
contentDisplayStrategy := MDLDisplayPaginatedTableContent new.
table := MDLTableWidget new
contentDisplayStrategy: contentDisplayStrategy;
collection: (1 to: 100) asArray;
yourself.

self assert: contentDisplayStrategy totalNumberOfRows equals: table collection size.
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"
I am a simple strategy displaying the full content of the table.

I have not footer to display.
"
Class {
#name : #MDLDisplayFullTableContent,
#superclass : #MDLTableContentDisplayStrategy,
#category : #'Material-Design-Lite-Widgets-Table'
}

{ #category : #rendering }
MDLDisplayFullTableContent >> renderContentOn: html [
html tableBody
class: 'mdl-table-widget__body';
with: [
self tableWidget collection do: [ :row |
html tableRow: [
self tableWidget columnDescriptions do: [ :columnDescription |
columnDescription render: row on: html ] ] ] ]
]

{ #category : #rendering }
MDLDisplayFullTableContent >> renderFooterOn: html [
"Nothing to render here."
]
Loading