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-advanced-search

v0.7.3

Published

Easy faceted search forms

Downloads

3

Readme

ember-cli-advanced-search

Build Status

Simplify advanced search forms. Works well with trample backend.

Installation

ember install ember-cli-advanced-search

Running

Define your route:

import Ember from 'ember';
import AdvancedSearchRouteable from 'ember-cli-advanced-search/mixins/advanced-search-routeable';

export default Ember.Route.extend(AdvancedSearchRouteable, {
  searchModel: 'people-search',
  aggregateOn: ['name'],

  model(params) {
    return this.query(params.search);
  }
});

...And controller

import Ember from 'ember';
import AdvancedSearchable from 'ember-cli-advanced-search/mixins/advanced-searchable';

export default Ember.Controller.extend(AdvancedSearchable)

...And model

import DS from 'ember-data';
import SearchBase from 'ember-cli-advanced-search/models/search-base';
import MF from 'model-fragments';

export default SearchBase.extend({
  conditions: MF.fragment('people-search/conditions', { defaultValue: {} }),
  results: DS.hasMany('person')
});

...And that model's conditions

import DS from 'ember-data';
import MF from 'model-fragments';

export default MF.Fragment.extend({
  name: DS.attr('string'),
  description: DS.attr('string')
});

Then bring everything together in a template:

<form {{action 'query' on='submit'}}>
  {{input type='text' value=model.conditions.name }}
</form>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>

  <tbody>
    {{#each model.results as |result|}}
      <tr>
        <td>{{result.name}}</td>
        <td>{{result.description}}</td>
      </tr>
    {{/each}}
  </tbody>
</table>

Faceting

Add aggregateOn to your route to specify the aggregations that should come back:

// code
export default Ember.Route.extend(AdvancedSearchRouteable, {
  searchModel: 'people-search',
  aggregateOn: ['name']

  // code
});

Then add facet sections component to your template:

{{facet-sections model.aggregations onFacetChange=(action 'query')}}

Enhance findRecord in application adapter

We need to send query params via findRecord. Since ember data doesn't support this out-of-the-box yet:

  // https://github.com/emberjs/data/issues/3596#issuecomment-126604014
  urlForFindRecord(id, modelName, snapshot) {
    let url   = this._super(id, modelName, snapshot);
    let query = Ember.get(snapshot, 'adapterOptions.params');
    if (query) {
      url += '?' + Ember.$.param(query);
    }
    return url;
  }

Snake-cased server API

Because this addon uses ember-data-model-fragments, if the server is returning snake-cased attributes - like search.metadata.current_page instead of search.metadata.currentPage - you must register a custom serializer for ember-data-model-fragments if you haven't already:

// https://github.com/lytics/ember-data-model-fragments/issues/166
// app/initializers/fragment-serializer

import DS from 'ember-data';

const FragmentSerializer = DS.JSONSerializer.extend({
  keyForAttribute(key) {
    return Ember.String.underscore(key);
  }
});

export default {
  name: 'FragmentSerializer',
  before: 'store',
  after: 'fragmentTransform',
  initialize: function(container) {
    container.register('serializer:-fragment', FragmentSerializer);
  }
};

Autocompletes

Use the autocomplete service:

autocomplete: Ember.inject.service(),

actions: {
  queryPersonNameAutocomplete(query, deferred) {
    return this.get('autocomplete')
      .query('/api/autocomplete/people', query.term, deferred);
  }
}

This is now compatible with select2, e.g.

{{select-2
  value=searchModel.conditions.people_ids.values
  allowClear=true
  multiple=true
  optionLabelPath='text'
  query="queryPersonNameAutocomplete"
}}

The expected server response is:

{
  data: [
    {
      id: 1,
      type: 'autocompletes',
      attributes: {
        key: 1,
        text: 'Joe'
      }
    }
  ]
}

Running Tests

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

Building

  • ember build

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