Skip to content

Commit

Permalink
Added pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Menke committed Feb 15, 2009
1 parent 010dadf commit f6af9eb
Show file tree
Hide file tree
Showing 52 changed files with 3,561 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/controllers/errors_controller.rb
@@ -1,6 +1,6 @@
class ErrorsController < ApplicationController

helper_method :errors, :error, :project
helper_method :errors, :error, :project, :occurences

before_filter :require_user
before_filter :require_membership, :except => [:index]
Expand Down Expand Up @@ -48,6 +48,10 @@ def error
@error ||= Error.find(params[:id])
end

def occurences
@occurences ||= error.occurences.paginate :page => params[:page]
end

def require_membership
unless current_user.member?(error)
store_location
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/projects_controller.rb
Expand Up @@ -112,7 +112,7 @@ def destroy
private

def projects
@projects ||= current_user.projects.all
@projects ||= current_user.projects.paginate :page => params[:page]
end

def project
Expand All @@ -124,11 +124,11 @@ def project
end

def open_errors
@open_errors ||= project.reports.open.all
@open_errors ||= project.reports.open.paginate :page => params[:page]
end

def closed_errors
@closed_errors ||= project.reports.closed.all
@closed_errors ||= project.reports.closed.paginate :page => params[:page]
end

end
2 changes: 2 additions & 0 deletions app/models/error.rb
@@ -1,5 +1,7 @@
class Error < ActiveRecord::Base

def self.per_page ; 20 ; end

validates_presence_of :project_id
validates_presence_of :hash_string

Expand Down
2 changes: 2 additions & 0 deletions app/models/occurence.rb
@@ -1,5 +1,7 @@
class Occurence < ActiveRecord::Base

def self.per_page ; 20 ; end

validates_presence_of :error
validates_presence_of :name
validates_presence_of :description
Expand Down
6 changes: 4 additions & 2 deletions app/views/errors/show.html.haml
Expand Up @@ -16,8 +16,10 @@
%tr
%th.first.last{:colspan=>'2'} Occurences

=render :partial => error.occurences.all

=render :partial => occurences
= will_paginate occurences
%br

- actions do |link|
- if error.closed
- link.to 'Mark as not closed', error_path(error, :error => {:closed => '0'}), :method => :put
Expand Down
2 changes: 2 additions & 0 deletions app/views/projects/closed.html.haml
Expand Up @@ -13,6 +13,8 @@
- else
%tr
%td{:colspan=>3} There are no closed errors.
= will_paginate closed_errors
%br

- actions do |link|
- link.to 'Edit project', edit_project_path(project)
2 changes: 2 additions & 0 deletions app/views/projects/show.html.haml
Expand Up @@ -13,6 +13,8 @@
- else
%tr
%td{:colspan=>3} There are no open errors.
= will_paginate(open_errors)
%br

- actions do |link|
- link.to 'Edit project', edit_project_path(project)
Expand Down
2 changes: 2 additions & 0 deletions config/environment.rb
Expand Up @@ -34,6 +34,8 @@
config.gem "authlogic"
config.gem 'railsgarden-message_block', :lib => 'message_block', :source => 'http://gems.github.com'
config.gem 'haml'
config.gem 'mislav-will_paginate', :lib => 'will_paginate',
:source => 'http://gems.github.com'

# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
Expand Down
132 changes: 132 additions & 0 deletions vendor/gems/mislav-will_paginate-2.3.7/.specification
@@ -0,0 +1,132 @@
--- !ruby/object:Gem::Specification
name: mislav-will_paginate
version: !ruby/object:Gem::Version
version: 2.3.7
platform: ruby
authors:
- "Mislav Marohni\xC4\x87"
- PJ Hyett
autorequire:
bindir: bin
cert_chain: []

date: 2009-02-10 00:00:00 +01:00
default_executable:
dependencies: []

description: The will_paginate library provides a simple, yet powerful and extensible API for ActiveRecord pagination and rendering of pagination links in ActionView templates.
email: mislav.marohnic@gmail.com
executables: []

extensions: []

extra_rdoc_files:
- README.rdoc
- LICENSE
- CHANGELOG.rdoc
files:
- CHANGELOG.rdoc
- LICENSE
- README.rdoc
- Rakefile
- examples
- examples/apple-circle.gif
- examples/index.haml
- examples/index.html
- examples/pagination.css
- examples/pagination.sass
- init.rb
- lib
- lib/will_paginate
- lib/will_paginate.rb
- lib/will_paginate/array.rb
- lib/will_paginate/collection.rb
- lib/will_paginate/core_ext.rb
- lib/will_paginate/finder.rb
- lib/will_paginate/named_scope.rb
- lib/will_paginate/named_scope_patch.rb
- lib/will_paginate/version.rb
- lib/will_paginate/view_helpers.rb
- test
- test/boot.rb
- test/collection_test.rb
- test/console
- test/database.yml
- test/finder_test.rb
- test/fixtures
- test/fixtures/admin.rb
- test/fixtures/developer.rb
- test/fixtures/developers_projects.yml
- test/fixtures/project.rb
- test/fixtures/projects.yml
- test/fixtures/replies.yml
- test/fixtures/reply.rb
- test/fixtures/schema.rb
- test/fixtures/topic.rb
- test/fixtures/topics.yml
- test/fixtures/user.rb
- test/fixtures/users.yml
- test/helper.rb
- test/lib
- test/lib/activerecord_test_case.rb
- test/lib/activerecord_test_connector.rb
- test/lib/load_fixtures.rb
- test/lib/view_test_process.rb
- test/tasks.rake
- test/view_test.rb
has_rdoc: true
homepage: http://github.com/mislav/will_paginate/wikis
post_install_message:
rdoc_options:
- --main
- README.rdoc
- --inline-source
- --charset=UTF-8
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: "0"
version:
requirements: []

rubyforge_project:
rubygems_version: 1.3.1
signing_key:
specification_version: 2
summary: Most awesome pagination solution for Rails
test_files:
- test/boot.rb
- test/collection_test.rb
- test/console
- test/database.yml
- test/finder_test.rb
- test/fixtures
- test/fixtures/admin.rb
- test/fixtures/developer.rb
- test/fixtures/developers_projects.yml
- test/fixtures/project.rb
- test/fixtures/projects.yml
- test/fixtures/replies.yml
- test/fixtures/reply.rb
- test/fixtures/schema.rb
- test/fixtures/topic.rb
- test/fixtures/topics.yml
- test/fixtures/user.rb
- test/fixtures/users.yml
- test/helper.rb
- test/lib
- test/lib/activerecord_test_case.rb
- test/lib/activerecord_test_connector.rb
- test/lib/load_fixtures.rb
- test/lib/view_test_process.rb
- test/tasks.rake
- test/view_test.rb
110 changes: 110 additions & 0 deletions vendor/gems/mislav-will_paginate-2.3.7/CHANGELOG.rdoc
@@ -0,0 +1,110 @@
== 2.3.6, released 2008-10-26

* Rails 2.2 fix: stop using `extract_attribute_names_from_match` inernal AR method, it no longer exists

== 2.3.5, released 2008-10-07

* update the backported named_scope implementation for Rails versions older than 2.1
* break out of scope of paginated_each() yielded block when used on named scopes
* fix paginate(:from)

== 2.3.4, released 2008-09-16

* Removed gem dependency to Active Support (causes trouble with vendored rails).
* Rails 2.1: fix a failing test and a deprecation warning.
* Cope with scoped :select when counting.

== 2.3.3, released 2008-08-29

* Ensure that paginate_by_sql doesn't change the original SQL query.
* RDoc love (now live at http://mislav.caboo.se/static/will_paginate/doc/)
* Rename :prev_label to :previous_label for consistency. old name still functions but is deprecated
* ActiveRecord 2.1: Remove :include option from count_all query when it's possible.

== 2.3.2, released 2008-05-16

* Fixed LinkRenderer#stringified_merge by removing "return" from iterator block
* Ensure that 'href' values in pagination links are escaped URLs

== 2.3.1, released 2008-05-04

* Fixed page numbers not showing with custom routes and implicit first page
* Try to use Hanna for documentation (falls back to default RDoc template if not)

== 2.3.0, released 2008-04-29

* Changed LinkRenderer to receive collection, options and reference to view template NOT in
constructor, but with the #prepare method. This is a step towards supporting passing of
LinkRenderer (or subclass) instances that may be preconfigured in some way
* LinkRenderer now has #page_link and #page_span methods for easier customization of output in
subclasses
* Changed page_entries_info() method to adjust its output according to humanized class name of
collection items. Override this with :entry_name parameter (singular).

page_entries_info(@posts)
#-> "Displaying all 12 posts"
page_entries_info(@posts, :entry_name => 'item')
#-> "Displaying all 12 items"

== 2.2.3, released 2008-04-26

* will_paginate gem is no longer published on RubyForge, but on
gems.github.com:

gem sources -a http://gems.github.com/ (you only need to do this once)
gem install mislav-will_paginate

* extract reusable pagination testing stuff into WillPaginate::View
* rethink the page URL construction mechanizm to be more bulletproof when
combined with custom routing for page parameter
* test that anchor parameter can be used in pagination links

== 2.2.2, released 2008-04-21

* Add support for page parameter in custom routes like "/foo/page/2"
* Change output of "page_entries_info" on single-page collection and erraneous
output with empty collection as reported by Tim Chater

== 2.2.1, released 2008-04-08

* take less risky path when monkeypatching named_scope; fix that it no longer
requires ActiveRecord::VERSION
* use strings in "respond_to?" calls to work around a bug in acts_as_ferret
stable (ugh)
* add rake release task


== 2.2.0, released 2008-04-07

=== API changes
* Rename WillPaginate::Collection#page_count to "total_pages" for consistency.
If you implemented this interface, change your implementation accordingly.
* Remove old, deprecated style of calling Array#paginate as "paginate(page,
per_page)". If you want to specify :page, :per_page or :total_entries, use a
parameter hash.
* Rename LinkRenderer#url_options to "url_for" and drastically optimize it

=== View changes
* Added "prev_page" and "next_page" CSS classes on previous/next page buttons
* Add examples of pagination links styling in "examples/index.html"
* Change gap in pagination links from "..." to
"<span class="gap">&hellip;</span>".
* Add "paginated_section", a block helper that renders pagination both above and
below content in the block
* Add rel="prev|next|start" to page links

=== Other

* Add ability to opt-in for Rails 2.1 feature "named_scope" by calling
WillPaginate.enable_named_scope (tested in Rails 1.2.6 and 2.0.2)
* Support complex page parameters like "developers[page]"
* Move Array#paginate definition to will_paginate/array.rb. You can now easily
use pagination on arrays outside of Rails:

gem 'will_paginate'
require 'will_paginate/array'

* Add "paginated_each" method for iterating through every record by loading only
one page of records at the time
* Rails 2: Rescue from WillPaginate::InvalidPage error with 404 Not Found by
default
18 changes: 18 additions & 0 deletions vendor/gems/mislav-will_paginate-2.3.7/LICENSE
@@ -0,0 +1,18 @@
Copyright (c) 2007 PJ Hyett and Mislav Marohnić

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit f6af9eb

Please sign in to comment.