npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cli-bs-pagination

v0.0.4

Published

A simple pagination addon for ember.js, which renders bootstrap-based pagination links.

Downloads

18

Readme

ember-cli-bs-pagination

A simple addon to render pagination links (using bootstrap 4 markup). What it does:

  • renders links with markup as specified by Bootstrap 4
  • sets the page variable you pass it to the clicked page (or to -1 or +1 if Previous or Next is clicked)

Assumptions:

  • The URL for the current page is the same as the paginated url

What it does not do:

  • paginate your models
  • allow you to use a zero-based index for pagination
  • update the URL (ember will do this for you when setup properly as outlined below)
  • cook you bacon

What it will do (roadmap):

  • support innerWindow argument (how many links are shown around the current page)
  • support outerWindow argument (how many links are around the first and the last page)
  • support rendering a pagination summary

What it depends on:

  • handlebars

Configuration options:

  • additionalClasses will be added to the ul.pagination node. Use pagination-sm or pagination-lg for sizing, use flexbox utilites for alignment (eg justify-content-center).
  • If you would prefer to use "actions up" instead of two-way binding for page, pass _setPage=(action mySetPageAction) and your action will receive the new value of page as an argument.

Installation & Usage

  • Install ember install ember-cli-bs-pagination

  • Tell your route that you want to refresh the model whenever the page query param changes (otherwise changing page won't call the model hook)

  • pass params when you query the store, which will have the query param page

// app/routes/items.js
export default Route.extend({
  queryParams: {
    page: { refreshModel: true },
  },
  model(params) {
    return get(this, 'store').query('item', params);
  },
})
  • Tell your controller that you want to bind the page query param to a page variable locally
  • Tell your controller the default value for page
// app/controllers/items.js
export default Controller.extend({
  queryParams: ["page"],
  page: 1,
});
  • Use the component (finally!)
{{!-- app/templates/items.hbs --}}
{{#each model do |item|}}
  {{!-- render item --}}
{{/each}}
{{page-numbers page=page totalPages=model.meta.total-pages}}

Note: meta.total-pages assumes your API returns this param properly formatted as per the JSONApi spec.

That's all!

Variations on a theme:

  • You can easily customize the view by defining your own app/components/templates/page-numbers.hbs. Look at page-numbers.hbs here for inspiration. NOTE: removing your local page-numbers.hbs file seems to confuse Ember. I've had to rm -rf node_modules/ember-cli-bs-pagination; yarn to get it working again after removing an app's local version of the template
  • You could paginate a local array of items just as easily by changing the model() hook and changing how you set totalPages
  • You can use anything you like for the page query param, say you wanted to use página, just use página in the Route & Controller setup, then pass it to the component, eg {{page-numbers page=página totalPages=totalPages}}

Collaborating

Get Started

  • fork the repo & clone it locally
  • cd ember-cli-bs-pagination
  • yarn install
  • git checkout -b my-feature-name-or-bug-fix-name
  • write some code
  • write some tests
  • submit a PR

Running Tests

  • yarn test (Runs ember try:each to test your addon against multiple Ember versions)
  • ember test
  • ember test --server
  • ember serve, then visit tests at http://localhost:4200/tests.