From 3851b7c36cb304eb89f6a1ccdb2e6723b423faba Mon Sep 17 00:00:00 2001 From: Alex Frazer Date: Thu, 29 Oct 2015 13:45:02 -0400 Subject: [PATCH] Create a filter component --- .../lib/filter/filter.html | 8 +++ .../lib/filter/filter.js | 65 +++++++++++++++++++ packages/easysearch:components/package.js | 7 +- packages/matteodem:easy-search/easy:search | 1 + .../easysearch:autosuggest | 1 + .../easysearch:components | 1 + .../matteodem:easy-search/easysearch:core | 1 + .../easysearch:elasticsearch | 1 + 8 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 packages/easysearch:components/lib/filter/filter.html create mode 100644 packages/easysearch:components/lib/filter/filter.js create mode 120000 packages/matteodem:easy-search/easy:search create mode 120000 packages/matteodem:easy-search/easysearch:autosuggest create mode 120000 packages/matteodem:easy-search/easysearch:components create mode 120000 packages/matteodem:easy-search/easysearch:core create mode 120000 packages/matteodem:easy-search/easysearch:elasticsearch diff --git a/packages/easysearch:components/lib/filter/filter.html b/packages/easysearch:components/lib/filter/filter.html new file mode 100644 index 0000000..b7b2653 --- /dev/null +++ b/packages/easysearch:components/lib/filter/filter.html @@ -0,0 +1,8 @@ + + diff --git a/packages/easysearch:components/lib/filter/filter.js b/packages/easysearch:components/lib/filter/filter.js new file mode 100644 index 0000000..800cfd0 --- /dev/null +++ b/packages/easysearch:components/lib/filter/filter.js @@ -0,0 +1,65 @@ +/** + * The FieldInputComponent lets you search through configured indexes for a specified fild. + * + * @type {FilterComponent} + */ +EasySearch.FilterComponent = class FilterComponent extends BaseComponent { + onCreated() { + if (!_.isString(this.getData().property)) { + throw new Meteor.Error('no-property', 'Please provide the property for your filter component'); + } + const optionsIsValid = _.all(this.getData().options, option => _.has(option, 'label', 'value')); + if (!_.isArray(this.getData().options) || !optionsIsValid) { + throw new Meteor.Error('no-options', 'Options missing or not valid. Please provide valid options'); + } + + this.setProperty = _.debounce((value) => { + this.eachIndex((index, name) => { + index.getComponentMethods().addProps(this.getData().property, value); + }); + }, this.options.timeout); + + super.onCreated(); + } + + /** + * Event map. + * @returns {Object} + */ + events() { + return [{ + 'change select': function (e) { + this.setProperty($(e.target).val()); + } + }] + } + + /** + * returns the options + * + * @returns {Object} + */ + get options() { + return { + options: this.getData().options + } + } + + /** + * Anything passed to the html that is not used by this class + * will just be passed plainly to the select field. + * + * @returns {Object} + */ + get attrs() { + return _.omit(this.getData(), 'options', 'index', 'property'); + } + + get defaultOptions() { + return { + timeout: 50 + } + } +} + +EasySearch.FilterComponent.register('EasySearch.Filter'); diff --git a/packages/easysearch:components/package.js b/packages/easysearch:components/package.js index 43e75a9..39b8a86 100644 --- a/packages/easysearch:components/package.js +++ b/packages/easysearch:components/package.js @@ -1,7 +1,7 @@ Package.describe({ name: 'easysearch:components', summary: "Blaze Components for EasySearch", - version: "2.0.1", + version: "2.0.2", git: "https://github.com/matteodem/meteor-easy-search.git", documentation: 'README.md' }); @@ -20,6 +20,11 @@ Package.onUse(function(api) { api.addFiles(['lib/input/input.html', 'lib/input/input.js', 'lib/field-input/field-input.html', 'lib/field-input/field-input.js'], 'client'); api.addFiles(['lib/each/each.html', 'lib/each/each.js'], 'client'); + // Filter component + api.addFiles([ + 'lib/filter/filter.html', 'lib/filter/filter.js' + ], 'client'); + // If Components api.addFiles(['lib/if-input-empty/if-input-empty.html', 'lib/if-input-empty/if-input-empty.js'], 'client'); api.addFiles(['lib/if-no-results/if-no-results.html', 'lib/if-no-results/if-no-results.js'], 'client'); diff --git a/packages/matteodem:easy-search/easy:search b/packages/matteodem:easy-search/easy:search new file mode 120000 index 0000000..f472fea --- /dev/null +++ b/packages/matteodem:easy-search/easy:search @@ -0,0 +1 @@ +/Users/afrazer/Code/.Clones/meteor-easy-search/packages/easy:search \ No newline at end of file diff --git a/packages/matteodem:easy-search/easysearch:autosuggest b/packages/matteodem:easy-search/easysearch:autosuggest new file mode 120000 index 0000000..87e7d74 --- /dev/null +++ b/packages/matteodem:easy-search/easysearch:autosuggest @@ -0,0 +1 @@ +/Users/afrazer/Code/.Clones/meteor-easy-search/packages/easysearch:autosuggest \ No newline at end of file diff --git a/packages/matteodem:easy-search/easysearch:components b/packages/matteodem:easy-search/easysearch:components new file mode 120000 index 0000000..7feb702 --- /dev/null +++ b/packages/matteodem:easy-search/easysearch:components @@ -0,0 +1 @@ +/Users/afrazer/Code/.Clones/meteor-easy-search/packages/easysearch:components \ No newline at end of file diff --git a/packages/matteodem:easy-search/easysearch:core b/packages/matteodem:easy-search/easysearch:core new file mode 120000 index 0000000..b232057 --- /dev/null +++ b/packages/matteodem:easy-search/easysearch:core @@ -0,0 +1 @@ +/Users/afrazer/Code/.Clones/meteor-easy-search/packages/easysearch:core \ No newline at end of file diff --git a/packages/matteodem:easy-search/easysearch:elasticsearch b/packages/matteodem:easy-search/easysearch:elasticsearch new file mode 120000 index 0000000..c4ea68e --- /dev/null +++ b/packages/matteodem:easy-search/easysearch:elasticsearch @@ -0,0 +1 @@ +/Users/afrazer/Code/.Clones/meteor-easy-search/packages/easysearch:elasticsearch \ No newline at end of file