Skip to content

Commit 8843891

Browse files
author
Nils Henning
committed
[TASK] update collection guide
1 parent dfe08cc commit 8843891

File tree

3 files changed

+85
-22
lines changed

3 files changed

+85
-22
lines changed

docs/api/100-components/collection.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,13 @@ class Pages::MyApp::Collection < Matestack::Ui::Page
114114
end
115115

116116
def response
117-
heading size: 2, text: "My Collection"
117+
heading size: 2, text: "My Collection"
118118

119-
filter
119+
filter
120120

121-
async rerender_on: "my-first-collection-update", id: "my-collection-content" do
122-
content
123-
end
124-
}
121+
async rerender_on: "my-first-collection-update", id: "my-collection-content" do
122+
content
123+
end
125124
end
126125

127126
def filter
@@ -210,16 +209,14 @@ class Pages::MyApp::Collection < Matestack::Ui::Page
210209
end
211210

212211
def response
213-
components {
214-
heading size: 2, text: "My Collection"
212+
heading size: 2, text: "My Collection"
215213

216-
filter
217-
ordering
214+
filter
215+
ordering
218216

219-
async rerender_on: "my-first-collection-update", id: "my-collection-content" do
220-
content
221-
end
222-
}
217+
async rerender_on: "my-first-collection-update", id: "my-collection-content" do
218+
content
219+
end
223220
end
224221

225222
def filter

docs/guides/800-isolated/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ Isolated components are wrapped in a special html structure allowing you to crea
148148

149149
## Complete documentation
150150

151-
If you want to know all details about isolated components checkout its [api documentation](/docs/api/000-base/40-isolated_component.md).
151+
If you want to know all details about isolated components checkout their [base api documentation](/docs/api/000-base/40-isolated_component.md).

docs/guides/900-collection/README.md

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
2323
end
2424

2525
def response
26-
async id: 'product-collection', rerender_on: 'product-collection-udpate' do
26+
async id: 'product-collection', rerender_on: "#{@collection_id}-udpate" do
2727
collection_content @collection.config do
2828
@collection.paginated_data.each do |product|
2929
paragraph text: product.name
@@ -59,7 +59,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
5959
end
6060

6161
def response
62-
async id: 'product-collection', rerender_on: 'product-collection-udpate' do
62+
async id: 'product-collection', rerender_on: "#{@collection_id}-udpate" do
6363
collection_content @collection.config do
6464
@collection.paginated_data.each do |product|
6565
paragraph text: product.name
@@ -72,8 +72,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
7272
def pagination
7373
plain "showing #{@my_collection.from}"
7474
plain "to #{@my_collection.to}"
75-
plain "of #{@my_collection.filtered_count}"
76-
plain "from total #{@my_collection.base_count}"
75+
plain "of #{@my_collection.base_count}"
7776
collection_content_previous do
7877
button text: "previous"
7978
end
@@ -119,7 +118,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
119118

120119
def response
121120
filter
122-
async id: 'product-collection', rerender_on: 'product-collection-udpate' do
121+
async id: 'product-collection', rerender_on: "#{@collection_id}-udpate" do
123122
collection_content @collection.config do
124123
@collection.paginated_data.each do |product|
125124
paragraph text: product.name
@@ -141,7 +140,22 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
141140
end
142141
end
143142

144-
#...
143+
def pagination
144+
plain "showing #{@my_collection.from}"
145+
plain "to #{@my_collection.to}"
146+
plain "of #{@my_collection.base_count}"
147+
collection_content_previous do
148+
button text: "previous"
149+
end
150+
@my_collection.pages.each do |page|
151+
collection_content_page_link page: page do
152+
button text: page
153+
end
154+
end
155+
collection_content_next do
156+
button text: "next"
157+
end
158+
end
145159

146160
end
147161
```
@@ -151,4 +165,56 @@ That's it. Now we can filter our collection by product name.
151165

152166
### Ordering
153167

154-
![Coming Soon](../../images/coming_soon.png)
168+
Ordering a collection can be achieved by using the `collection_order_toggle` helper along with `get_collection_order` to receive the selected order.
169+
170+
```ruby
171+
class Shop::Pages::Products::Index < Matestack::Ui::Page
172+
include Matestack::Ui::Core::Collection::Helper
173+
174+
def prepare
175+
@collection_id = 'products-collection'
176+
base_query = Products.all
177+
178+
order = get_collection_order(@collection_id)
179+
ordered_query = Products.all.order(current_order)
180+
181+
@collection = set_collection(
182+
id: @collection_id,
183+
data: ordered_query,
184+
init_limit: 20,
185+
base_count: base_query.count
186+
)
187+
end
188+
189+
def response
190+
order
191+
async id: 'product-collection', rerender_on: "#{@collection_id}-udpate" do
192+
collection_content @collection.config do
193+
@collection.paginated_data.each do |product|
194+
paragraph text: product.name
195+
end
196+
end
197+
end
198+
pagination
199+
end
200+
201+
def order
202+
collection_order @my_collection.config do
203+
plain "sort by:"
204+
collection_order_toggle key: :title do
205+
button do
206+
plain "Title"
207+
collection_order_toggle_indicator key: :title, asc: '&#8593;', desc: '&#8595;'
208+
end
209+
end
210+
end
211+
end
212+
213+
#...
214+
215+
end
216+
```
217+
218+
## Complete documentation
219+
220+
If you want to know all details about the collection component as well as more example on how to use filtering, ordering and pagination together checkout its [api documentation](/docs/api/100-components/collection.md).

0 commit comments

Comments
 (0)