Skip to content

Commit 4ebe79f

Browse files
author
Marvin Kuhn
committed
added new limit option to list prototype
1 parent 84d4757 commit 4ebe79f

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This package is heavily inspired by [Flowpack.Listable](https://github.com/Flowp
1111
## Installation
1212
Most of the time you have to make small adjustments to a package (e.g., the configuration in Settings.yaml). Because of that, it is important to add the corresponding package to the composer from your theme package. Mostly this is the site package located under Packages/Sites/. To install it correctly go to your theme package (e.g.Packages/Sites/Foo.Bar) and run following command:
1313

14+
*Important*: If you use a Neos Version >5 you should require version 1 of this package.
15+
1416
```bash
1517
composer require breadlesscode/neos-listable --no-update
1618
```
@@ -21,7 +23,7 @@ The --no-update command prevent the automatic update of the dependencies. After
2123
```
2224
prototype(Vendor.Xy:MyPersonalList) < prototype(Breadlesscode.Listable:List) {
2325
collection = ${ q(site).find('[instanceof Vendor.Xy:BlogPost]') }
24-
itemsPerPage = ${ 10 }
26+
limit = ${ 10 }
2527
itemRenderer = 'Vendor.Xy:MyPersonalListItem'
2628
itemName = ${ 'item' }
2729
# if you want no pagination you can set this property:

Resources/Private/Fusion/Component/Collection.fusion

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
prototype(Breadlesscode.Listable:Collection) < prototype(Neos.Fusion:Component) {
22
collection = ${ [] }
33
currentPage = ${ 1 }
4-
itemsPerPage= ${ 15 }
4+
limit = ${ 15 }
55
paginate = ${ false }
66

7-
@context.limit = ${ this.currentPage * this.itemsPerPage }
8-
@context.offset = ${ (this.currentPage - 1) * this.itemsPerPage }
7+
@context.limit = ${ this.currentPage * this.limit }
8+
@context.offset = ${ (this.currentPage - 1) * this.limit }
99

1010
renderer = Neos.Fusion:Case {
1111
# elastic search pagination implementation
@@ -15,7 +15,12 @@ prototype(Breadlesscode.Listable:Collection) < prototype(Neos.Fusion:Component)
1515
renderer.@process {
1616
limitAndOffset = ${ value.limit(limit).from(offset) }
1717
[email protected] = ${ props.paginate }
18-
execute = ${ value.execute() }
18+
19+
limits = ${ value.limit(limit) }
20+
[email protected] = ${ !props.paginate && limit >= 1 }
21+
22+
execute = ${ value }
23+
executee = ${ value.execute() }
1924
}
2025
}
2126
# default flow query and array implementaion
@@ -25,6 +30,10 @@ prototype(Breadlesscode.Listable:Collection) < prototype(Neos.Fusion:Component)
2530
renderer.@process {
2631
slice = ${ value.slice(offset, limit) }
2732
[email protected] = ${ props.paginate }
33+
34+
limits = ${ value.limit(0, limit) }
35+
[email protected] = ${ !props.paginate && limit >= 1 }
36+
2837
execute = ${ value.get() }
2938
}
3039
}

Resources/Private/Fusion/Component/List.fusion

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
prototype(Breadlesscode.Listable:List) < prototype(Neos.Fusion:Component) {
22
collection = ${ [] }
3-
itemsPerPage = ${ 10 }
3+
limit = ${ 10 }
44
itemRenderer = 'Breadlesscode.Listable:ListItem'
55
itemName = ${ 'item' }
66
paginated = ${ true }
77
paginationConfig = Breadlesscode.Listable:PaginationConfig
88

99
@context.currentPage = ${ request.arguments.currentPage || 1 }
1010

11-
renderer = Neos.Fusion:Array {
11+
renderer = Neos.Fusion:Join {
1212
@context.collection = Neos.Fusion:RawArray {
1313
items = Breadlesscode.Listable:Collection {
1414
collection = ${ props.collection }
1515
currentPage = ${ currentPage }
16-
itemsPerPage= ${ props.itemsPerPage }
16+
limit = ${ props.limit }
1717
paginate = ${ props.paginated }
1818
}
1919
totalCount = ${ Type.getType(props.collection) == 'array' ? q(props.collection).count() : props.collection.count() }
@@ -29,7 +29,7 @@ prototype(Breadlesscode.Listable:List) < prototype(Neos.Fusion:Component) {
2929
currentPage = ${ currentPage }
3030
maximumNumberOfLinks = ${ 3 }
3131
totalCount = ${ collection.totalCount }
32-
itemsPerPage = ${ props.itemsPerPage }
32+
itemsPerPage = ${ props.limit }
3333
paginationConfig = ${ props.paginationConfig }
3434

3535
@if.shouldPaginate = ${ props.paginated }

0 commit comments

Comments
 (0)