Sha256: dc5b674a83d815243c84912bdba411e5002bf1080ffaa9456667e5d318934309

Contents?: true

Size: 1.08 KB

Versions: 32

Compression:

Stored size: 1.08 KB

Contents

!(angular => {
  'use strict';

  class SelectionTagInput {
    constructor(options) {
      this._items = this._makeItemsFn(options.items, options.iteratee);
      this._itemField = options.itemField;
      this.selectedTags = [];
    }

    add(tag) {
      _.each(this._items(), item => {
        item[this._itemField].unshift(tag.text);
      });
    }

    remove(tag) {
      _.each(this._items(), item => {
        item[this._itemField] = _.reject(item[this._itemField], itemTag => {
          return tag.text === itemTag;
        });
      });
    }

    onSelection() {
      this.selectedTags = _.reduce(this._items(), (acc, item) => {
        return _.uniq(acc.concat(item[this._itemField]));
      }, []);
    }

    // private methods

    _makeItemsFn(items, _iteratee) {
      let rawItems = _.isFunction(items) ? items : () => items;
      let iteratee = _iteratee;
      return _.isFunction(iteratee) ? () => _.map(rawItems(), iteratee) : rawItems;
    }
  }

  angular.module('alephServices.selectionTagInput', []).service('SelectionTagInput', () => SelectionTagInput);

}(angular));

Version data entries

32 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.4.9.pre.dev app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.4.8 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.4.8 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.4.7 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.4.7 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.4.4 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.4.4 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.4.2 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.4.2 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.4.1 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.4.1 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.3.0 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.3.0 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.2.0 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.2.0 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.1.0 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.1.0 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6
aleph_analytics-0.0.6 public/assets/angular/services/lib/selection_tag_input.js-86cc6d564c108d722951b6fcd2b51221.es6
aleph_analytics-0.0.6 app/assets/javascripts/angular/services/lib/selection_tag_input.js.es6