Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a filter component #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/easysearch:components/lib/filter/filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template name="EasySearch.Filter">
<select {{ attrs }}>
{{#each options.options}}
<option value="{{value}}">{{label}}</option>
{{/each}}
</select>
</template>

65 changes: 65 additions & 0 deletions packages/easysearch:components/lib/filter/filter.js
Original file line number Diff line number Diff line change
@@ -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');
7 changes: 6 additions & 1 deletion packages/easysearch:components/package.js
Original file line number Diff line number Diff line change
@@ -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'
});
Expand All @@ -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');
Expand Down
1 change: 1 addition & 0 deletions packages/matteodem:easy-search/easy:search
1 change: 1 addition & 0 deletions packages/matteodem:easy-search/easysearch:autosuggest
1 change: 1 addition & 0 deletions packages/matteodem:easy-search/easysearch:components
1 change: 1 addition & 0 deletions packages/matteodem:easy-search/easysearch:core
1 change: 1 addition & 0 deletions packages/matteodem:easy-search/easysearch:elasticsearch