No commit activity in last 3 years
No release in over 3 years
Allows you to incorporate will_paginate into an Angular on Ruby on Rails app.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

NgWillPaginate

ng_will_paginate makes it easy to use the will_paginate gem with Angular, everyone's favorte Javascript framework.

Normal use of will_paginate gem requires a page reload. Trying to paginate with AJAX on a single page requires quite a bit of extra work. This gem does that work for you.

This allows you to use the will_paginate gem via an Angular controller. User pushes button on page, triggering a method in Angular controller that calls a Rails controller for selected page of records.

Includes:

  • service that talks to rails
  • directive that puts links on page

Installation

Add this line to your application's Gemfile:

gem 'will_paginate'
gem 'ng_will_paginate'

And then execute:

$ bundle

Add '//= require ng_will_paginate' to your application.js manifest

Add 'ng-will-paginate' as a dependency of your Angular app: angular.module('myModule', ['ng-will-paginate'])

Usage

To use ng_will_paginate, first include the logic to retrieve your records from your database.

In your Rails controller:

def index
  @records = MyClass.paginate(:page => params[:page], :per_page => 10).order(created_at: 'desc')

  render json: {  max: @records.total_pages,
                  records: @records.as_json() }

The .as_json() method can accept all of its normal options. See the .to_JSON documentation for examples

In your Angular controller:

  1. inject $scope and paginationService into your controller
myApp.controller 'myController', ['$scope', 'paginationService', ($scope, paginationService)->
//the controller code
]
  1. add the following code to your controller
$scope.route = '/my_route' //this is the path for your method, if the index method above was for a class called 'Record', the path may look like '/records'
$scope.goToPage=(pageNumber)->
  paginationService.getPage(pageNumber, $scope.route, $scope)
$scope.goToPage 1

Now your records will be available as an array of JSON object in $scope.records 3. in your view add the pagination directive where you'd like your page links to show up

<pagination></pagination>

Development

After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release to create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Testing

We love testing - so we want to test all the things.

To run jasmine tests:

  1. Navigate from the gem's repo to the dummy app cd spec/dummy
  2. Start a server rails s
  3. In your browser navigate to "localhost:3000/specs"

Contributing

Issues and tasks are in the Issues for this repo. We'd love your help!

Please comment on an Issue if you'd like to work on it, and submit a Pull Request when the work is done. All code should be tested.

  1. Fork it ( https://github.com/[my-github-username]/ng_will_paginate/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

About NIRD

alt text

ng_will_paginate is maintained and funded by NIRD LLC. The names and logos of NIRD are trademarks of NIRD LLC. We are committed to giving back to the open source community. We are available for hire.

License

The gem is available as open source under the terms of the MIT License.