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-jsonapi-resources-list

v1.0.0-beta

Published

Addon for JSON API list support, search, filter, sort, etc.

Downloads

2

Readme

Ember JSONAPI Resources List Addon

Ember Addon that provides mixins for use with controllers and routes that need to display a list of resources that follow the JSON API 1.0 specification.

Example Use

In the router a list route is defined at the path '/' under the 'products' route.

Router.map(function() {
  this.route('products', { path: '/' }, function () {
    this.route('list', { path: '/' });
  });
});

List Route:

import Ember from 'ember';
import ListRouteMixin from 'ember-jsonapi-resources-list/mixins/routes/jsonapi-list';

export default Ember.Route.extend(ListRouteMixin, {
  /**
    The name of the model type, used with store service

    @property resourceName
    @type String
    @required
  */
  resourceName: 'products',

  /**
    The parent or route name

    @property routeParent
    @type String
    @required
  */
  routeParent: 'products'
});

List Controller

Use query params on the products list page which represent the request parameters used with the API server.

This example includes a filter for a facet. Perhaps the actual implementation will use color or size, or both (facets).

import Ember from 'ember';
import ListControllerMixin from 'ember-jsonapi-resources-list/mixins/controllers/jsonapi-list';
import facetTransform from '../transforms/facet';

export default Ember.Controller.extend(ListControllerMixin, {
  queryParams: [
    { searchQuery: 'search' },
    { sortParamName: 'sort' },
    { sortingDirection: 'order'},
    { facetParam: 'facet' }
  ],

  /**
    Value use with `filter[facet]` param in API requests

    @property facetParam
    @type String
  */
  facetParam: '',

  /**
    @property facetFilter
    @type String
  */
  facetFilter: Ember.computed('facets', 'facetParam', {
    get() {
      if (!this.get('facetParam')) {
        this.set('facetParam', this.get('facets')[0]);
      }
      return this.get('facetParam');
    },
    set(key, value) {
      return this.set('facetParam', value);
    },
  }),

  /**
    @property facets
    @type {Array}
  */
  facets: Ember.computed(function() {
    let facets = facetTransform.values.map(function(i){ return i; });
    facets.unshift('All'); // Allow "All" as an option
    return facets;
  }),

  actions: {
    /**
      Set the filtering params to pass into the route and display into the URL

      @method filtering
      @param {String} key
      @param {String} value
    */
    filtering(key, value) {
      if (key === 'facet') {
        this.set('facetFilter', value);
      }
      this.get('target').send('filtering', {
        facet: this.get('facetParam')
      });
    }
  }
});

List Template

{{input value=searchQuery placeholder="Search…" enter="search" class="search"}}

<div class="resource-filters row">
  <section class="one column">
    <p class="resource-filters-title">Filters</p>
  </section>
  <section class="resource-filters-item eleven columns icons">
    <em>Facet</em>
    {{#each facets as |filter|}}
      {{#selectable-button value=filter selectedValue=facetFilter action="filtering" attrName="facet"}}
        {{filter}}
      {{/selectable-button}}
    {{/each}}
  </section>
</div>

<table class="Product-list resource-list u-full-width">
  <thead>
    <tr class="u-small-text u-short-header">
      {{#jsonapi-list-heading
        on-sort=(action "sorting") field="facet"
        order=sortingDirection
        activeHeader=sortParamName}}Facet{{/jsonapi-list-heading}}
      {{#jsonapi-list-heading
        on-sort=(action "sorting") field="name"
        order=sortingDirection
        activeHeader=sortParamName}}Product{{/jsonapi-list-heading}}
      {{#jsonapi-list-heading
        on-sort=(action "sorting") field="updated-at"
        order=sortingDirection
        activeHeader=sortParamName}}Updated{{/jsonapi-list-heading}}
    </tr>
  </thead>
  <tbody>
    {{#each model key="id" as |resource|}}
      <tr {{action "detail" resource}}>
        <td>{{icon-for value=resource.facet}}</td>
        <td>{{resource.display-name}}</td>
        <td>{{moment-format resource.updated-at "ll"}}</td>
      </tr>
    {{/each}}
  </tbody>
  <tfoot>
    <tr>
      <td colspan="4" class="u-align-center">
        {{jsonapi-list-loader hasMore=hasMore loadingMore=loadingMore action="more"}}
      </td>
    </tr>
  </tfoot>
</table>

{{outlet}}

Installation

In the consuming application…

ember install ember-jsonapi-resources-list

Development

Install dependencies…

  • git clone this repository
  • npm install
  • bower install

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

For more information on using ember-cli, visit http://ember-cli.com/.