Sha256: 40993b6b0c98f3093d061aa25f4588d74ddacd01207940d5f9245fb521f9c863

Contents?: true

Size: 1.85 KB

Versions: 14

Compression:

Stored size: 1.85 KB

Contents

!(angular => {
  'use strict';

  class MatcherRunner {

    constructor(matchers, items) {
      this._matchers = matchers;
      this._items = items;
    }

    execute(currentContext, filterArgs, prefix) {
      let allMatches = [];

      _.each(this._matchers, matcher => {
        if (this._isMatcherRelevant(matcher, currentContext)) {
          let matches = this._uniqueFilteredMatches(matcher, currentContext, filterArgs, prefix);

          _.each(matches, ea => {
            allMatches.push({
              name: ea,
              value: ea,
              score: matcher.contextRelevance[currentContext],
              meta: matcher.meta
            });
          });
        }
      });

      return allMatches;
    }

    // private methods

    _uniqueFilteredMatches(matcher, currentContext, filterArgs, prefix) {
      let filteredItems = _.map(this._items, item => {
        if (!this._matcherFiltersForContext(matcher, currentContext) ||
          this._itemSatisfiesFilters(matcher.contextItemFilters[currentContext], item, filterArgs)) {
          let itemName = _.exists(matcher.nameProperty) ? item[matcher.nameProperty] : item;
          if (itemName.indexOf(prefix) === 0) {
            return itemName;
          }
        }
      });

      return _.compact(_.uniq(filteredItems));
    }

    _itemSatisfiesFilters(filters, item, filterArgs) {
      return _.all(filters, filterFunc => filterFunc(item, filterArgs));
    }

    _matcherFiltersForContext(matcher, currentContext) {
      return _.getPath(matcher, ('contextItemFilters.' + currentContext));
    }

    _isMatcherRelevant(matcher, currentContext) {
      return _.any(_.keys(matcher.contextRelevance), contextKey => {
        return (contextKey === currentContext);
      });
    }
  }

  angular.module('alephServices.matcherRunner', []).service('MatcherRunner', () => MatcherRunner);

}(angular));

Version data entries

14 entries across 7 versions & 1 rubygems

Version Path
aleph_analytics-0.0.6 public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6
aleph_analytics-0.0.6 app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.5 public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6
aleph_analytics-0.0.5 app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.4 app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.4 public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6
aleph_analytics-0.0.3 public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6
aleph_analytics-0.0.3 app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.2 public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6
aleph_analytics-0.0.2 app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.1.alpha public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6
aleph_analytics-0.0.1.alpha app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.0.alpha app/assets/javascripts/angular/services/lib/matcher_runner.js.es6
aleph_analytics-0.0.0.alpha public/assets/angular/services/lib/matcher_runner.js-bd63f4c6ad965716c5b793d3c4602563.es6