lib/builder.rb in sinatra_resource-0.4.4 vs lib/builder.rb in sinatra_resource-0.4.5

- old
+ new

@@ -2,10 +2,12 @@ class Builder FILTER_KEY = "filter" SEARCH_KEY = "search" + + ITEMS_PER_PAGE = 20 def initialize(klass) @klass = klass @resource_config = @klass.resource_config @@ -62,12 +64,15 @@ model = @model resource_config = @resource_config if !@parent @klass.get '/?' do role = lookup_role(nil) - documents = documents_for_get_many(role, model, resource_config, true, nil, nil) - resources = build_resources(documents, resource_config) + page = get_page(params) + documents = documents_for_get_many(role, model, resource_config, page, ITEMS_PER_PAGE, true, nil, nil) + document_count = document_count_for_get_many(model, resource_config, nil, nil) + page_count = calculate_page_count(document_count, ITEMS_PER_PAGE) + resources = build_resources(documents, resource_config, page, page_count) display(:list, resources, resource_config) end else child_assoc = @child_assoc parent_model = @parent_model @@ -77,11 +82,14 @@ parent_id = params.delete("parent_id") parent_role = role_for(parent_model, parent_id) parent_document = document_for_get_one(parent_role, parent_model, parent_resource_config, false, parent_id, nil, nil) # ------ role = lookup_role(nil) - documents = documents_for_get_many(role, model, resource_config, true, parent_document, child_assoc) - resources = build_resources(documents, resource_config) + page = get_page(params) + documents = documents_for_get_many(role, model, resource_config, page, ITEMS_PER_PAGE, true, parent_document, child_assoc) + document_count = document_count_for_get_many(model, resource_config, parent_document, child_assoc) + page_count = calculate_page_count(document_count, ITEMS_PER_PAGE) + resources = build_resources(documents, resource_config, page, page_count) display(:list, resources, resource_config, parent_id) end end end