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

angular-filter-service

v1.0.3

Published

Simple data manager for filtering, sorting, and pagination

Downloads

1

Readme

angular-filter-service

Provides a simple utility to help with filtering, sorting, and pagination capabilities. Potentially useful for tables, lists, and grids.

This service adds an abstraction layer slightly above Angular's filters, but below a full-blown directive/component.

Usage

angular.module('myApp', ['banno.filterService'])
.controller('myController', function($scope, filterService) {
  function completed(response) {
    $scope.filtered = response;
  }

  function searchItems() {
    $scope.filters = filterService.getParameters();
    myService.get({
      limit: $scope.filters.limit,
      offset: $scope.filters.offset,
      sortField: $scope.filters.sortField,
      sortDirection: $scope.filters.sortAscending ? 'asc' : 'desc'
    }).then(function(results) {
      filterService.setResults(results, completed);
    }, function() {
      filterService.setResults({
        items: [],
        total: 0
      }, completed);
    });
  }

  $scope.onPreviousClick = function() {
    filterService.showPreviousPage();
  };

  $scope.onNextClick = function() {
    filterService.showNextPage();
  };

  $scope.onSortFieldClick = function(sortField) {
    filterService.setSortField(sortField);
  };

  $scope.onSortDirectionClick = function(direction) {
    filterService.setSortAscending(direction.toLowerCase() === 'asc');
  };

  $scope.onSubmitSearch = function(text) {
    filterService.setSearchQuery(text);
  };

  $scope.onSetSearchFieldClick = function(type, forceUpdate) {
    filterService.setSearchField(type, forceUpdate);
  };

  $scope.onClearSearchClick = function() {
    filterService.setSearchQuery('');
  };

  $scope.refresh = function() {
    filterService.use($scope.filters, searchItems);
    $scope.filtered = filterService.getState();
  };

  $scope.filters = {
    limit: 20,
    offset: 0,
    sortField: 'createdOn',
    sortAscending: false,
    searchField: 'Title',
    searchQuery: ''
  };
  $scope.refresh();
});

Installation

bower install --save angular-filter-service

If you are using RequireJS, load the "banno/filterService" module.

API

getParameters()

Returns the filtering parameters as an object with the following properties:

  • limit
  • offset
  • sortField
  • sortAscending
  • searchField
  • searchQuery

getState()

Returns an object that contains information about the search state:

  • isLastPage -- true if the current results are the last page (given the offset & limit)
  • isFirstPage -- true if the current results are the first page (given the offset)
  • count -- The number of results
  • firstIndex -- Index of the first item in the results (beginning with 1)
  • lastIndex -- Index of the last item in the results (beginning with 1)
  • results -- An object containing the results of the search:
    • total -- Number of results
    • items -- Array of results
  • empty -- true if the results are empty

refresh()

Performs the search, i.e. runs the function callback passed to use().

setPageLimit(newLimit)

Changes the limit parameter (number of results per page).

Also resets the offset parameter to 0 and performs the search.

setResults(results, callback)

Saves the results into the service's state. The results object should contain total and items properties.

The callback function is then called, with the search state passed as an argument.

setSearchField(string, forceUpdate)

Changes the search field.

If forceUpdate is truthy, it also resets the offset parameter to 0 and performs the search.

setSearchQuery(string)

Changes the search text parameter.

Also resets the offset parameter to 0 and performs the search.

setSortAscending(bool)

Changes the ascending/descending order for sorting. A true value indicates that the results should be sorted in ascending order; otherwise the results should be sorted in descending order.

Also resets the offset parameter to 0 and performs the search.

setSortField(field)

Changes the field for sorting.

Also resets the offset parameter to 0 and performs the search.

showNextPage()

Moves the offset forward (based on the limit) and performs the search.

showPreviousPage()

Moves the offset backward (based on the limit) and performs the search.

use(searchParams, searchFunction)

Sets the parameters for the search, and performs the search.

The searchParams argument should be an object the same properties as getParameters(). The second argument (searchFunction) is called every time that refresh() is called.

Contributing

You'll need gulp installed on your machine to run the development tools. Then run gulp to run all of the tasks and watch the files for changes.

Please add tests and maintain the existing styling when adding and updating the code.

Bugs & Feature Requests

Have an issue or feature request? Please open a new issue.

License

Copyright 2015 Jack Henry & Associates Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.